26 lines
636 B
Python
26 lines
636 B
Python
from pathlib import Path
|
|
|
|
label_dir = Path("./datasets/your_dataset/val/labels")
|
|
|
|
def valid_line(line):
|
|
parts = line.split()
|
|
if len(parts) != 5:
|
|
return False
|
|
cls, x, y, w, h = map(float, parts)
|
|
return 0 <= cls and 0 < w <= 1 and 0 < h <= 1
|
|
|
|
|
|
empty = []
|
|
for p in label_dir.glob("*.txt"):
|
|
if p.stat().st_size == 0:
|
|
empty.append(p.name)
|
|
|
|
print(f"Empty label files: {len(empty)}")
|
|
|
|
invalid = []
|
|
for p in label_dir.glob("*.txt"):
|
|
lines = p.read_text().strip().splitlines()
|
|
if not any(valid_line(l) for l in lines):
|
|
invalid.append(p.name)
|
|
|
|
print(f"Effectively empty labels: {len(invalid)}") |