AlexeyAB / darknet

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

Do I have to forward pass for every new detection threshold ? #2429

Open Moadab-AI opened 5 years ago

Moadab-AI commented 5 years ago

Hey AlexeyAB,

Thanks for the repository. I would like to know whether I have to forward pass for every different threshold at inference time separately? in other words is the threshold setting intertwined with the CNN layers or its just set at the end of forward pass?

I am interested in setting the lowest threshold (e.e. 0.0001) and pass the image once at detections time and have all possible detections (for higher thresholds) and be able to chose the correct threshold then by means of a sliding toggle over all thresholds. I have a feeling this is not possible, but just wanted to make sure. Thanks

AlexeyAB commented 5 years ago

@moabaom Hi,

You can compile Darknet as libdarknet.so library with LIBSO=1 in the Makefile, and use this library in your own application to detect object with low threshold=0.0001 and then filter it with higher threshold in your code multiple times as you want.

Moadab-AI commented 5 years ago

@moabaom Hi,

You can compile Darknet as libdarknet.so library with LIBSO=1 in the Makefile, and use this library in your own application to detect object with low threshold=0.0001 and then filter it with higher threshold in your code multiple times as you want.

Thanks, but I had already compiled with LIBSO=1 originally(I thought it was the default way). Can you be more specific as to how after I got results with thresh=0.0001 I could sweep over different threshold values and get different results ? I was browsing through the code to see how threshold is used and it looks like threshold is applied to every layer of the network separately. doesnt that mean I have to do a separate forward pass for every threshold separately? :

int num_detections(network *net, float thresh) { int i; int s = 0; for (i = 0; i < net->n; ++i) { layer l = net->layers[i]; if (l.type == YOLO) { s += yolo_num_detections(l, thresh); } if (l.type == DETECTION || l.type == REGION) { s += l.w*l.h*l.n; } } return s; }

pshwetank commented 4 years ago

Basically, what he mean is that you have to add a post-processing script after you get the results from YOLOv4. The script will again calculate the IOU between your ground truth and predictions. Once its done, you can put different threshold for different classes before calculating the mAP and average precision. This blog post might be helpful: https://towardsdatascience.com/evaluating-performance-of-an-object-detection-model-137a349c517b