-1

How can I save results to my own folder? I using YOLOv8

I tried to do this :

from ultralytics import YOLO


model = YOLO('yolov8n.pt', 'v8')

# input video path
input_path = r"C:\Users\user\PycharmProjects\Gen\Users\Per\pre_video\BAACAgIAAxkBAAICPGSP5ivdrC9mmwABPTyoVDnBtEAhswACHCcAAu5agEgK3IT3udd3Yy8E.mp4"

# output directory
output_dir = r"C:\Users\user\PycharmProjects\Gen\Users\Pre\post_video"

results = model.predict(source=input_path, conf=0.45)

# Save annotated frames to the output directory
results.save(save_dir = input_path)

but got an error :

video 1/1 (135/135) C:\Users\user\PycharmProjects\Gen\Users\Pre\pre_video\BAACAgIAAxkBAAICPGSP5ivdrC9mmwABPTyoVDnBtEAhswACHCcAAu5agEgK3IT3udd3Yy8E.mp4: 384x640 1 person, 77.6ms
Speed: 2.2ms preprocess, 67.7ms inference, 1.2ms postprocess per image at shape (1, 3, 640, 640)
Traceback (most recent call last):
  File "C:\Users\user\PycharmProjects\Gen\Yolo.py", line 15, in <module>
    results.save(save_dir = input_path)
    ^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'save'

Process finished with exit code 1

I search in the internet of solve this problem,so my code must work but it's not

LTS FG
  • 19
  • 5
  • The result variable is obviously a list, which does not have a save function. You should check the docs to find which object you should be using. – Itération 122442 Jun 19 '23 at 06:17
  • I saw, but idk how to use it, I mean I know how to use it but I don't know how to use it right, I need to use "save_dir = path" but how to use it right – LTS FG Jun 19 '23 at 13:11

2 Answers2

2

You should save it as following

model.predict(source=input_path, project="output_dir", name="smth")

It will be saved as output_dir/smth

0

You had done perfect just add one parameter which is project and update your code to

from ultralytics import YOLO


model = YOLO('yolov8n.pt', 'v8')

# input video path
input_path = r"path\to\folder\filename.extension"

# output directory
output_dir = r"path\to\output"

results = model.predict(source=input_path, conf=0.45, **project="path to output folder"**)

# Save annotated frames to the output directory
results.save(save_dir = input_path)
Mr. Hobo
  • 530
  • 1
  • 7
  • 22
Leo
  • 5
  • 1