Search code examples
pythondetectionyolodarknet

Darknet YOLOv4: show only selected classes


I'm trying to use the coco dataset, just to make detections for 4 classes. I use the YOLOv4 network. I changed the coco.data file like this:

classes= 4
train = /home/pjreddie/data/coco/trainvalno5k.txt
valid = coco_testdev
#valid = data/coco_val_5k.list
names = data/coco.names
backup = /home/pjreddie/backup/
eval=coco

, and the coco.names like this:

person
car
bus
truck

I also changed all the classes lines from 80 to 4 in the yolov4.cfg file and changed filters according to the 3*(classes+5) formula. When I pass a movie to the detector by using:

./darknet detector demo cfg/coco.data cfg/yolov4.cfg yolov4.weights -dont_show /mydrive/praca/videoname1.mkv -thresh 0.4 -i 0 -out_filename results.avi

It doesn't detect anything. What could be the issue?


Solution

  • If you do not have the time or resources to train, you can prevent the bounding boxes of other 76 objects from being drawn by replacing the unwanted classes with dont_show in the original coco.names file

    person
    dont_show
    car
    dont_show
    dont_show
    bus
    dont_show
    truck
    dont_show
    .
    .
    .
    (and so on)
    

    Reference: https://github.com/AlexeyAB/darknet/issues/7318#issuecomment-771603265