yolov4-deepsort icon indicating copy to clipboard operation
yolov4-deepsort copied to clipboard

Different Yolov4 .cfg file

Open victorvargass opened this issue 5 years ago • 27 comments

When I use a different .weights trained from another .cfg Yolov4 configuration file, gives me the following error:

File "save_model.py", line 50, in save_tf utils.load_weights(model, FLAGS.weights, FLAGS.model, FLAGS.tiny) File "/home/redbird/Escritorio/2020/3. CAR-DETECTION/yolov4-custom-functions-master/core/utils.py", line 143, in load_weights conv_weights = conv_weights.reshape(conv_shape).transpose([2, 3, 1, 0]) ValueError: cannot reshape array of size 4604005 into shape (1024,512,3,3)

How can I set a different .cfg to the FLAGS or something like that? Your work is amazing!, and I need to use another configuration for my trained Yolov4 Thank you!

victorvargass avatar Oct 14 '20 22:10 victorvargass

Assuming that you are using custom classes for training (to obtain the weights), then look at core/config.py . You need to change __C.YOLO.CLASSES value to use the path to your custom classes file. Wrong value in this variable is usually what causes failure in array dimension/shape conversion.

pinczakko avatar Oct 15 '20 12:10 pinczakko

Okay thanks! I changed __C.YOLO.CLASSES to my .names path file and I could effectively generate the weights in tensorflow, but... when I run detect.py or detect_video.py there no detections at all, why?

victorvargass avatar Oct 15 '20 12:10 victorvargass

did you start the training with the "default"/"base" weights from Yolov4 as explained at: https://github.com/AlexeyAB/darknet#how-to-train-to-detect-your-custom-objects ? If not then you need to retrain by using the "base" weights (either yolov4.conv.137 or yolov4-tiny.conv.29), because the training step is basically "transfer learning".

If you've followed Alexey's guide then I'm at a loss as to what exactly happened because in my case it works perfectly. Well, I still need to do some tuning, but for basic custom object detection and tracking, it works.

pinczakko avatar Oct 15 '20 13:10 pinczakko

Yeah, I did the training like Alexey's repo said (with yolov4.conv.137) Did you try with a different .cfg from original yolov4.cfg file? This zip contains original yolov4 and my cfg files... maybe the different masks or anchors make the difference...

yolov4-cfg-files.zip

victorvargass avatar Oct 15 '20 13:10 victorvargass

Yeah, I did the training like Alexey's repo said (with yolov4.conv.137) Did you try with a different .cfg from original yolov4.cfg file? This zip contains original yolov4 and my cfg files... maybe the different masks or anchors make the difference...

yolov4-cfg-files.zip

Yes, I modified the cfg files (both tiny and full model cfg) according to the README file (how to train custom objects section), but I didn't make changes to either masks or anchors setting. I only change settings related to the classes or other that's derived from it and also activated random flag for training.

pinczakko avatar Oct 16 '20 01:10 pinczakko

Yes, I just did another training with the AlexeyAB repository and the detections worked fine, except for the size of the Bounding Boxes, I imagine it is because I used other anchors, is there a way to use custom anchors?

victorvargass avatar Oct 16 '20 14:10 victorvargass

Yes, I just did another training with the AlexeyAB repository and the detections worked fine, except for the size of the Bounding Boxes, I imagine it is because I used other anchors, is there a way to use custom anchors?

in my experience, one of the factor that determines the size of the bounding box is how the data is labeled. I've had similar problem before where the size of the bounding boxes fluctuates in a very wide range (up to 2 times the object size). I traced it back to badly labeled datasets--where the labeling is waaay outside of the object to be detected (it was labeled by another team). Once I fixed the labeling, everything went back to normal. Well, after all machine learning is GIGO (garbage in garbage out), if it's fed with "garbage" training datasets, what comes out is "garbage" as well.

pinczakko avatar Oct 16 '20 22:10 pinczakko

Yeah, I understand what you say, but I think the problem is due to the anchors, because with the same weight file, in other codes, even in Alexey AB's detector, the bounding boxes work fine

victorvargass avatar Oct 16 '20 23:10 victorvargass

No, it was not my dataset's fault, I effectively trained with the original yolov4.cfg anchors, converted the weights and it worked fine, with correct Bounding Boxes...:D thank you anyway!

In other hand, I want to edit the count function for a global counting for any class, have you done something like that?

victorvargass avatar Oct 17 '20 15:10 victorvargass

@victorvargass hi !I also encountered the same problem as you, when I use own weights and run detect.py or detect_video.py there no detections at all.What codes have you changed to solve this problem.

ronger-git avatar Oct 22 '20 04:10 ronger-git

@victorvargass hi !I also encountered the same problem as you, when I use own weights and run detect.py or detect_video.py there no detections at all.What codes have you changed to solve this problem.

What anchors did you use in your training .cfg file?, if you used the generated custom anchors by calculate_anchors.py script by AlexeyAB, you will have the same problems than me.

For this yolov4-deepsort repo, you have to re-train your model with yolov4 original anchors (without any change of that): https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4.cfg#L967 anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401

victorvargass avatar Oct 22 '20 14:10 victorvargass

I use the original anchors to train my model(yolov4-custom.cfg), but nothing can be detected. But AlexeyAB detections worked well.

ronger-git avatar Oct 23 '20 01:10 ronger-git

I use the original anchors to train my model(yolov4-custom.cfg), but nothing can be detected. But AlexeyAB detections worked well.

Can you upload your yolov4-custom.cfg file?

victorvargass avatar Oct 23 '20 01:10 victorvargass

that is my cfg file: https://github.com/ronger-git/darknet/blob/master/cfg/yolov4-ship.cfg I only modified the 'classes','filters','max_batches' and 'steps' from original yolov4-custom.cfg files: https://github.com/AlexeyAB/darknet/blob/master/cfg/yolov4-custom.cfg

ronger-git avatar Oct 23 '20 02:10 ronger-git

Did you define your --input_size flag when you run save_model.py? How did you run this script?

victorvargass avatar Oct 23 '20 17:10 victorvargass

I did not modify the input_size. I only modify the path of weights and output.Then use 'python save_model.py --model yolov4' to run.

ronger-git avatar Oct 24 '20 06:10 ronger-git

I did not modify the input_size. I only modify the path of weights and output.Then use 'python save_model.py --model yolov4' to run.

But you must specify the --input-size flag cause the Yolov4 input size default value is 416 but you trained your model with an input size of 608 (is in your .cfg file).

So to save your model correctly you have to run this:

python save_model.py --weights weights_path --output output_weights_path --input_size 608 --model yolov4

And then to run the detecctions: python detect.py --weights output_weights_path --size 608 --model yolov4 --images image_path

victorvargass avatar Oct 24 '20 13:10 victorvargass

我没有修改input_size。 我只修改权重和输出的路径,然后使用'python save_model.py --model yolov4'运行。

但是您必须指定--input-size标志,因为Yolov4输入大小的默认值为416,但是您使用608的输入大小来训练模型(位于.cfg文件中)。

因此,要正确保存模型,您必须运行以下命令:

python save_model.py --weights weights_path-输出output_weights_path --input_size 608 --model yolov4

然后运行检测: python detect.py --weights output_weights_path --size 608 --model yolov4 --images image_path

I did as you said, but still no targets were detected. I can't find the reason. By the way, is it correct that there is nothing in the 'assert' folder of the saved model?

ronger-git avatar Oct 25 '20 04:10 ronger-git

Hi all! I also trained YOLO v4 on the custom data. It's detecting for detection but for deep sort, after converting, when I run objecting tracking.py, python object_tracker.py --video ./data/video/test.mp4 --weights ./checkpoints/my_custom_yolov4-416 --size 416 --model yolov4 --tiny False --video './data/video/video3.mp4

I am getting nothing. Anyone can help.........

sharoseali avatar Oct 27 '20 18:10 sharoseali

Did you changed the anchors or masks the from cfg file when you trained your Yolov4 model?

victorvargass avatar Nov 12 '20 21:11 victorvargass

Did you changed the anchors or masks the from cfg file when you trained your Yolov4 model?

No, I didn't change mask and anchors, but for small object detection, I change the upsampling layer from 2 to 4. I also tried a trained model on custom classes without changing the upsampling layer. again it didn't detect or show anything.

sharoseali avatar Nov 12 '20 21:11 sharoseali

I have trained my own yolov4 model and used those weights, changed coco.name, did all things mentioned in this thread but not able to detect anything when I run tracker. Please help me

pranavk2050 avatar Dec 04 '20 13:12 pranavk2050

If anyone sees this, I was having the same issues. I finally figured out that I had to uncomment Step 3, run it, and then re-run everything again in order to get it to work! hope this helps someone!

JefeDryden avatar Jan 19 '21 07:01 JefeDryden

I have trained my own yolov4 model and used those weights, changed coco.name, did all things mentioned in this thread but not able to detect anything when I run tracker. Please help me : I hadn't trained enough to make model detect. I am able to detect objects now after training for 10000 batches

pranavk2050 avatar Jan 19 '21 10:01 pranavk2050

I have trained my own yolov4 model and used those weights, changed coco.name, did all things mentioned in this thread but not able to detect anything when I run tracker. Please help me : I hadn't trained enough to make model detect. I am able to detect objects now after training for 10000 batches

Hi @pranavk2050 does the DeepSORT algorithm (i.e. the object tracker algorithm) require that the object detection part be extremely good at its job (i.e. to detect) and so, you had to train it longer?

Arpitrf avatar Mar 03 '21 17:03 Arpitrf

I have trained my own yolov4 model and used those weights, changed coco.name, did all things mentioned in this thread but not able to detect anything when I run tracker. Please help me : I hadn't trained enough to make model detect. I am able to detect objects now after training for 10000 batches

Hi @pranavk2050 does the DeepSORT algorithm (i.e. the object tracker algorithm) require that the object detection part be extremely good at its job (i.e. to detect) and so, you had to train it longer?

yes..! that's why detection happened after that amount of batches

pranavk2050 avatar Mar 04 '21 12:03 pranavk2050

I have trained my own yolov4 model and used those weights, changed coco.name, did all things mentioned in this thread but not able to detect anything when I run tracker. Please help me : I hadn't trained enough to make model detect. I am able to detect objects now after training for 10000 batches

Hi @pranavk2050 does the DeepSORT algorithm (i.e. the object tracker algorithm) require that the object detection part be extremely good at its job (i.e. to detect) and so, you had to train it longer?

yes..! that's why detection happened after that amount of batches

Hey @pranavk2050, wanted to ask how many training images had you used to train your yolov4 model? And what was the MAP for the object detection (yolov4)?

Arpitrf avatar Mar 06 '21 09:03 Arpitrf