Spaces:
Sleeping
Sleeping
Dev Nagaich commited on
Commit ·
2751713
1
Parent(s): bba0ec4
Fix: Clone SAM2 from Meta repo and download weights using official scripts
Browse files- Dockerfile +41 -21
- requirements.txt +5 -2
Dockerfile
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
FROM
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
@@ -6,42 +6,62 @@ WORKDIR /app
|
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
git \
|
| 8 |
wget \
|
|
|
|
| 9 |
libsm6 \
|
| 10 |
libxext6 \
|
| 11 |
libxrender-dev \
|
| 12 |
libgl1-mesa-glx \
|
| 13 |
&& rm -rf /var/lib/apt/lists/*
|
| 14 |
|
| 15 |
-
#
|
| 16 |
COPY requirements.txt .
|
| 17 |
-
|
| 18 |
-
# Install Python dependencies
|
| 19 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
COPY app.py model_server.py ./
|
| 24 |
|
| 25 |
# Create .streamlit directory and config
|
| 26 |
RUN mkdir -p .streamlit
|
| 27 |
COPY .streamlit/config.toml .streamlit/
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
import os
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# Expose Streamlit port
|
| 47 |
EXPOSE 7860
|
|
|
|
| 1 |
+
FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
|
| 2 |
|
| 3 |
WORKDIR /app
|
| 4 |
|
|
|
|
| 6 |
RUN apt-get update && apt-get install -y \
|
| 7 |
git \
|
| 8 |
wget \
|
| 9 |
+
curl \
|
| 10 |
libsm6 \
|
| 11 |
libxext6 \
|
| 12 |
libxrender-dev \
|
| 13 |
libgl1-mesa-glx \
|
| 14 |
&& rm -rf /var/lib/apt/lists/*
|
| 15 |
|
| 16 |
+
# Install Python dependencies first
|
| 17 |
COPY requirements.txt .
|
|
|
|
|
|
|
| 18 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
|
| 20 |
+
# Clone Segment Anything 2 from Meta
|
| 21 |
+
RUN git clone https://github.com/facebookresearch/sam2.git segment-anything-2 && \
|
| 22 |
+
cd segment-anything-2 && \
|
| 23 |
+
pip install -e . && \
|
| 24 |
+
cd ..
|
| 25 |
+
|
| 26 |
+
# Download SAM2 model weights
|
| 27 |
+
RUN cd segment-anything-2/checkpoints && \
|
| 28 |
+
bash download_ckpts.sh && \
|
| 29 |
+
cd ../..
|
| 30 |
+
|
| 31 |
+
# Set Hugging Face token for VREyeSAM weights (injected by HF Spaces)
|
| 32 |
+
ENV HF_TOKEN=""
|
| 33 |
+
|
| 34 |
+
# Copy application files
|
| 35 |
COPY app.py model_server.py ./
|
| 36 |
|
| 37 |
# Create .streamlit directory and config
|
| 38 |
RUN mkdir -p .streamlit
|
| 39 |
COPY .streamlit/config.toml .streamlit/
|
| 40 |
|
| 41 |
+
# Download VREyeSAM fine-tuned weights from Hugging Face
|
| 42 |
+
# This assumes your weights are available on HF Model Hub
|
| 43 |
+
RUN if [ ! -z "$HF_TOKEN" ]; then \
|
| 44 |
+
python -c "
|
| 45 |
+
from huggingface_hub import hf_hub_download
|
| 46 |
import os
|
| 47 |
+
|
| 48 |
+
hf_token = os.getenv('HF_TOKEN')
|
| 49 |
+
if hf_token:
|
| 50 |
+
# Download VREyeSAM weights from your HF repo
|
| 51 |
+
# Replace 'your-username/vreyesam' with your actual repo
|
| 52 |
+
try:
|
| 53 |
+
checkpoint = hf_hub_download(
|
| 54 |
+
repo_id='devnagaich/VREyeSAM',
|
| 55 |
+
filename='VREyeSAM_uncertainity_best.torch',
|
| 56 |
+
token=hf_token,
|
| 57 |
+
cache_dir='segment-anything-2/checkpoints'
|
| 58 |
+
)
|
| 59 |
+
print(f'Downloaded VREyeSAM weights to: {checkpoint}')
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f'Warning: Could not download VREyeSAM weights: {e}')
|
| 62 |
+
print('App will attempt to load from cache at runtime')
|
| 63 |
+
" || true; \
|
| 64 |
+
fi
|
| 65 |
|
| 66 |
# Expose Streamlit port
|
| 67 |
EXPOSE 7860
|
requirements.txt
CHANGED
|
@@ -2,8 +2,8 @@
|
|
| 2 |
streamlit>=1.28.0
|
| 3 |
|
| 4 |
# Core ML and Deep Learning
|
| 5 |
-
torch>=2.
|
| 6 |
-
torchvision>=0.
|
| 7 |
numpy>=1.22.0,<2.0.0
|
| 8 |
|
| 9 |
# Computer Vision
|
|
@@ -17,5 +17,8 @@ scikit-learn>=1.0.0
|
|
| 17 |
# Visualization
|
| 18 |
matplotlib>=3.5.0
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# Utility packages
|
| 21 |
tqdm>=4.60.0
|
|
|
|
| 2 |
streamlit>=1.28.0
|
| 3 |
|
| 4 |
# Core ML and Deep Learning
|
| 5 |
+
torch>=2.5.1,<2.6.0
|
| 6 |
+
torchvision>=0.20.1,<0.21.0
|
| 7 |
numpy>=1.22.0,<2.0.0
|
| 8 |
|
| 9 |
# Computer Vision
|
|
|
|
| 17 |
# Visualization
|
| 18 |
matplotlib>=3.5.0
|
| 19 |
|
| 20 |
+
# Hugging Face integration
|
| 21 |
+
huggingface-hub>=0.19.0
|
| 22 |
+
|
| 23 |
# Utility packages
|
| 24 |
tqdm>=4.60.0
|