Spaces:
Sleeping
Sleeping
DariusGiannoli commited on
Commit ·
a6793fb
1
Parent(s): 986fe2c
perf: pre-download backbone weights at Docker build time
Browse files- Dockerfile +16 -1
Dockerfile
CHANGED
|
@@ -28,7 +28,22 @@ RUN pip install --no-cache-dir \
|
|
| 28 |
torch torchvision \
|
| 29 |
-r requirements.txt
|
| 30 |
|
| 31 |
-
# 6.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
COPY --chown=user . .
|
| 33 |
|
| 34 |
# 7. Expose Streamlit port
|
|
|
|
| 28 |
torch torchvision \
|
| 29 |
-r requirements.txt
|
| 30 |
|
| 31 |
+
# 6. Pre-download backbone weights at BUILD time so they are baked into the
|
| 32 |
+
# image layer and never re-fetched at runtime.
|
| 33 |
+
# Weights are cached to $HOME/.cache/{torch,huggingface} inside the image.
|
| 34 |
+
RUN python - <<'EOF'
|
| 35 |
+
import torchvision.models as m
|
| 36 |
+
print("Downloading ResNet-18...")
|
| 37 |
+
m.resnet18(weights=m.ResNet18_Weights.DEFAULT)
|
| 38 |
+
print("Downloading MobileNetV3-Small...")
|
| 39 |
+
m.mobilenet_v3_small(weights=m.MobileNet_V3_Small_Weights.DEFAULT)
|
| 40 |
+
print("Downloading MobileViT-XXS...")
|
| 41 |
+
import timm
|
| 42 |
+
timm.create_model("mobilevit_xxs.cvnets_in1k", pretrained=True, num_classes=0)
|
| 43 |
+
print("All backbone weights cached.")
|
| 44 |
+
EOF
|
| 45 |
+
|
| 46 |
+
# 7. Copy the rest of the project
|
| 47 |
COPY --chown=user . .
|
| 48 |
|
| 49 |
# 7. Expose Streamlit port
|