Reputation: 1
I would like yolov8 to display the sum of each of the classes in an image on the CLI.
In yolov7 for example, when I run inference on a custom data set it displays something like this:
12 capacitor-sam2s, 5 capacitor-mur1s, 5 capacitor-mur2s, 1 rfid, 1 ntc, 2 resistor-packs, Done. (1513.7ms) Inference, (55.4ms) NMS
How do I do this with yolov8?
It doesn't display the results on the command line.
Upvotes: 0
Views: 233
Reputation: 85
I would recommend you to achieve this in python and not via bash.
You have to route the corresponding labels to a dictionary.
You can do it like this:
model = YOLO(MODEL_NAME)
results = model.predict(imgsz=1024, source=filepath, save=False, conf=min_conf_threshold) # source already setup
dictionary = {}
for r in results:
for c in r.boxes.cls:
labelnames = model.names[int(c)]
dictionary[labelnames ] = dictionary.get(labelnames, 0) + 1
and afterwards you can simply sum it up over all classes:
amount = sum(dictionary.values())
dictionary["Cumulated"]= amount
for i in dictionary:
print (i + str(":"), dictionary[i])
Upvotes: 1