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

AssertionError: Over-read bin/yolo.weights #153

Closed
loretoparisi opened this issue Apr 9, 2017 · 12 comments
Closed

AssertionError: Over-read bin/yolo.weights #153

loretoparisi opened this issue Apr 9, 2017 · 12 comments

Comments

@loretoparisi
Copy link
Contributor

I have downloaded the yolo.weights and yolo.cfg from P.J Reddie darknet site:

cd darkflow && mkdir bin && cd bin/ \
wget http://pjreddie.com/media/files/yolo.weights >/dev/null 2>&1 && \
wget http://pjreddie.com/media/files/tiny-yolo-voc.weights >/dev/null 2>&1 && \    

then tried to run into flow:

$ ./flow --model cfg/yolo.cfg --load bin/yolo.weights --demo videofile.avi --gpu 1.0

and I get

$:/darkflow/darkflow# ./flow --model cfg/yolo.cfg --load bin/yolo.weights --demo videofile.avi --gpu 1.0
Parsing ./cfg/yolo.cfg
Parsing cfg/yolo.cfg
Loading bin/yolo.weights ...
Traceback (most recent call last):
  File "./flow", line 45, in <module>
    tfnet = TFNet(FLAGS)
  File "/darkflow/net/build.py", line 46, in __init__
    darknet = Darknet(FLAGS)
  File "/darkflow/dark/darknet.py", line 27, in __init__
    self.load_weights()
  File "/darkflow/dark/darknet.py", line 82, in load_weights
    wgts_loader = loader.create_loader(*args)
  File "/darkflow/utils/loader.py", line 105, in create_loader
    return load_type(path, cfg)
  File "/darkflow/utils/loader.py", line 19, in __init__
    self.load(*args)
  File "/darkflow/utils/loader.py", line 70, in load
    val = walker.walk(new.wsize[par])
  File "/darkflow/utils/loader.py", line 127, in walk
    'Over-read {}'.format(self.path)
AssertionError: Over-read bin/yolo.weights
@loretoparisi
Copy link
Contributor Author

loretoparisi commented Apr 9, 2017

[UPDATE]
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

The problem was that I had to do this server-side, so after digging a bit, the simplest solution was to use the Firefox addon gcurl that mimic the direct download command:

cd darkflow/bin && \
    curl --header 'Host: doc-0k-88-docs.googleusercontent.com' --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' --header 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3' --header 'Referer: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU' --header 'Connection: keep-alive' --header 'Upgrade-Insecure-Requests: 1' 'https://doc-0k-88-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/etft348j4r0b37n9p1jkokvbfagiimk2/1491782400000/16010642207042931662/*/0B1tW_VtY7onieS0zMzdkSG11OW8?e=download' -o 'tiny-yolo-v1.1.weights' -L && \
    curl --header 'Host: doc-08-88-docs.googleusercontent.com' --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' --header 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3' --header 'Referer: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU' --header 'Connection: keep-alive' --header 'Upgrade-Insecure-Requests: 1' 'https://doc-08-88-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/s29gvf1n83pqr37pk2l7t2cvcjnssd8s/1491782400000/16010642207042931662/*/0B1tW_VtY7oniTjM3YUxlRHpDVW8?e=download' -o 'tiny-yolo-voc.weights' -L && \
    curl --header 'Host: doc-10-88-docs.googleusercontent.com' --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' --header 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3' --header 'Referer: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU' --header 'Connection: keep-alive' --header 'Upgrade-Insecure-Requests: 1' 'https://doc-10-88-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/fmtsb8ruqk7a4tg5p98khj6qp4fq3p6i/1491782400000/16010642207042931662/*/0B1tW_VtY7onicFlqclhnRGlodGM?e=download' -o 'yolo-full.weights' -L && \
    curl --header 'Host: doc-0k-88-docs.googleusercontent.com' --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' --header 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3' --header 'Referer: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU' --header 'Connection: keep-alive' --header 'Upgrade-Insecure-Requests: 1' 'https://doc-0k-88-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/knshmif3mk3n4ogtq9p77nf2f5v3dr0d/1491782400000/16010642207042931662/*/0B1tW_VtY7onibmdQWE1zVERxcjQ?e=download' -o 'yolo-tiny.weights' -L && \
    curl --header 'Host: doc-0c-88-docs.googleusercontent.com' --header 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0' --header 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' --header 'Accept-Language: it-IT,it;q=0.8,en-US;q=0.5,en;q=0.3' --header 'Referer: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU' --header 'Connection: keep-alive' --header 'Upgrade-Insecure-Requests: 1' 'https://doc-0c-88-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/ggut18kr6ubhoc8btg5hf6f32stoh50n/1491782400000/16010642207042931662/*/0B1tW_VtY7oniZGlkLTh5YVl1WWs?e=download' -o 'yolo.weights' -L

Btw I'm not sure if those links will work forever, after the download my bin/ folder looks like:

# cd darkflow/bin/
# ls -lh
total 1.6G
-rw-r--r-- 1 root root 104M Apr 10 00:20 tiny-yolo-v1.1.weights
-rw-r--r-- 1 root root  61M Apr 10 00:20 tiny-yolo-voc.weights
-rw-r--r-- 1 root root 1.1G Apr 10 00:20 yolo-full.weights
-rw-r--r-- 1 root root 173M Apr 10 00:21 yolo-tiny.weights
-rw-r--r-- 1 root root 258M Apr 10 00:21 yolo.weights

@thtrieu
Copy link
Owner

thtrieu commented Apr 10, 2017

Files on official YOLO are always renewed as he experiments new configs, you have to check if there is corresponding .cfg released. weights file I uploaded are older versions and is compatible with the .cfg in this repo.

@thtrieu thtrieu closed this as completed Apr 10, 2017
@loretoparisi
Copy link
Contributor Author

@thtrieu thanks, I solved in the meanwhile using your files!

@chadrick-kwag
Copy link

this error is caused by the mismatch between the cfg and binary weight file. Here is the related code which causes it.
At the beginning of flow, it will first try to initialize the TFNet from the given cfg and bin specified by the user in the command line.

# in darkflow/utils/loader.py

class weights_walker(object):
  ...
  self.size = os.path.getsize(path)

this walker is created and called function walk
This walk will read weights from the bin file for each layer with the exact amount of bytes according to the cfg. Before actually reading it, it does a check on if the bytes to read is less than the remaining bytes in the file. Here is the code for that

    def walk(self, size):

        if self.eof: return None
        end_point = self.offset + 4 * size

        assert end_point <= self.size, \
        'Over-read {}'.format(self.path)

here the end_point is where the file descriptor cursor would be located when it finishes reading the required amount from the binary file for the current layer's weights. The self.size is the total size of the binary file. You can see how the comparison of these two variables will indicate if there is a conflict between the cfg and bin file.

Based on the discussions above, I have downloaded the latest cfg and binary file from the yolov2 website. However, it still doesn't work and I am now sure why. Hope I can write down a successful story later on.

@AlexeyAB
Copy link

@chadrick-kwag Hi, did you solve it?

@chadrick-kwag
Copy link

@AlexeyAB unfortunately no. I had to just switch to tiny-yolo-voc which worked without a glitch. My project is simple so tiny-yolo suits me as well. Sorry to tell you the bad news :(

@AlexeyAB
Copy link

@chadrick-kwag Ok thanks. Do you use tiny-yolo-voc from https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU or from https://pjreddie.com/darknet/yolo/ ?

@chadrick-kwag
Copy link

@AlexeyAB I used the one from pjreddie . FYI I am using the one that I downloaded about 6 months ago. I hope it still works.

@shailensobhee
Copy link

Anyone has the direct download link to the cfg file that corresponds to the the weight file (yolo.weights) from the above Google Drive link?

@prateethvnayak
Copy link

@shailensobhee I tried all possible combinations of yolov2-voc cfg and weight files between darkflow and darknet repo. There seems to be no single match.

@thtrieu @AlexeyAB Any idea ?

@Ata1362
Copy link

Ata1362 commented May 13, 2019

you can fix this issue by changing the offset in the loader.py in your darkflow directory.
recommended decreasing the offset to 16 then test again.
GL

@mpky
Copy link

mpky commented May 14, 2019

Drive

Did you get the link? If not, here's what I've been using: https://drive.google.com/drive/folders/0B1tW_VtY7onidEwyQ2FtQVplWEU

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

8 participants