thtrieu / darkflow

Translate darknet to tensorflow. Load trained weights, retrain/fine-tune using tensorflow, export constant graph def to mobile devices
GNU General Public License v3.0
6.13k stars 2.08k forks source link

AssertionError with four byte size difference when converting #421

Open sunsided opened 7 years ago

sunsided commented 7 years ago

I'm getting a rather weird error trying to convert a darknet trained Tiny YOLO (adjusted model, transfer learned using a custom dataset) using flow --savepb, which complains about finding an unexpected file size. The size difference appears to be exactly four bytes though:

Traceback (most recent call last):
  File "./flow", line 6, in <module>
    cliHandler(sys.argv)
  File "/home/mmayer/dev/ml/darkflow/darkflow/cli.py", line 22, in cliHandler
    tfnet = TFNet(FLAGS)
  File "/home/mmayer/dev/ml/darkflow/darkflow/net/build.py", line 58, in __init__
    darknet = Darknet(FLAGS)
  File "/home/mmayer/dev/ml/darkflow/darkflow/dark/darknet.py", line 27, in __init__
    self.load_weights()
  File "/home/mmayer/dev/ml/darkflow/darkflow/dark/darknet.py", line 82, in load_weights
    wgts_loader = loader.create_loader(*args)
  File "/home/mmayer/dev/ml/darkflow/darkflow/utils/loader.py", line 105, in create_loader
    return load_type(path, cfg)
  File "/home/mmayer/dev/ml/darkflow/darkflow/utils/loader.py", line 19, in __init__
    self.load(*args)
  File "/home/mmayer/dev/ml/darkflow/darkflow/utils/loader.py", line 77, in load
    walker.offset, walker.size)
AssertionError: expect 63184556 bytes, found 63184560

I was trying it with different versions of TensorFlow, specifically 1.0.1 and 1.3.1, but that didn't change anything. Does anyone have an idea what could trigger this issue?

sunsided commented 7 years ago

This comment on #107 suggests that training from scratch might solve this issue. I retrained the network using darknet an converted it again, but do still receive the same error.

sunsided commented 7 years ago

This comment suggests to change self.offset = 16 to self.offset = 20 in utils/loader.py's weights_walker.__init__() method. If I do that the error disappears but I have no idea if that is a smart thing to do.

QueenJuliaZxx commented 6 years ago

I meet this problems too,I think it is caused by the unpair between .weight and .cfg , maybe it is a little cue, but I have no idea to solve it,so sorry

shangliy commented 6 years ago

Modify loader.py under darkflow/utils may help. Change the line 121 from self.offset = 16 to self.offset = 20~~~ This work for me, hope help~

QueenJuliaZxx commented 6 years ago

thank you for your help,i have solve it ,thankyou again

发自我的 iPhone

在 2017年11月16日,03:52,shangliy notifications@github.com 写道:

Modify loader.py under darkflow/utils may help. Change the line 121 from self.offset = 16 to self.offset = 20~~~ This work for me, hope help~

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

wingerboy commented 6 years ago

i have Changed the line 121 from self.offset = 16 to self.offset = 20! but the same error not disappear!

wingerboy commented 6 years ago

why should we change this number "self.offset" value

ttorkar commented 6 years ago

My guess is that the offset that deals with the difference between c and python but I could be wrong. Can you try reduce the offset to 12 to keep the expected bytes equal to the actual bytes. Let me know how that goes.

wingerboy commented 6 years ago

This is my training output used darkflow, please tell me, what is the format of the file, why not get the .CKPT format file! How can I generate the required weight file for tensorflow?(.ckpt) image

ttorkar commented 6 years ago

@yw455801125 how did you get it working? You can convert it by using --savepb or something similar. It is in the Readme.

shangliy commented 6 years ago

@yw455801125 The weights I used to transform are from Darknet not darkflow. The weights storage format from Darkflow and Darknet are different. So, I guess my solution may not work on your case.

nicolefinnie commented 6 years ago

@yw455801125 I think it's because the size of the header of the most up-to-date yolo v2 weights changed from 16 bytes to 20 bytes, so the weights_walker doesn't reach the end of the file because it expects an older header size. If I hit the same problem, I'd try to change the self.offset from 16 to file size - expected size, in case the weight files change again.

fbadaud commented 6 years ago

@yw455801125 in case you have not solved this issue yet or for others , you need to upgrade your darkflow installation after your modification of darkflow/utils/loader.py you can use: pip install . --upgrade anyway i got another error now with labels mismatches: /anaconda2/lib/python2.7/site-packages/darkflow/net/yolo/init.py", line 24, in constructor ).format(meta['model']) AssertionError: labels.txt and ../darknet/cfg/yolov2-tiny.cfg indicate inconsistent class numbers

hsgaurav commented 6 years ago

go the same error AssertionError: labels.txt and ../darknet/cfg/yolov2-tiny.cfg indicate inconsistent class numbers please someone have any answer REPLY

fbadaud commented 6 years ago

@HsGaurav to fix error in labels i just link the labels.txt to the corresponding file with list of label used on the dataset on which the network as been trained. for example for yolov2-voc I linked to darknet/data/voc.names etc...

adhi-thirumala commented 5 years ago

@fbadaud how do you link a file

DigvijaySingh7720 commented 5 years ago

Error :- AssertionError: expect 63184556 bytes, found 63184560

Solution : " ./darkflow/utils/loader.py" at line 121, you will find self.offset= 16 or 20. update to be done : - found 63184560 - expect 63184556 = 4, then add 4 to self.offset = add this 4 (or any other value) diff to 16 or 20 and then run your command again.

Best of Luck, it work for me, hope it may work for you as well, keep helping other.