1

Here is my code:

from ultralytics import YOLO
model = YOLO('best.pt')
results = model.predict(
    source = '/Users/sereentaleb/Desktop/download.jpg',
    save=True,
    conf=0.25
)

This script will save my file in runs/detect/predict. However, I don't want it saved there. Is there a way to tell the function to save the file somewhere else? And is there a way to give the file (the file that I did the detection on) a name of my choosing?

I searched the ultralytics documentation for an answer and I couldn't find anything that helped.

1 Answer 1

0

If you only need to save a small number of test results, you can try using the following method to save them to your desired location.

import cv2
import numpy as np
import matplotlib.pyplot as plt
from ultralytics import YOLO

# # Load the YOLOv8 model
model = YOLO('yolov8n.pt')
image_data = 'pic.png'

# read your image
img = cv2.imread(image_data)
# predict return result
result = model(img)[0].plot()
# save path
file_path = r'./save/save_img.jpg'
cv2.imwrite(file_path,result)

# show result
res = cv2.cvtColor(result, cv2.COLOR_BGR2RGB)
plt.imshow(res)
plt.axis('off')
plt.show()

# Note: This program originates from my own work. To meet the requirements of the problem,
# I utilized AI assistance in some parts. After successful implementation and reviewing the rules,
# I am publishing it.
Sign up to request clarification or add additional context in comments.

1 Comment

Ok, I got it. Thank you!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.