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

getting error when converting yolo-obj.weights to yolo-obj.h5 #12

Closed
vihari1729 opened this issue Jun 18, 2020 · 9 comments
Closed

getting error when converting yolo-obj.weights to yolo-obj.h5 #12

vihari1729 opened this issue Jun 18, 2020 · 9 comments

Comments

@vihari1729
Copy link

Hi,
I have worked on training yolo-custom.weights with my own dataset. I took the mode(yolo-obj_1000.weights) when it finished 1000 iterations and tried to convert it to yolo-obj_1000.h5.
But I am getting the following error:

File "convert.py", line 171, in <module>
    yolo4_model = Yolo4(score, iou, anchors_path, classes_path, model_path, weights_path)
  File "convert.py", line 157, in __init__
    self.load_yolo()
  File "convert.py", line 98, in load_yolo
    buffer=weights_file.read(weights_size * 4))
TypeError: buffer is too small for requested array

also while testing my custom model yolo-obj_1000.weights, I am getting good results for images and videos

@LeonLok
Copy link
Owner

LeonLok commented Jun 19, 2020

Make sure these are correct:

model_path = 'model_data/yolo4.h5'
anchors_path = 'model_data/yolo_anchors.txt'
classes_path = 'model_data/coco_classes.txt'
weights_path = 'yolov4.weights'

@vihari1729
Copy link
Author

@LeonLok yes, I changed them and then the above error is coming. Is there anything to do with custom cfg file?.

@LeonLok
Copy link
Owner

LeonLok commented Jun 19, 2020

Perhaps this is not correct:

self.yolo4_model = yolo4_body(Input(shape=(416, 416, 3)), num_anchors//3, num_classes)

@vihari1729
Copy link
Author

vihari1729 commented Jun 19, 2020

Input shape, anchors and classes are correct.
when i am trying to convert yolov4.weights to keras, I am getting something like this:

Loading weights.
Weights Header:  0 2 5 [32032000]
Converting  0
Converting  1
Converting  2
Converting  3
.
.
.

and for my custom weights model, it is something like this:

Loading weights.
Weights Header:  0 2 5 [64000]
Converting  1
Converting  2
Converting  3
.
.
.

the weights (32032000 and 6400) are around too more for yolov4.weights compare to my model. Is there something to do with this or it doesn't matter?.

Should I train fully [ 2000 *3 i.e. according to darknet ,we should train for 2000 *len(labels) times ] for 6000 iterations and obtain weights file(yolo-obj_6000.weights), then I should convert it to keras model or I can convert yolo.weights model to keras model at any iteration?

@LeonLok
Copy link
Owner

LeonLok commented Jun 19, 2020

To be honest, I don't know. I've never had that problem.

Perhaps this is your problem: qqwweee/keras-yolo3#17 (comment)

I did not write convert.py. The original code is from Ma-Dan which used qqwweee's code as the frame. Please try asking there instead.

@LeonLok LeonLok closed this as completed Jun 19, 2020
@minhlu-i
Copy link

Hello, has anyone solved this problem yet?

@Melkeydev
Copy link

bump?

@harrysprogramming
Copy link

Any Fix?

@thundo
Copy link

thundo commented Aug 11, 2021

I stumbled into this issue too. The repo has repeated code for boilerplate of tensorflow2.0/deep-sort-yolov4 and tensorflow2.0/deep-sort-yolov4-low-confidence-track-filtering. Problem is that the convert.py in the two folders is different.

--- /deep-sort-yolov4-low-confidence-track-filtering/convert.py	2021-08-11 18:25:24.426847255 +0200
+++ /deep-sort-yolov4/convert.py	2021-08-11 17:23:33.364568240 +0200
@@ -69,9 +69,15 @@
         bns_to_load = []
         for i in range(len(self.yolo4_model.layers)):
             layer_name = self.yolo4_model.layers[i].name
-            if layer_name.startswith('conv2d_'):
+            if layer_name.startswith('conv2d'):
+                if layer_name == 'conv2d':
+                    convs_to_load.append((0, i))
+                else:
                 convs_to_load.append((int(layer_name[7:]), i))
-            if layer_name.startswith('batch_normalization_'):
+            if layer_name.startswith('batch_normalization'):
+                if layer_name == 'batch_normalization':
+                    bns_to_load.append((0, i))
+                else:
                 bns_to_load.append((int(layer_name[20:]), i))
 
         convs_sorted = sorted(convs_to_load, key=itemgetter(0))

You just need to copy the deep-sort-yolov4 version to the other folder and voilà, convert is now working.

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

6 participants