Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

argument save_dir doesn't work #13041

Open
1 of 2 tasks
AN-ZE opened this issue May 23, 2024 · 5 comments
Open
1 of 2 tasks

argument save_dir doesn't work #13041

AN-ZE opened this issue May 23, 2024 · 5 comments
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@AN-ZE
Copy link

AN-ZE commented May 23, 2024

Search before asking

  • I have searched the YOLOv8 issues and found no similar bug report.

YOLOv8 Component

Train

Bug

use python environment train and predict.
results = model.train(data='ultralytics/cfg/datasets/VOC.yaml',
save_dir='/home/lutos/anze/ultralytics/yolov8n')
results = model(img_path,
save_dir='/home/lutos/anze/ultralytics/yolov8n_qrcode')

The save_dir argument doesn't work,
My thoughts #8912
adding this argument to the file(ultralytics/cfg/default.yaml) can fix this problem.

Environment

ubuntu20.04
git clone new master.

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@AN-ZE AN-ZE added the bug Something isn't working label May 23, 2024
Copy link

👋 Hello @AN-ZE, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher glenn-jocher added the invalid This doesn't seem right label May 23, 2024
@glenn-jocher
Copy link
Member

@AN-ZE there is no save_dir argument. For Predict mode arguments see https://docs.ultralytics.com/modes/predict/#inference-arguments

@AlexandreOuellet
Copy link

AlexandreOuellet commented May 29, 2024

Sorry to comment on an old PR, but I have an issue that is related to this PR.
Here's what I'm trying to do :

  1. Load a model
  2. do a prediction with visualize=True
  3. save that prediction and visualization in a folder

The issue that I encounter is saving the visualization. It appears that I can send overrides to predict() to use with the predictor, but save_dir was specifically removed from overrides in this PR specifically. How do I specify save_dir now? Using Result class is not good enough as I want to save the visualization created with predict(img, visualize=True) somewhere I know. Since the predictor is essentially "lazy loaded", and since it removes the save_dir as a feature, I can't really rely on doing predict(img, visualized=True, save_dir="/tmp/somedir"). Do I now need to do an empty predict, then pass in an override?

I expected to be able to do something like this :

temp_dir = tempfile.mkdtemp()
model.predict(image, visualize=True, save_dir=temp_dir)

Instead, I seem to be forced to actually move the files after the fact, like this :

model.predict(image, visualize=True)
#move everything into the tmp folder
temp_dir = tempfile.mkdtemp()
shutil.move(model.predictor.save_dir, temp_dir)

Why was save_dir removed in #4480?

Update: https://docs.ultralytics.com/reference/engine/predictor/ seems to still refer to an argument called save_dir, so I would have expected it to be able to be overriden.

@glenn-jocher
Copy link
Member

@AlexandreOuellet hello! Thanks for reaching out with your query. I understand the confusion regarding the save_dir parameter.

In the current implementation of the YOLOv8 predict() method, the save_dir parameter isn't directly modifiable as an argument. Instead, the results and visualizations are automatically saved in the runs/predict directory under the project directory.

To save the visualizations to a specific directory, you can indeed move the files after prediction as you've described. Here's a streamlined approach:

import shutil
import tempfile
from ultralytics import YOLO

# Load your model
model = YOLO('path/to/model.pt')

# Run prediction
results = model.predict('path/to/image.jpg', visualize=True)

# Create temporary directory and move files
temp_dir = tempfile.mkdtemp()
for path in results.files:
    shutil.move(path, temp_dir)

This method ensures that all generated files from the prediction are moved to your desired temporary directory.

We appreciate your feedback on this, and I'll relay it to our development team to consider reintroducing or modifying the save_dir functionality in future updates. If you have any more questions or need further assistance, feel free to ask. Happy coding! 🚀

@AN-ZE
Copy link
Author

AN-ZE commented Jun 3, 2024

@AlexandreOuellet
Hi, your problem is actually the same as mine.
ultralytics/cfg/default.yaml
The reason is that the file yaml not have save save_dir parameter. Just add it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants