Download scripts/verify_datasets.py from Gowtham25/hc-mts-training-data: direct link, hf CLI and curl.
- Browser
- Download file 2.75 kB
-
https://huggingface.co/datasets/Gowtham25/hc-mts-training-data/resolve/main/scripts/verify_datasets.py
- Command line
-
hf download hf://datasets/Gowtham25/hc-mts-training-data/scripts/verify_datasets.py
-
curl -L -o verify_datasets.py https://huggingface.co/datasets/Gowtham25/hc-mts-training-data/resolve/main/scripts/verify_datasets.py
2.75 kB
| #!/usr/bin/env python3 | |
| """Count images/metadata and write data/manifests/inventory.json.""" | |
| from __future__ import annotations | |
| import json | |
| from collections import Counter | |
| from pathlib import Path | |
| ROOT = Path("/opt/dlami/nvme/workspace/skin_disease_classification") | |
| RAW = ROOT / "data/raw" | |
| OUT = ROOT / "data/manifests/inventory.json" | |
| IMG_EXT = {".jpg", ".jpeg", ".png", ".bmp", ".tif", ".tiff", ".webp"} | |
| def count_images(path: Path) -> int: | |
| if not path.exists(): | |
| return 0 | |
| n = 0 | |
| for p in path.rglob("*"): | |
| if p.is_file() and p.suffix.lower() in IMG_EXT: | |
| n += 1 | |
| return n | |
| def folder_classes(path: Path) -> dict[str, int]: | |
| if not path.exists(): | |
| return {} | |
| counts: Counter[str] = Counter() | |
| for p in path.rglob("*"): | |
| if p.is_file() and p.suffix.lower() in IMG_EXT: | |
| rel = p.relative_to(path) | |
| if len(rel.parts) > 1: | |
| counts[rel.parts[0]] += 1 | |
| return dict(sorted(counts.items())) | |
| def main() -> None: | |
| inv = { | |
| "skindisnet": { | |
| "images": count_images(RAW / "skindisnet"), | |
| "classes": folder_classes(RAW / "skindisnet"), | |
| }, | |
| "pad_ufes_20": { | |
| "images": count_images(RAW / "pad_ufes_20"), | |
| "metadata": str(RAW / "pad_ufes_20/metadata.csv"), | |
| }, | |
| "scin": { | |
| "images": count_images(RAW / "scin"), | |
| "cases_csv": str(RAW / "scin/dataset/scin_cases.csv"), | |
| "labels_csv": str(RAW / "scin/dataset/scin_labels.csv"), | |
| }, | |
| "fitzpatrick17k": { | |
| "images": count_images(RAW / "fitzpatrick17k"), | |
| "csv": str(RAW / "fitzpatrick17k/fitzpatrick17k.csv"), | |
| }, | |
| "ddi": { | |
| "images": count_images(RAW / "ddi"), | |
| }, | |
| "ham10000_isic2018_task3": { | |
| "images": count_images(RAW / "ham10000"), | |
| "metadata": str(RAW / "ham10000/HAM10000_metadata.tab"), | |
| }, | |
| "isic2016_task3": {"images": count_images(RAW / "isic2016")}, | |
| "isic2017_task3_labels_only": {"csvs": [p.name for p in (RAW / "isic2017").glob("*.csv")]}, | |
| "isic2019": {"images": count_images(RAW / "isic2019")}, | |
| "isic2020": { | |
| "images": count_images(RAW / "isic2020"), | |
| "csvs": [p.name for p in (RAW / "isic2020").glob("*.csv")], | |
| }, | |
| "isic2024": {"images": count_images(RAW / "isic2024")}, | |
| "milk10k": {"images": count_images(RAW / "milk10k")}, | |
| } | |
| OUT.parent.mkdir(parents=True, exist_ok=True) | |
| OUT.write_text(json.dumps(inv, indent=2)) | |
| print(json.dumps(inv, indent=2)) | |
| print("total_images", sum(v.get("images", 0) for v in inv.values() if isinstance(v, dict))) | |
| if __name__ == "__main__": | |
| main() | |