mirror of
https://github.com/THU-MIG/yolov10.git
synced 2025-05-23 05:24:22 +08:00
New test for labels and crops (#8861)
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
58a05f8e70
commit
82e8daef72
@ -334,6 +334,28 @@ def test_results():
|
||||
print(r, len(r), r.path)
|
||||
|
||||
|
||||
def test_labels_and_crops():
|
||||
"""Test output from prediction args for saving detection labels and crops."""
|
||||
imgs = [SOURCE, ASSETS / "zidane.jpg"]
|
||||
results = YOLO(WEIGHTS_DIR / "yolov8n.pt")(imgs, imgsz=160, save_txt=True, save_crop=True)
|
||||
save_path = Path(results[0].save_dir)
|
||||
for r in results:
|
||||
im_name = Path(r.path).stem
|
||||
cls_idxs = r.boxes.cls.int().tolist()
|
||||
# Check label path
|
||||
labels = save_path / f"labels/{im_name}.txt"
|
||||
assert labels.exists()
|
||||
# Check detections match label count
|
||||
assert len(r.boxes.data) == len([l for l in labels.read_text().splitlines() if l])
|
||||
# Check crops path and files
|
||||
crop_dirs = [p for p in (save_path / "crops").iterdir()]
|
||||
crop_files = [f for p in crop_dirs for f in p.glob("*")]
|
||||
# Crop directories match detections
|
||||
assert all([r.names.get(c) in [d.name for d in crop_dirs] for c in cls_idxs])
|
||||
# Same number of crops as detections
|
||||
assert len([f for f in crop_files if im_name in f.name]) == len(r.boxes.data)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not ONLINE, reason="environment is offline")
|
||||
def test_data_utils():
|
||||
"""Test utility functions in ultralytics/data/utils.py."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user