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

Error while loading weights #1042

Open aaditnaren opened 5 years ago

aaditnaren commented 5 years ago

After placing the .weights and .cfg (after editing it in accordance to my classes) files properly and also the images and their annotations, I get an error while running the code.

import cv2 from darkflow.net.build import TFNet import matplotlib.pyplot as plt

%config InlineBackend.figure_format = 'svg'

options = { 'model' : 'cfg/yolo.cfg', 'load' : 'bin/yolo.weights', "batch": 8, "epoch": 25, 'threshold' : 0.3, "annotation": "./annotations/", "dataset": "./images/" }

tfnet = TFNet (options) tfnet.train()

OUTPUT: Parsing ./cfg/yolo.cfg Parsing cfg/yolo.cfg Loading bin/yolo.weights ...


AssertionError Traceback (most recent call last)

in 11 12 ---> 13 tfnet = TFNet (options) 14 tfnet.train() ~\Desktop\darkflow-master\darkflow\net\build.py in __init__(self, FLAGS, darknet) 56 57 if darknet is None: ---> 58 darknet = Darknet(FLAGS) 59 self.ntrain = len(darknet.layers) 60 ~\Desktop\darkflow-master\darkflow\dark\darknet.py in __init__(self, FLAGS) 25 self.meta, self.layers = des_parsed 26 ---> 27 self.load_weights() 28 29 def get_weight_src(self, FLAGS): ~\Desktop\darkflow-master\darkflow\dark\darknet.py in load_weights(self) 80 81 args = [self.src_bin, self.src_layers] ---> 82 wgts_loader = loader.create_loader(*args) 83 for layer in self.layers: layer.load(wgts_loader) 84 ~\Desktop\darkflow-master\darkflow\utils\loader.py in create_loader(path, cfg) 103 load_type = checkpoint_loader 104 --> 105 return load_type(path, cfg) 106 107 class weights_walker(object): ~\Desktop\darkflow-master\darkflow\utils\loader.py in __init__(self, *args) 17 self.src_key = list() 18 self.vals = list() ---> 19 self.load(*args) 20 21 def __call__(self, key): ~\Desktop\darkflow-master\darkflow\utils\loader.py in load(self, path, src_layers) 75 assert walker.offset == walker.size, \ 76 'expect {} bytes, found {}'.format( ---> 77 walker.offset, walker.size) 78 print('Successfully identified {} bytes'.format( 79 walker.offset)) AssertionError: expect 202335260 bytes, found 203934260 I tried multiple .weights files and .cfg files, but it is never resolved. The expected and found values change with accordance to the weights but the error is never resolved. I read a solution, where they added the difference between the found and expected values to the self.offset value in the /darkflow/utils/loader.py file, and many claimed that it worked. I tried the same but it didn't work for me. How do I resolve this?
kmarrip commented 5 years ago

after changing the yolo.cfg file save it as something else like yolo_1c.cfg in the same directory, u will have to keep the original yolo.cfg unchanged

Tanmay-Kulkarni101 commented 4 years ago

Check out this answer in stackoverflow- https://stackoverflow.com/a/58812151/6517340

Did it work out for you ?