Spaces:
Paused
Paused
Download scripts/fetch_models.py from Kamlesh21/preprocessing-lab: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/spaces/Kamlesh21/preprocessing-lab/resolve/main/scripts/fetch_models.py
- Command line
-
hf download hf://spaces/Kamlesh21/preprocessing-lab/scripts/fetch_models.py
-
curl -L -o fetch_models.py https://huggingface.co/spaces/Kamlesh21/preprocessing-lab/resolve/main/scripts/fetch_models.py
909 Bytes
| """Download model weights once so the demo runs offline: ResNet50 (torchvision, V1 weights) and YOLO11s-seg.""" | |
| import os | |
| import urllib.request | |
| from pathlib import Path | |
| WEIGHTS = Path(__file__).resolve().parents[1] / "weights" | |
| YOLO_URL = "https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11s-seg.pt" | |
| def main() -> None: | |
| WEIGHTS.mkdir(exist_ok=True) | |
| os.environ.setdefault("TORCH_HOME", str(WEIGHTS / "torch")) | |
| from torchvision.models import ResNet50_Weights, resnet50 | |
| # V1, not V2: V2 was trained with label smoothing, so even correct answers show only 30-50% confidence. | |
| resnet50(weights=ResNet50_Weights.IMAGENET1K_V1) | |
| print("resnet50 ok") | |
| target = WEIGHTS / "yolo11s-seg.pt" | |
| if not target.exists(): | |
| urllib.request.urlretrieve(YOLO_URL, target) | |
| print("yolo11s-seg ok", target.stat().st_size, "bytes") | |
| if __name__ == "__main__": | |
| main() | |