preprocessing-lab / scripts /fetch_models.py
Kamlesh21's picture
Deploy Preprocessing Lab
b0acf7c verified
Raw History Blame Contribute Delete
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()