Skip to content

Conversation

glenn-jocher
Copy link
Member

@glenn-jocher glenn-jocher commented Mar 26, 2022

os.path.relpath() seems to have a major bug on Windows caused by Windows own horrible path handling. This fix attempts to sidestep the issue.

File "C:\Users\mkokg/.cache\torch\hub\ultralytics_yolov5_master\export.py", line 64, in
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
File "C:\Users\mkokg\AppData\Local\Programs\Python\Python310\lib\ntpath.py", line 718, in relpath
raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'D:'

More info at https://bugs.python.org/issue7195

Test script:

import torch

model = torch.hub.load('ultralytics/yolov5:fix/relpath', 'yolov5s', force_reload=True)

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Improved cross-platform path handling in YOLOv5's export and model scripts.

📊 Key Changes

  • Added import os and import platform to check the operating system type.
  • Conditionally set the ROOT path to be relative unless running on Windows.

🎯 Purpose & Impact

  • Purpose: To ensure proper path handling across different operating systems, addressing an issue where setting a relative ROOT path may cause errors on Windows.
  • Impact: Users on non-Windows systems will benefit from cleaner path management, while Windows users will have reduced risk of encountering path-related errors. This change promotes cross-platform compatibility, making YOLOv5 more robust and user-friendly. 🖥️🚀

os.path.relpath() seems to have a major bug on Windows due to Windows horrible path handling. This fix attempts to sidestep the issue.

```
File "C:\Users\mkokg/.cache\torch\hub\ultralytics_yolov5_master\export.py", line 64, in
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
File "C:\Users\mkokg\AppData\Local\Programs\Python\Python310\lib\ntpath.py", line 718, in relpath
raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'D:'
```
@glenn-jocher glenn-jocher merged commit e19f87e into master Mar 26, 2022
@glenn-jocher glenn-jocher deleted the fix/relpath branch March 26, 2022 13:18
BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
* Sidestep os.path.relpath() Windows bug

os.path.relpath() seems to have a major bug on Windows due to Windows horrible path handling. This fix attempts to sidestep the issue.

```
File "C:\Users\mkokg/.cache\torch\hub\ultralytics_yolov5_master\export.py", line 64, in
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
File "C:\Users\mkokg\AppData\Local\Programs\Python\Python310\lib\ntpath.py", line 718, in relpath
raise ValueError("path is on mount %r, start on mount %r" % (
ValueError: path is on mount 'C:', start on mount 'D:'
```

* Update yolo.py

* Update yolo.py

* Update yolo.py

* Update export.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

model = torch.hub.load('ultralytics/yolov5', 'yolov5s') [solve]Exception: path is on mount 'C:', start on mount 'D:'. Cache may be out of date,

1 participant