From 17f3ac679c500058ca09fc6e7e860dac38dd4fb1 Mon Sep 17 00:00:00 2001 From: Malte Lorbach <49158835+maltelorbach@users.noreply.github.com> Date: Mon, 11 Oct 2021 18:47:24 +0200 Subject: [PATCH] Fix `ROOT` as relative path (#5129) * use os.path.relpath instead of relative_to * use os.path.relpath instead of relative_to * Remove os.path from val.py * Remove os.path from train.py * Update detect.py import to os * Update export.py import to os Co-authored-by: Glenn Jocher --- detect.py | 3 ++- export.py | 3 ++- train.py | 2 +- val.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/detect.py b/detect.py index 75ec3ecc5ff3..346860e3832f 100644 --- a/detect.py +++ b/detect.py @@ -7,6 +7,7 @@ """ import argparse +import os import sys from pathlib import Path @@ -19,7 +20,7 @@ ROOT = FILE.parents[0] # 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 +ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative from models.experimental import attempt_load from utils.datasets import LoadImages, LoadStreams diff --git a/export.py b/export.py index 74aca4b6c30a..2aca0f341dbd 100644 --- a/export.py +++ b/export.py @@ -21,6 +21,7 @@ """ import argparse +import os import subprocess import sys import time @@ -34,7 +35,7 @@ ROOT = FILE.parents[0] # 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 +ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative from models.common import Conv from models.experimental import attempt_load diff --git a/train.py b/train.py index e8034a648cac..29ae43e3bd37 100644 --- a/train.py +++ b/train.py @@ -30,7 +30,7 @@ ROOT = FILE.parents[0] # 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 +ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative import val # for end-of-epoch mAP from models.experimental import attempt_load diff --git a/val.py b/val.py index 2cd8eba87443..2fc547322a0a 100644 --- a/val.py +++ b/val.py @@ -21,7 +21,7 @@ ROOT = FILE.parents[0] # 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 +ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative from models.experimental import attempt_load from utils.datasets import create_dataloader