'How to access the save results of yolov5 in different folder?
I am using the below code to load the trained custom Yolov5 model and perform detections.
import cv2
import torch
from PIL import Image
model = torch.hub.load('ultralytics/yolov5', 'custom',
path='yolov5/runs/train/exp4/weights/best.pt', force_reload=True)
img = cv2.imread('example.jpeg')[:, :, ::-1] # OpenCV image (BGR to RGB)
results = model(img, size=416)
#To display and save results I am using:
results.print()
results.save()
results.show()
My question is how can I save the results in different directory so that I can use them in my web-based application. For your reference I am using Streamlit. For instance, at the moment, results (image) are being saved in runs\detect\exp*. I want to change it. Can anyone please guide me.
Solution 1:[1]
You can make changes in the function definition of results.save(), the function can be found in the file yolov5/models/common.py. By default the definition is:
def save(self, labels=True, save_dir='runs/detect/exp'):
save_dir = increment_path(save_dir, exist_ok=save_dir != 'runs/detect/exp', mkdir=True) # increment save_dir
self.display(save=True, labels=labels, save_dir=save_dir) # save results
You can make changes in the save_dir argument to the desired save location and the files should be saved in the new directory.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Azhan Mohammed |
