'Changing darknet weights into tensorflow weights

I used this https://github.com/theAIGuysCode/tensorflow-yolov4-tflite rep to create my own yolov4 detection. The detection with the yolov4.weights and coco.names works just fine on images/videos/webcam.

Next I trained my own weights file with a custom dataset by using darknet: ./darknet detector train cfg/obj.data cfg/yolov4.cfg yolov4.conv.137

Now I want to use these weights to work with tensorflow. To achieve this I followed the instructions explained under "Using Custom Trained YOLOv4 Weights" in the rep. I.e. I have created a custom.names file with my classes and saved it in the corresponding directory. I also changed the path in the config.py file.

But still I get following error:ValueError: cannot reshape array of size 2309394 into shape (1024,512,3,3)



Solution 1:[1]

You need to convert your weights with save_model.py and make sure you specify the same pixel size for the --input_size you trained at.

Example: If you trained in darknet at width and height 608

python save_model.py --weights ./data/your-custom-trained-yolov4.weights --output ./checkpoints/your-custom-trained-yolov4 --input_size 608 --model yolov4

Also: edit core/config.py line 14 __C.YOLO.CLASSES = "./data/classes/coco.names" to __C.YOLO.CLASSES = "./data/classes/yourCustom.names" or whatever you called your names file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1