Spaces:
Paused
Paused
Download python_files/inspect_yolo_zip.py from Rachel7/hvac_fable: direct link, hf CLI and curl.
- Browser
- Download file 2.08 kB
-
https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/inspect_yolo_zip.py
- Command line
-
hf download hf://spaces/Rachel7/hvac_fable/python_files/inspect_yolo_zip.py
-
curl -L -o inspect_yolo_zip.py https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/inspect_yolo_zip.py
2.08 kB
| """Extract and inspect the YOLO annotations zip. Writes results to log file.""" | |
| import zipfile | |
| import sys | |
| from pathlib import Path | |
| RAW_DIR = Path(__file__).resolve().parent / "yolo_v2_data" / "raw" | |
| EXTRACT_DIR = Path(__file__).resolve().parent / "yolo_v2_data" / "extracted" | |
| LOG_FILE = Path(__file__).resolve().parent / "yolo_v2_data" / "inspect_log.txt" | |
| log_lines = [] | |
| def log(msg): | |
| log_lines.append(str(msg)) | |
| print(msg) | |
| try: | |
| zips = list(RAW_DIR.glob("*.zip")) | |
| log(f"Zips found: {[z.name for z in zips]}") | |
| zip_path = zips[0] | |
| log(f"\nExtracting: {zip_path.name}") | |
| EXTRACT_DIR.mkdir(parents=True, exist_ok=True) | |
| with zipfile.ZipFile(zip_path, "r") as zf: | |
| log("\nContents of zip:") | |
| for info in zf.infolist(): | |
| log(f" {info.filename} ({info.file_size} bytes)") | |
| zf.extractall(EXTRACT_DIR) | |
| log(f"\nExtracted to: {EXTRACT_DIR}") | |
| log("\n=== Files in extracted folder ===") | |
| for f in sorted(EXTRACT_DIR.rglob("*")): | |
| if f.is_file(): | |
| rel = f.relative_to(EXTRACT_DIR) | |
| log(f" {rel} ({f.stat().st_size} bytes)") | |
| classes_files = list(EXTRACT_DIR.rglob("classes.txt")) + list(EXTRACT_DIR.rglob("*.yaml")) | |
| for cf in classes_files: | |
| log(f"\n=== {cf.name} ===") | |
| log(cf.read_text()) | |
| log("\n=== Label files ===") | |
| label_files = [f for f in EXTRACT_DIR.rglob("*.txt") if f.name != "classes.txt"] | |
| for lf in label_files: | |
| log(f"\n--- {lf.name} ---") | |
| content = lf.read_text().strip() | |
| log(content[:2000]) | |
| lines = content.split("\n") if content else [] | |
| log(f" Total boxes: {len(lines)}") | |
| class_counts = {} | |
| for line in lines: | |
| if line.strip(): | |
| cls = line.split()[0] | |
| class_counts[cls] = class_counts.get(cls, 0) + 1 | |
| log(f" Per class: {class_counts}") | |
| except Exception as e: | |
| log(f"ERROR: {e}") | |
| import traceback | |
| log(traceback.format_exc()) | |
| LOG_FILE.write_text("\n".join(log_lines), encoding="utf-8") | |
| print(f"\nLog saved to {LOG_FILE}") | |