simplify module3 venue workflow
This commit is contained in:
@@ -5,18 +5,24 @@ from pathlib import Path
|
||||
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
SOURCE = HERE / "dataset/raw"
|
||||
SOURCE = HERE / "dataset/label-studio"
|
||||
IMAGES = SOURCE / "images"
|
||||
LABELS = SOURCE / "labels"
|
||||
OUTPUT = HERE / "training_new"
|
||||
IMAGE_EXTENSIONS = {".jpg", ".jpeg", ".png", ".bmp", ".webp"}
|
||||
|
||||
|
||||
def main():
|
||||
images = sorted(path for path in SOURCE.iterdir() if path.suffix.lower() in IMAGE_EXTENSIONS)
|
||||
if not IMAGES.is_dir():
|
||||
raise SystemExit(f"Нет каталога {IMAGES}")
|
||||
images = sorted(path for path in IMAGES.iterdir() if path.suffix.lower() in IMAGE_EXTENSIONS)
|
||||
if not images:
|
||||
raise SystemExit(f"Нет кадров в {SOURCE}")
|
||||
raise SystemExit(f"Нет кадров в {IMAGES}")
|
||||
if not LABELS.is_dir():
|
||||
raise SystemExit(f"Сначала экспортируйте YOLO-разметку в {LABELS}")
|
||||
classes_file = SOURCE / "classes.txt"
|
||||
if not classes_file.is_file():
|
||||
raise SystemExit(f"Нет {classes_file}")
|
||||
|
||||
random.Random(42).shuffle(images)
|
||||
test_count = max(1, round(len(images) * 0.1)) if len(images) >= 3 else 0
|
||||
@@ -44,7 +50,7 @@ def main():
|
||||
else:
|
||||
destination.touch()
|
||||
|
||||
classes = (HERE / "dataset/classes.txt").read_text(encoding="utf-8").splitlines()
|
||||
classes = classes_file.read_text(encoding="utf-8").splitlines()
|
||||
names = "\n".join(f" {number}: {name}" for number, name in enumerate(classes))
|
||||
(OUTPUT / "data.yaml").write_text(
|
||||
f"path: {OUTPUT}\ntrain: train/images\nval: valid/images\ntest: test/images\n\nnames:\n{names}\n",
|
||||
|
||||
Reference in New Issue
Block a user