AlexeyAB / darknet

YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
http://pjreddie.com/darknet/
Other
21.65k stars 7.96k forks source link

Convert custom training CSP-YOLOv4 weights to Tensorflow #7539

Open RFedererno1 opened 3 years ago

RFedererno1 commented 3 years ago

Thank you for your contribution for community with this very good YOLO implementation. I have converted yolov4-csp.weights file with yolov4-csp.cfg for COCO dataset you published to tensorflow and it worked fine. In darknet: darknet_coco_result And my weight convert implementation: tf_coco_result As you can see, the results from darknet and tf with yolov4-csp.weights on COCO dataset are very close and they are accurate. Then i trained yolov4-csp on my custom model on detecting face/facemask on darknet. Its result is very good on darknet detector. But after converting it to tf model, it cannot detect any object. The only change i made to config file is replace last filter from 255 = (5 + 80)3 to 21 = (5 + 2)3. Is there any change to darknet source code ? Thanks for your answer.

AlexeyAB commented 3 years ago

What TF implementation did you use? Maybe in your implementation the number of classes are hardcoded in the Python code.

RFedererno1 commented 3 years ago

TF version is 2.4.1. I use colab for converting. In TF code, i changed number of filter in the last conv to 21. And when i get the weights from my custom model darknet weights, It got exactly the number of parameters in my TF model. It found that the mish function in darknet is different from the real mish function. Can it cause the problem to model calculation ?

AlexeyAB commented 3 years ago

It found that the mish function in darknet is different from the real mish function. Can it cause the problem to model calculation ?

This is the same Mish-function, just accelerated for CUDA.

Did you write your own code of Yolo for TF? Can you share both versions of your code for 80 classes and 2 classes?

RFedererno1 commented 3 years ago

Yes, i wrote my own model with the way of copying weight from darknet based on hunglc code. About the code, the first part of model is identical for 80 class and 2 class. The first change is the number of filter in the last conv: 80 classes: image 2 classes: image Then i decoded the output of the model, this is for 80 classes and 2 classes: image Last, i nms the predictions: 80 classes: image 2 classes: image

Everything else is identical for both 80 classes and 2 classes. For the link to my source code: https://colab.research.google.com/drive/1IaVXKKG12ghh7Iu3ZHIBig_fs3nR653c?usp=sharing

RFedererno1 commented 3 years ago

This is 1 result i ran on darknet and TF with the same weight i trained on darknet: darknet: image It is pretty good. TF: image It can predict some of objects, but very bad accurate. Maybe because the resize, RGB, of model calculation for floating foint ?