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

Multiple overlapping boxes even with very low NMS threshold #6347

Open anant15 opened 4 years ago

anant15 commented 4 years ago

I am getting these multiple overlapping boxes in the prediction after training YOLOv4 on my custom dataset. I use confidence score = 0.8, and NMS threshold = 0.5. I tried reducing the NMS threshold to 0.05, but the number of boxes somewhat reduced but the boxes aren't well fitted. Please suggest ways to improve training or mitigate this problem in general.

PS: I am using 9 pairs of custom anchors, calculated for my dataset.

image
AlexeyAB commented 4 years ago

It seems you disabled NMS. What command do you use? Attach cfg-file.

I tried reducing the NMS threshold to 0.05, but the number of boxes somewhat reduced but the boxes aren't well fitted.

Show image.

anant15 commented 4 years ago

Thanks @AlexeyAB for a super quick response. Really grateful to you. I have already attached the image in my first comment, The image is a bit heavy and takes a little time to load.

For training, I used a command like this

./darknet detector train ../cfgYolov3/yolov4-custom.data ../cfgYolov3/yolov4-custom.cfg ../backupYolov3/july24_4_yolov4/yolov4-custom_best.weights -dont_show -mjpeg_port 8090 -map 2>&1 | tee -a ../log_july24_4_yolov4.txt

For checking predictions, I am using my own custom Python script as I wanted to check the results visually on multiple images.

The cfg file is as follows. I intentionally used leaky instead of mish because it was not supported with the current OpenCV version that I had; didn't to re-install and break things.

yolov4.txt

AlexeyAB commented 4 years ago

Show detection result by using command ./darknet detector test ... with the same image

OpenCV 4.4.0 supports YOLOv4 and mish: https://opencv.org/releases/

anant15 commented 4 years ago
./darknet detector test ../cfgYolov3/yolov4-custom.data ../cfgYolov3/yolov4-custom.cfg ../backupYolov3/july24_4_yolov4/yolov4-custom_last.weights -ext_output ../images_4/E000V1920-20200530062056_1fps_hand_head_annotations_000252.jpg

On using this, I get this error

image

Upgrading OpenCV will be a little challening. I work on an organization's computer, and I need to take permissions before installation or compiling anything. The training went well with leaky too.

image
AlexeyAB commented 4 years ago

Show prediction.png file

anant15 commented 4 years ago

predictions.jpg is a garbage 10X10 file which looks like a black blob.

Also, it showed Cannot load image ../images_4/E000V1920-20200530062056_1fps_hand_head_annotations_000252.jpg in the testing log.

AlexeyAB commented 4 years ago

use correct path

anant15 commented 4 years ago

image

This came out pretty well, I think there is some problem with NMS. I am using indexes = cv2.dnn.NMSBoxes(boxes, confidences, confThresh, nmsThresh), but the interesting thing is that this problem didn't arise until I was using the YOLOv3 model. But I will look into it. Thanks.

Just a request, if you could please add a functionality to check predictions on images placed in a directory, and save corresponding outputs somehwhere, it will be really helpful. Thanks a lot.

AlexeyAB commented 4 years ago

So the issue is in your Python code.

Read: https://github.com/opencv/opencv/wiki/ChangeLog#version440

State-of-art Yolo v4 Detector: #17148. Disabled per-layer NMS for [yolo] layers (Yolo v3 and Yolo v4) as incorrect - use cv::dnn::NMSBoxes over all the detections.

anant15 commented 4 years ago

Thanks a lot, @AlexeyAB , isn't somehow the support for testing the predictions for multiple images be done? I am not a C/C++ user and finding it difficult to extend your code.