Skip to content

Commit

Permalink
Sidestep os.path.relpath() Windows bug (ultralytics#7158)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
glenn-jocher committed Mar 26, 2022
1 parent 5c50504 commit 2b812f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion export.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
ROOT = FILE.parents[0] # YOLOv5 root directory
if str(ROOT) not in sys.path:
sys.path.append(str(ROOT)) # add ROOT to PATH
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative
if platform.system() != 'Windows':
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative

from models.common import Conv
from models.experimental import attempt_load
Expand Down
5 changes: 4 additions & 1 deletion models/yolo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"""

import argparse
import os
import platform
import sys
from copy import deepcopy
from pathlib import Path
Expand All @@ -15,7 +17,8 @@
ROOT = FILE.parents[1] # YOLOv5 root directory
if str(ROOT) not in sys.path:
sys.path.append(str(ROOT)) # add ROOT to PATH
# ROOT = ROOT.relative_to(Path.cwd()) # relative
if platform.system() != 'Windows':
ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative

from models.common import *
from models.experimental import *
Expand Down

0 comments on commit 2b812f7

Please sign in to comment.