Darkflow: Assertion error: over-read yolo.weights

Created on 28 Mar 2017  ·  35Comments  ·  Source: thtrieu/darkflow

I tried to run ./flow --test test/ --model cfg/yolo.cfg --load yolo.weights --gpu 1.0

I get loading yolo.weights .... and then assertion error: Over-read yolo.weights.

However, when I run the same command with tiny-yolo.cfg and tiny-yolo.weights it works. I downloaded the weights file from https://pjreddie.com/darknet/yolo/

Most helpful comment

@Dhruv-Mohan @kinhunt see updated README, I uploaded some of the weights file.

All 35 comments

i guess u had used wrong weights, it didn't match with cfg. i tried with yolo.cfg & yolo.weights it worked fine.
however when i train yolo-voc.cfg with custom class, i get the same error message with my trained weights. i would appreciate if someone can explain what this error mean.

The .weights parser follow .cfg layer by layer, reading the corresponding chunk of bytes from .weights, but then there is still layer to read while the parser has already reach the end of .weights; that is when you have the assertion error.

Please give the command that leads to this error. If you want to custom your class, then there is a few places to make modifications:

  1. Number of filters in the last conv layer in .cfg
  2. class number in region layer
  3. labels.txt

Then run

./flow --model cfg/model.cfg --load bin/model.weights --train

Try training your network from scratch, the latest weights https://pjreddie.com/darknet/yolo/ don't seem to align with the cfg file.
I've run into the same problem with yolo.weights and yolo-voc.weights, however my custom trained network's weights work just fine

Could you provide instructions to train using yolo.cfg file. Thanks

On Wed, Mar 29, 2017 at 12:20 PM, Dhruv-Mohan notifications@github.com
wrote:

Try training your network from scratch, the latest weights
https://pjreddie.com/darknet/yolo/ don't align with the cfg file.
I've run into the same problem with yolo.weights and yolo-voc.weights,
however my custom trained network's weights work just fine


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/thtrieu/darkflow/issues/107#issuecomment-289999490,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AZgJMHWUgCDnwlS_s1HY5RcBNrVSAWusks5rqf9CgaJpZM4Mrj84
.

same problem. use readme instruction with yolo.cfg and v2 weights of http://pjreddie.com/media/files/yolo-voc.weights

@kinhunt yolo.cfg and yolo-voc.weights don't match. Even the new yolo.weights does not match yolo.cfg, it seems the official YOLO site does not keep their files reliably.

@thtrieu thank you to clear out. do you know where to find the matching files?

@kinhunt i've hunted for many days and haven't found em. You're best best is to train from scratch

I can upload mine. Wait for ~ 24 hours.

@thtrieu good news. thank you

@Dhruv-Mohan @kinhunt see updated README, I uploaded some of the weights file.

got it thank you. it works

@thtrieu could you provide the steps you followed to trainj on coco dataset to generate yolo.weights file. I would liketo repeat the same and generate weights file for yolov2 on coco dataset.

Hi @thtrieu,
I have followed steps you mentioned to retrain the model with custom number of classes

[convolutional]
size=1
stride=1
pad=1
filters=30
activation=linear

[region]
anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
bias_match=1
classes=1
coords=4
num=5

I also have just one label in label.txt. But when i run this with the tiny weights file i downloaded from your google share [https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU tiny-yolo-voc.weights] , it fails with assertion error

AssertionError: expect 63082056 bytes, found 63471556

Can you help me understand what might be wrong here.

I had a similar problem with a previously custom-trained weight from darknet, I copied the same .cfg file with the weight to try it on darkflow and got:
AssertionError: expect 202314760 bytes, found 202314764
It only differs by 4 bytes so am I missing some settings?

@deng1028 have you solved your problem yet? I have the same problem.

@helloGitHub1993 have you solved your problem yet? I have the same problem.

@helloGitHub1993 go into loader.py in utils folder ,then change self.offset = 20 on line 121

@beerboaa i used another way. flow -model cfg/yolo-new.cfg(replace it with your training cfg) --load -1 --imgdir yourimgdir. It works for me and you can have a try.By the way, you dont need to train again.

@itsayush have you solved your problem yet? I also followed the same steps as you and have the same problem with training custom data (1 class). I tried changing self.offset = 1 in loader.py, it didn't work.
My command:
flow --train --model cfg/tiny-yolo-voc-1c.cfg --load bin/tiny-yolo-voc.weights --annotation train/Annotations/ --dataset train/Images/ --config cfg/ --gpu 0.9
But it works well with:
flow --imgdir sample_img/ --model cfg/tiny-yolo-voc.cfg --load bin/tiny-yolo-voc.weights --gpu 0.9
AssertionError: expect 63471541 bytes, found 63471556

Can anyone help me?

I have the same problem using this git's code https://github.com/bendidi/Tracking-with-darkflow with tiny-yolo

@hyperfraise
image
I also have the same problem, do you fix it?

facing the same issue. i tried to use weights from your google drive with corresponding .cfg, worked until i tried to change num of classes to 1 (=> filters in last layer = 30). Is there still a chance to train on custom num of classes with pretrained model?

I had the same problem when I trained Yolo with my own custom dataset from pjreddie's website and tried to run the resulting .weights file using darkflow. I had the problem of "Assertion Error : expect 268283952 bytes, found 268283956". Once I've changed self.offset = 20 on line 121 in loader.py in utils folder like @beerboaa said, it works fine. Thanks.

@MartinBrisiak where you did you get the corresponding .cfg?

nevermind, i have it running in one environment with the yolo.weights from @thtrieu and the yolo.cfg in this repo
something wrong with the other environment...

@helloGitHub1993 go into loader.py in utils folder ,then change self.offset = 20 on line 121

ye, it works,thanks a lot

@beerboaa Thanks mahn..it worked

It seems that the PJ Reddie files are not fully compatible, so I have to download the pre built weights from the provided link in the README: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU

It seems that the PJ Reddie files are not fully compatible, so I have to download the pre built weights from the provided link in the README: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU

where to find yolov2-voc.weights? is missing... any idea?

there is mix with 2 different issues, the first one if there is different from the existing weight file and the configuration of exactly 4 bytes in this case you need to change the offset in line 121 to 20 (in my case is working with yolov2) the second case if the different is more than 4 bytes, this is wrong configuration file for weight file OR in case you want to train your own objects make sure that yolov2-voc.cfg exists in the configuration folder, i attach the one that resolve the issue
cfg-yolov2-voc.zip

I had the same problem when I trained Yolo with my own custom dataset from pjreddie's website and tried to run the resulting .weights file using darkflow. I had the problem of "Assertion Error : expect 268283952 bytes, found 268283956". Once I've changed self.offset = 20 on line 121 in loader.py in utils folder like @beerboaa said, it works fine. Thanks.

for me it not work, any other ideas? :(

Hi,
I finally was able to make it work by using this .cfg file https://github.com/pjreddie/darknet/blob/master/cfg/yolov2.cfg
and it works with the "yolov2 608X608" weight from here: https://pjreddie.com/darknet/yolo/

To deal with the error

AssertionError: expect 64701556 bytes, found 180357512

just run

$ cd /content/darkflow
$ !sed -i "s/self.offset = 16/self.offset = 20/g"  ./darkflow/utils/loader.py

Regarding the assertion error, its probably due to the mismatch of the configuration file and the weights.

So, I found a hack around it. Use this notebook by Zoltan Szabo
The author provides a demo for only 2 classes. So, his cfg file has 2 classes and uses the yolov2-tiny-voc-10000 weights, found here.
But the actual model (v2-tiny) was trained on 20 classes. So, to generate a pb file for the actual model, use the actual config file of the model, maintained by pJreddie at
https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov2-tiny-voc.cfg"

and replace the original cfg file with this one. Let the weights remain same.

Now, the final change you must make, is to the text file containing the class names. For this, go to the class names file maintained by pj reddie and paste them to the text file present in /content/darkflow/labels.txt (in Google Collab).

Now simply run the command that you were running
!./flow --model cfg/yolo-v2-tiny.cfg --load weights/yolov2-tiny-voc_10000.weights --savepb

And you should get the desired protobuf file :yum:

Was this page helpful?
0 / 5 - 0 ratings