Skip to content

Commit

Permalink
Fix *.txt source inference dataloader (ultralytics#4468)
Browse files Browse the repository at this point in the history
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2023
1 parent 3acead7 commit c659c0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions tests/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion ultralytics/data/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c659c0f

Please sign in to comment.