diff --git a/tests/test_python.py b/tests/test_python.py index 7b6c6f5ae98..dff14994112 100644 --- a/tests/test_python.py +++ b/tests/test_python.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') diff --git a/ultralytics/data/loaders.py b/ultralytics/data/loaders.py index 1534a50003c..cdbf5e4c5bc 100644 --- a/ultralytics/data/loaders.py +++ b/ultralytics/data/loaders.py @@ -182,7 +182,7 @@ def __init__(self, path, imgsz=640, vid_stride=1): 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