-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Results between OpenCV and Darknet CLI differ #5435
Comments
There are 3 different approaches for resizing: #232 (comment) For fair comparison you must use the same In the OpenCV are very strong tests for equivalence of network results, so there can be no different results. |
nms wrong |
The region layer in OpenCV performs NMS classwise. You can disable it by setting This has the side-effect of improving the performance by avoiding the switch to CPU for NMS during inference (this happens three times in total). |
Hi @AlexeyAB , I am having the same issues where the darknet version (darknet.py) is yielding different results from the opencv dnn implementation. Mostly in the confidence. At first, I thought it was related to image resizing and different methods being used (keeping/not keeping aspect ratio ecc.), but even trying different methods I couldn't align the confidences. Eventually I just resized the image to 416x416 using an external tool and used the resized image as input, so no resizing should be done. However I am still experiencing a difference in confidence. Here's my code for the DNN: inpWidth = 416
inpHeight = 416
custom_image_bgr = cv.imread(input_img, 1) # Also tried to remove this "1" here
custom_image = cv.cvtColor(custom_image_bgr, cv.COLOR_BGR2RGB) # Also tried to comment this and set swapRB to True
#custom_image = cv.resize(custom_image, (inpWidth, inpHeight), interpolation=cv.INTER_LINEAR) #Previous tests
blob = cv.dnn.blobFromImage(custom_image, scalefactor=(1/255), size=(inpWidth, inpHeight), mean=[0, 0, 0], swapRB=False,
crop=False, ddepth=cv.CV_32F) # Also tried with no ddepth, different scale factors, with/without mean
# Run a model
net.setInput(blob)
outs = net.forward(outNames) Of course, weights, classes and config file are exactly the same. Any ideas? Thank you! |
@arocketman Did you find any solution? |
@matt-sharp Are you facing the same problem? If yes, try the following:
|
@YashasSamaga I've tried setting the nms threshold to zero in my cfg file but this doesn't seem to change either the FPS or accuracy. I'm getting approx. 45FPS with 1 x Tesla v100 using:
To measure speed:
My F1-score is 0.88 when using Darknet detector test but only 0.75 with OpenCV 4.5.1. Please can you help me to understand if there is anything else I can do to improve the speed for inference and get the accuracy to match more closely to Darknet? |
@matt-sharp The NMS issue has been fixed since OpenCV 4.4 I think. The nms threshold fix is no longer required. What backend did you use? I think I have seen people get 100FPS on V100 with 608 x 608 images. What version of cuDNN are you using? cuDNN 8 caused some slowdowns. You might surpass 100+ FPS on FP16 target with cuDNN 7.
That's surprising. I had found the accuracy tests to be practically identical to Darknet. This was the script I used. mAP results from my calculations are here: opencv/opencv#17621. |
@YashasSamaga I'm using cuDNN 8 - libcudnn8-8.0.5.39-1.cuda11.0. |
Hi,
I have an issue with the results I obtained. On one hand, I run Yolo v3 ( OpenCV 4.2 with CUDA 10.2 and cuDNN 7.6.5). On the other hand, I recently compiled Darknet following the release of Yolo v4. It was compiled with CUDA and cuDNN (same versions) but the OpenCV_DIR used was the one from vcpkg and the version is 4.1.1 (I don't know if it matters, but I prefer to highlight it just in case).
Both use the same weights and the same config files starting with:
With the same image, I get different results:
Darknet CLI
PS> darknet.exe detector test cfg\coco.data cfg\yolov3.cfg path\to\yolov3\model.weights -thresh 0.25 -letter_box
E:\darknet-master\data\horses.jpg: Predicted in 31.315000 milli-seconds.
horse: 96%
horse: 100%
horse: 95%
horse: 25%
horse: 100%
OpenCV implementation
horse 99,67%
horse 99,52%
horse 96,78%
horse 89,76%
horse 33,61%
Here is the code that I use:
I also tried without the black border (and without -letter_box) but I get different results as well:
Darknet CLI:
horse: 88%
horse: 100%
horse: 91%
horse: 100%
OpenCV implementation:
horse 99,83%
horse 99,68%
horse 90,06%
horse 54,31%
Is there something is handled differently in OpenCV or is there a problem in my code?
Also, the original image size is 773x512, the image that I display with the OpenCV implementation is 608x608 (with or without borders) and the one that is displayed in command line is always 790x608. Is there any reason for such size?
Thank you very much for your help,
Jonathan Samelson
The text was updated successfully, but these errors were encountered: