Spaces:
Paused
Paused
File size: 909 Bytes
b0acf7c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | """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()
|