ultralytics / ultralytics

Ultralytics YOLO11 🚀
https://docs.ultralytics.com
GNU Affero General Public License v3.0
36.33k stars 7k forks source link

Dir Not Found: How to Set Conda Environment to Reference Current Directory's Code/Settings? #18950

Closed khandriod closed 1 week ago

khandriod commented 1 week ago

Search before asking

Question

I have multiple Conda environments (e.g., yolov8, yolov11) with separate YOLO installations. However, when I activate an environment, it continues to reference code and settings from a previous default directory instead of the current project directory.

Example:

Environment yolov8 should reference /projects/yolov8/code Environment yolov11 should reference /projects/yolov11/code But both currently point to an older directory (e.g., /projects/yolov8/code).

What I’ve Tried/Expected:

Installed YOLO in each environment separately. Expected each environment to use its own local code/settings when activated.

Question: How do I configure each Conda environment to prioritize the current working directory for code and settings?

OS: Ubuntu 22.04 (WSL2)

I just found this setting.json file

I have fixed the runs folder but should I have to set dataset and weights here ?

I have this setting.json file

JSONDict("/home/sdasl/.config/Ultralytics/settings.json"):
{
  "settings_version": "0.0.6",
  "datasets_dir": "/home/sdasl/yolo8/datasets",
  "weights_dir": "/home/sdasl/yolo8/ultralytics/weights",
  "runs_dir": "./runs",
  "uuid": "28e136f7ff23d1abad0a17879*****066fc0c2e4824d451f5aa77225cab6d3d76",
  "sync": true,
  "api_key": "",
  "openai_api_key": "",
  "clearml": true,
  "comet": true,
  "dvc": true,
  "hub": true,
  "mlflow": true,
  "neptune": true,
  "raytune": true,
  "tensorboard": true,
  "wandb": false,
  "vscode_msg": true
}

Error form CLI

Traceback (most recent call last):
  File "/home/sdasl/anaconda3/envs/yolo11/bin/yolo", line 8, in <module>
    sys.exit(entrypoint())
  File "/home/sdasl/yolo11/ultralytics/ultralytics/cfg/__init__.py", line 986, in entrypoint
    getattr(model, mode)(**overrides)  # default args from model
  File "/home/sdasl/yolo11/ultralytics/ultralytics/engine/model.py", line 802, in train
    self.trainer = (trainer or self._smart_load("trainer"))(overrides=args, _callbacks=self.callbacks)
  File "/home/sdasl/yolo11/ultralytics/ultralytics/engine/trainer.py", line 133, in __init__
    self.trainset, self.testset = self.get_dataset()
  File "/home/sdasl/yolo11/ultralytics/ultralytics/engine/trainer.py", line 566, in get_dataset
    raise RuntimeError(emojis(f"Dataset '{clean_url(self.args.data)}' error ❌ {e}")) from e
RuntimeError: Dataset '../data/data.yaml' error ❌
Dataset '../data/data.yaml' images not found ⚠️, missing path '/home/sdasl/yolov11/data/valid/images'
Note dataset download directory is '/home/sdasl/yolo11/data'. You can update this in '/home/sdasl/.config/Ultralytics/settings.json'
UltralyticsAssistant commented 1 week ago

👋 Hello @khandriod, thank you for your interest in Ultralytics 🚀! We recommend visiting the Docs for guidance, where you can find many Python and CLI usage examples, along with answers to many common questions.

If this is a 🐛 Bug Report or environment setup issue, please provide a minimum reproducible example detailing your exact setup and steps to replicate. This will help ensure we can debug effectively.

Suggestions for Conda Environments

It seems like your issue revolves around environment isolation and the way ultralytics is resolving paths. To troubleshoot:

  1. Ensure each Conda environment has a unique and up-to-date ultralytics installation.
  2. Double-check your PYTHONPATH configuration to ensure paths are correctly aligned with your current directory.
  3. Run the following inside each environment after activation to verify the YOLO version and path being used:
    python -c "import ultralytics; print(ultralytics.__version__, ultralytics.__file__)"

For real-time discussions and additional troubleshooting, we encourage you to join the Ultralytics community:

Upgrade

Ensure you're working with the latest ultralytics version to minimize potential issues. Upgrade in your respective environments using:

pip install -U ultralytics

Environments

YOLO is highly versatile and can be used in the following verified setups (with dependencies like CUDA/CUDNN, Python, and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are passing. CI tests cover all YOLO Modes and Tasks daily across various platforms.

This is an automated response to your issue, but rest assured, an Ultralytics engineer will assist you further as soon as possible. Thank you for your patience and understanding! 😊

khandriod commented 1 week ago

Hello, I have solved the issue. The path to dataset in data.yaml should be relative not absolute. Thanks

Y-T-G commented 1 week ago

It can be both absolute and relative. If it's relative, it will consider it relative to the datasets_dir in the settings, not your current working directory.

UltralyticsAssistant commented 1 week ago

Thanks for reporting this issue and for your patience! A potential fix has now been merged via PR #18953. This PR improves clarity in dataset configuration by explicitly documenting how relative paths behave. Specifically:

Huge thanks to the efforts of the PR author @Y-T-G and contributions from @glenn-jocher for addressing this!

To test if this update resolves your issue, you can:

  1. Install the latest changes directly using:
    pip install git+https://github.com/ultralytics/ultralytics.git@main
  2. Wait for the next official release on PyPI if you'd prefer to upgrade through the usual package update process.

Your feedback would be incredibly valuable! Please let us know if this resolves the issue for you or if you're still experiencing any challenges. Thank you again for reporting this, and feel free to share any further feedback or suggestions. 🙏