Bilal Ahmed
Bilal Ahmed

Reputation: 1

Que: How to get detected label from yolov5 and store it into an array

This is my code:

# For Yolov5 command

#clone YOLOv5 
!git clone https://github.com/ultralytics/yolov5  # clone repo
%cd yolov5
%pip install -qr requirements.txt # install dependencies
%pip install -q roboflow

import torch
import os
from IPython.display import Image, clear_output  # to display images

print(f"Setup complete. Using torch {torch.__version__} ({torch.cuda.get_device_properties(0).name if torch.cuda.is_available() else 'CPU'})")

For training command
!python train.py --img 597 --batch 16 --epochs 100 --data {dataset.location}/data.yaml --weights yolov5s.pt --cache

For detecting command
!python detect.py --weights runs/train/exp/weights/best.pt --img 416 --conf 0.1 --source /content/IMG-20221220-WA0031.jpg

Command Log

Upvotes: 0

Views: 647

Answers (1)

Rafael
Rafael

Reputation: 53

If you see the detect.py code, there are these lines (158-160):

# Print results
for c in det[:, 5].unique():
  n = (det[:, 5] == c).sum()  # detections per class
  s += f"{n} {names[int(c)]}{'s' * (n > 1)}, "  # add to string

n is the number of detections for a determinate class (name[int(c)]), which is stored in s. You can append n and name[int(c)] to an array, dictionary or JSON and save it.

Upvotes: 1

Related Questions