Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion error: over-read yolo.weights #107

Closed
ramarajan09 opened this issue Mar 28, 2017 · 35 comments
Closed

Assertion error: over-read yolo.weights #107

ramarajan09 opened this issue Mar 28, 2017 · 35 comments

Comments

@ramarajan09
Copy link

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/

@Prakash19921206
Copy link
Contributor

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.

@thtrieu
Copy link
Owner

thtrieu commented Mar 28, 2017

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

@Dhruv-Mohan
Copy link
Contributor

Dhruv-Mohan commented Mar 29, 2017

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

@ramarajan09
Copy link
Author

ramarajan09 commented Mar 29, 2017 via email

@kinhunt
Copy link

kinhunt commented Apr 2, 2017

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

@thtrieu
Copy link
Owner

thtrieu commented Apr 3, 2017

@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 thtrieu closed this as completed Apr 3, 2017
@kinhunt
Copy link

kinhunt commented Apr 3, 2017

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

@Dhruv-Mohan
Copy link
Contributor

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

@thtrieu
Copy link
Owner

thtrieu commented Apr 3, 2017

I can upload mine. Wait for ~ 24 hours.

@kinhunt
Copy link

kinhunt commented Apr 3, 2017

@thtrieu good news. thank you

@thtrieu
Copy link
Owner

thtrieu commented Apr 3, 2017

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

@kinhunt
Copy link

kinhunt commented Apr 3, 2017

got it thank you. it works

@ramarajan09
Copy link
Author

@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.

@itsayush
Copy link

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.

@deng1028
Copy link

deng1028 commented Jul 3, 2017

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?

@helloGitHub1993
Copy link

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

@beerboaa
Copy link

beerboaa commented Aug 4, 2017

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

@beerboaa
Copy link

beerboaa commented Aug 4, 2017

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

@helloGitHub1993
Copy link

helloGitHub1993 commented Aug 5, 2017

@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.

@rujiao
Copy link

rujiao commented Sep 5, 2017

@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?

@hyperfraise
Copy link

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

@zhangyujia0223
Copy link

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

@MartinBrisiak
Copy link

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?

@Ugenteraan
Copy link

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.

@jo-tham
Copy link

jo-tham commented May 9, 2018

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

@jo-tham
Copy link

jo-tham commented May 9, 2018

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...

@shenyingying
Copy link

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

ye, it works,thanks a lot

@VernonNabibya
Copy link

@beerboaa Thanks mahn..it worked

@iseegr8tfuldeadppl
Copy link

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

@proxytype
Copy link

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?

@proxytype
Copy link

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

@alansoliditydev
Copy link

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? :(

@BlueSeven277
Copy link

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/

@pra-dan
Copy link

pra-dan commented Mar 18, 2020

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

@pra-dan
Copy link

pra-dan commented Mar 19, 2020

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 😋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests