Search code examples
computer-visionobject-detectionyolobounding-boxyolov4

How can I edit or remove the bounding box label text in YOLO (V4)?


I want to edit the bounding box label to show only the probability of detection and not the class label, How shall I do this?

I found a file called image.c in darknet/src which I think is where my edits need to be made. But there are multiple functions in it that seem relevant for this task and I'm not sure which one to edit, and how to edit to get what I want. The code in image.c in quite long, hence kindly refer to this link (official darknet repo) where the code I'm referring to is available.

I tried editing the function void draw_detections at line 465 by simply changing the code at line 511 to printf("%s: %.0f%%", " ", prob * 100);, ran the !make command but the labels were still present in detection.


Solution

  • Finally found how to do this:

    Locate the file darknet/src/image.c

    Delete lines of code at 436

    strcat(labelstr, names[selected_detections[i].best_class]);
    

    and from line 441 to 446

    for (j = 0; j < classes; ++j) { 
        if (selected_detections[i].det.prob[j] > thresh && j != selected_detections[i].best_class) { 
            strcat(labelstr, ", "); 
            strcat(labelstr, names[j]); 
        } 
    } 
    

    Make sure to rebuild the darknet in the project (!make)

    Note:These changes will erase out if the darknet repository is cloned again.