LeonLok / Deep-SORT-YOLOv4

People detection and optional tracking with Tensorflow backend.
GNU General Public License v3.0
496 stars 170 forks source link

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

Closed vihari1729 closed 4 years ago

vihari1729 commented 4 years ago

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 commented 4 years ago

Make sure these are correct: https://github.com/LeonLok/Deep-SORT-YOLOv4/blob/695ef5d20a22c91252e4b6dffbbb9a9511ae2a93/tensorflow1.14/deep-sort-yolov4/convert.py#L163-L166

vihari1729 commented 4 years ago

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

LeonLok commented 4 years ago

Perhaps this is not correct: https://github.com/LeonLok/Deep-SORT-YOLOv4/blob/695ef5d20a22c91252e4b6dffbbb9a9511ae2a93/tensorflow1.14/deep-sort-yolov4/convert.py#L54

vihari1729 commented 4 years ago

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 commented 4 years ago

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

Perhaps this is your problem: https://github.com/qqwweee/keras-yolo3/issues/17#issuecomment-384987027

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.

minhlu-i commented 4 years ago

Hello, has anyone solved this problem yet?

Melkeydev commented 4 years ago

bump?

harrysprogramming commented 4 years ago

Any Fix?

thundo commented 3 years ago

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.