Closed asaf0813 closed 3 years ago
@haspberry I'm not sure what you mean, can you elaborate? Instances of the same class are already separately identified by default, the persons and the ties are uniquely detected in the PyTorch Hub tutorial example:
This example shows batched inference with PIL and OpenCV image sources. results
can be printed to screen, saved to runs/hub
, showed to screen on supported environments, and returned as tensors or pandas dataframes.
import cv2
import torch
from PIL import Image
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Images
for f in ['zidane.jpg', 'bus.jpg']: # download 2 images
print(f'Downloading {f}...')
torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/releases/download/v1.0/' + f, f)
img1 = Image.open('zidane.jpg') # PIL image
img2 = cv2.imread('bus.jpg')[..., ::-1] # OpenCV image (BGR to RGB)
imgs = [img1, img2] # batch of images
# Inference
results = model(imgs, size=640) # includes NMS
# Results
results.print()
results.save() # or .show()
results.xyxy[0] # img1 predictions (tensor)
results.pandas().xyxy[0] # img1 predictions (pandas)
# xmin ymin xmax ymax confidence class name
# 0 749.50 43.50 1148.0 704.5 0.874023 0 person
# 1 433.50 433.50 517.5 714.5 0.687988 27 tie
# 2 114.75 195.75 1095.0 708.0 0.624512 0 person
# 3 986.00 304.00 1028.0 420.0 0.286865 27 tie
@glenn-jocher
In the photo above, two people (Zidane and Ancelotti) were recognized. I don't want person 0.62, person 0.87. i want person1 0.62, person2 0.87 to name.
add plus My project is to connect multiple ip cameras and detect whether an object is in the corresponding area using yolo. Thank you so much for your help.
@haspberry ah, well you can update the annotation strings to your needs. In detect.py you can modify the strings here for example: https://github.com/ultralytics/yolov5/blob/238583b7d5c19029920d56c417c406c829569c75/detect.py#L111-L114
@glenn-jocher I am really really grateful for your help. ❤
# Label names count
label_names_count_list = []
# Write results
for *xyxy, conf, cls in reversed(det):
if save_txt: # Write to file
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
with open(txt_path + '.txt', 'a') as f:
f.write(('%g ' * len(line)).rstrip() % line + '\n')
if save_img or view_img: # Add bbox to
label_names_count_list.append(names[int(cls)])
label_names_count = f'{names[int(cls)]}{label_names_count_list.count(names[int(cls)])}'
print(label_names_count)
# label = f'{names[int(cls)]} {conf:.2f}'
label = f'{label_names_count} {conf:.2f}'
plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=3)
In the photo, it's fine auto. This is because the accuracy of the first recognized object does not change in photos. However, when the accuracy of object recognition in real-time video is changed, it seems that the object is recognized as a new object rather than an existing object.
ex) Three cars were first recognized. car1 0.84 , car2 0.81, car3 0.53 1 second later car1 0.84, car2 0.53 car3 0.78 (Car 1>Car 1, Car 2>Car 3, Car 3>Car 2 It changes like this. I have a wrong explanation and attach a picture.)
You need temporal consistence of intance id's.
I think you can try to propagate id's from frame t to frame t+1 by looking at the IoU of the bounding boxes. Please note that moving objects can cause problems with this approach. You have to consider like
You may instead want to incorporate some object tracking algorithm to the repo.
@cahity hey buddy. Yes that's correct, we are not doing tracking at all and there is no assumption of relationships between images in a batch or between sequential batches etc.
For video/realtime inference this leaves a lot of room on the table for additional improvements based on AI or classical tracking methods like LSTM, KLT trackers, Kalman Filtering, etc.
If you'd like to contribute experiments in this direction that would be great!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
❔Question
I want to label an object of the same name with a new name once it is identified. Can you help?
I am using the original without using any other customized models(yolov5), datasets(coco), code. ex) car 0.9 car 0.7 car 0.4 -> car1 0.9 car2 0.7 car3 0.4
Additional context