Fix `*.txt` source inference dataloader (#4468)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
pull/4482/head
GrunCrow 1 year ago committed by GitHub
parent 3acead7e79
commit c659c0fa7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      tests/test_python.py
  2. 2
      ultralytics/data/loaders.py

@ -49,6 +49,16 @@ def test_predict_dir():
model(source=ASSETS, imgsz=32)
def test_predict_txt():
# Write a list of sources to a txt file
txt_file = TMP / 'sources.txt'
with open(txt_file, 'w') as f:
for x in [ASSETS / 'bus.jpg', ASSETS / 'zidane.jpg']:
f.write(f'{x}\n')
model = YOLO(MODEL)
model(source=txt_file, imgsz=640)
def test_predict_img():
model = YOLO(MODEL)
seg_model = YOLO(WEIGHTS_DIR / 'yolov8n-seg.pt')

@ -182,7 +182,7 @@ class LoadImages:
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()
path = Path(path).read_text().splitlines() # list of sources
files = []
for p in sorted(path) if isinstance(path, (list, tuple)) else [path]:
a = str(Path(p).absolute()) # do not use .resolve() https://github.com/ultralytics/ultralytics/issues/2912

Loading…
Cancel
Save