Closed Laudarisd closed 3 years ago
@Laudarisd you can use the --save-txt
argument in test.py and detect.py to autolabel images.
Let me try, Thanks alot.
Thank you @glenn-jocher It helped me. Is there any chance to save a csv file with xmin, ymin, xmax, ymax without yolo format?
Thank you for your time.
@Laudarisd you can customize the code here: https://github.com/ultralytics/yolov5/blob/3f74cd9ed1a17de94ed4a19dcefbaa3b27d16a95/detect.py#L101-L108
Thank you @glenn-jocher I will try. If I stuck here I will come back. Really appreciate your answer and time for reviewing my question. Thanks a lot.
@Laudarisd also note that the YOLOv5 PyTorch Hub models can present results as pandas dataframes which include the class names:
import cv2
import torch
from PIL import Image
# Model
model = torch.hub.load('ultralytics/yolov5', 'yolov5s')
# Images
for f in ['zidane.jpg', 'bus.jpg']:
torch.hub.download_url_to_file('https://ultralytics.com/images/' + f, f) # download 2 images
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
@Laudarisd and the PyTorch Hub model results can be presented in 4 different formats, including xyxy and xyxy normalized: https://github.com/ultralytics/yolov5/blob/b7cd1f540d5815b0a1cf2e23ce82a5fdb8f6b525/models/common.py#L308-L311
Thank you so much @glenn-jocher I will go through this one.
Hi @glenn-jocher when I tried to load model from my local. it show HTTPError: HTTP Error 404: Not Found
error.
Could you kindly give me little hint ?
I tried to upload model as
path = "./"
model = torch.hub.load(path, 'last')
Similarly tried to import images as
for f in glob.glob('./test/*'):
#torch.hub.download_url_to_file("./test/" + f, f)
img = Image.open(f)
Thank you.
@Laudarisd see PyTorch Hub tutorial for directions on loading local YOLOv5 models:
Thanks @glenn-jocher .
I will really appreciate your suggestions.
Recently I am trying to do object detection project for my personal project. To run training I need lots of images and annotation files. For that I managed to do almost 800 annotations files. But it takes lots of time to collect such annotation files.
So I tried to do training for 800 images and corresponding annotation files with
YOLO-V5
. Now I have.pt
model and it gives me around 80% detection box on my test images.I want to save those bounding box , image name, and class in csv so that I can create more annotations files for next training.
So How can I extract those parameters in csv ?
Import library and functions
I guess this part loads model and classifier
I guess in this part we get normalize boxes, prediction with classes and accuracy.
I guess we get tensor value from
pred
(in this section) which are related to bounding boxes.I tried to add this script after this
pred
sectionI somehow managed to save only one tensor value in one cell (all together) but couldn't go through loop for other parameters.
Any help would be appreciated.
And it would be a great help for me to generate annotation files.
Hoping for your kind answer.
Thank you