From 15f79d6f35f2921ab04dc5db22b23edf4088bae5 Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Sun, 23 Jul 2023 20:43:07 +0200 Subject: [PATCH] Allow paths relative to `*.txt` files for LoadImages (#3905) --- ultralytics/data/loaders.py | 18 +++++++++++------- ultralytics/engine/exporter.py | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ultralytics/data/loaders.py b/ultralytics/data/loaders.py index f75f3f7..01acd8e 100644 --- a/ultralytics/data/loaders.py +++ b/ultralytics/data/loaders.py @@ -164,17 +164,21 @@ class LoadImages: def __init__(self, path, imgsz=640, vid_stride=1): """Initialize the Dataloader and raise FileNotFoundError if file not found.""" + parent = None if isinstance(path, str) and Path(path).suffix == '.txt': # *.txt file with img/vid/dir on each line + parent = Path(path).parent path = Path(path).read_text().rsplit() files = [] for p in sorted(path) if isinstance(path, (list, tuple)) else [path]: - p = str(Path(p).absolute()) # do not use .resolve() https://github.com/ultralytics/ultralytics/issues/2912 - if '*' in p: - files.extend(sorted(glob.glob(p, recursive=True))) # glob - elif os.path.isdir(p): - files.extend(sorted(glob.glob(os.path.join(p, '*.*')))) # dir - elif os.path.isfile(p): - files.append(p) # files + a = str(Path(p).absolute()) # do not use .resolve() https://github.com/ultralytics/ultralytics/issues/2912 + if '*' in a: + files.extend(sorted(glob.glob(a, recursive=True))) # glob + elif os.path.isdir(a): + files.extend(sorted(glob.glob(os.path.join(a, '*.*')))) # dir + elif os.path.isfile(a): + files.append(a) # files (absolute or relative to CWD) + elif parent and (parent / p).is_file(): + files.append(str((parent / p).absolute())) # files (relative to *.txt file parent) else: raise FileNotFoundError(f'{p} does not exist') diff --git a/ultralytics/engine/exporter.py b/ultralytics/engine/exporter.py index 1793028..a35b089 100644 --- a/ultralytics/engine/exporter.py +++ b/ultralytics/engine/exporter.py @@ -570,7 +570,7 @@ class Exporter: cuda = torch.cuda.is_available() check_requirements(f"tensorflow{'-macos' if MACOS else '-aarch64' if ARM64 else '' if cuda else '-cpu'}") import tensorflow as tf # noqa - check_requirements(('onnx', 'onnx2tf>=1.7.7', 'sng4onnx>=1.0.1', 'onnxsim>=0.4.17', 'onnx_graphsurgeon>=0.3.26', + check_requirements(('onnx', 'onnx2tf>=1.9.1', 'sng4onnx>=1.0.1', 'onnxsim>=0.4.17', 'onnx_graphsurgeon>=0.3.26', 'tflite_support', 'onnxruntime-gpu' if torch.cuda.is_available() else 'onnxruntime'), cmds='--extra-index-url https://pypi.ngc.nvidia.com')