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

Running from outside yolov5 folder fails since PR #4954 #5065

Closed
maltelorbach opened this issue Oct 6, 2021 · 5 comments · Fixed by #5129
Closed

Running from outside yolov5 folder fails since PR #4954 #5065

maltelorbach opened this issue Oct 6, 2021 · 5 comments · Fixed by #5129
Labels
bug Something isn't working

Comments

@maltelorbach
Copy link
Contributor

🐛 Bug

Running any yolov5-script from outside the yolov5 folder fails. This is a regression due to #4954 (which seems ironic because the PR should have make an arbitrary cwd possible but instead made it impossible ;) )

The attempt to determine a ROOT path relative to the cwd fails if that cwd is not a sub-path of ROOT.

To Reproduce

git clone https://github.com/ultralytics/yolov5.git /home/user/yolov5
cd /home/user/yolov5
[install requirements etc...]
mkdir /home/user/other-dir
cd /home/user/other-dir
python /home/user/yolov5/train.py

Output:

Traceback (most recent call last):
  File "../yolov5/train.py", line 33, in <module>
    ROOT = ROOT.relative_to(Path.cwd())  # relative
  File "/home/user/.pyenv/versions/3.8.12/lib/python3.8/pathlib.py", line 908, in relative_to
    raise ValueError("{!r} does not start with {!r}"
ValueError: '/home/user/yolov5' does not start with '/home/user/other-dir'

Expected behavior

The training to start.

Additional context

This worked before #4954

The same PR resulted in these issues: #4973 and #4970 where custom model could not be loaded from torch hub. That issue has been fixed, but not the above mentioned.

@maltelorbach maltelorbach added the bug Something isn't working label Oct 6, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2021

👋 Hello @maltelorbach, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://ultralytics.com or email Glenn Jocher at [email protected].

Requirements

Python>=3.6.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

$ git clone https://github.com/ultralytics/yolov5
$ cd yolov5
$ pip install -r requirements.txt

Environments

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

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), validation (val.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@maltelorbach
Copy link
Contributor Author

maltelorbach commented Oct 6, 2021

To offer a solution: falling back to os.path.relpath seems to do what is desired. But correct me if I'm missing something. os.path.relpath works with strings as well as path-like objects since Python 3.6. So instead of

ROOT = ROOT.relative_to(Path.cwd())

we can do

ROOT = Path(os.path.relpath(ROOT, Path.cwd()))

Only drawback is:

On Windows, ValueError is raised when path and start are on different drives.

Not sure if that's a case that needs to be covered.

In my example above, this would be the output:

>>> from pathlib import Path
>>> import os.path
>>> ROOT = Path("/home/user/yolov5")
>>> other = Path("/home/user/other")
>>> ROOT.relative_to(other)  # fails
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/malte/.pyenv/versions/3.8.12/lib/python3.8/pathlib.py", line 908, in relative_to
    raise ValueError("{!r} does not start with {!r}"
ValueError: '/home/user/yolov5' does not start with '/home/user/other'
>>> os.path.relpath(ROOT, other)  # works
'../yolov5'

@glenn-jocher
Copy link
Member

@maltelorbach thanks for the bug report! Your fix looks good, can you submit a PR please?

@maltelorbach
Copy link
Contributor Author

Of course, see: #5129

@glenn-jocher
Copy link
Member

@maltelorbach great, thank you!

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

Successfully merging a pull request may close this issue.

2 participants