MatA fixing
Browse files- Dockerfile +9 -25
Dockerfile
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
# BackgroundFX Pro — Dockerfile (Hardened for Spaces GPU)
|
| 3 |
# ===============================
|
| 4 |
|
| 5 |
-
# Match PyTorch cu121 wheels (critical to avoid CUDA probe stalls)
|
| 6 |
FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
|
| 7 |
|
| 8 |
# --- Build args (optional pins) ---
|
|
@@ -18,7 +17,6 @@ RUN useradd -m -u 1000 user
|
|
| 18 |
ENV HOME=/home/user
|
| 19 |
ENV PATH=/home/user/.local/bin:$PATH
|
| 20 |
|
| 21 |
-
# Pre-create app dir + caches with correct ownership (avoid permission denied)
|
| 22 |
RUN mkdir -p /home/user/app/third_party /data/.cache && \
|
| 23 |
chown -R user:user /home/user /data
|
| 24 |
WORKDIR /home/user/app
|
|
@@ -31,7 +29,7 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
|
|
| 31 |
libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev libgomp1 \
|
| 32 |
&& rm -rf /var/lib/apt/lists/*
|
| 33 |
|
| 34 |
-
# Switch to non-root
|
| 35 |
USER user
|
| 36 |
|
| 37 |
# --- Python + Torch (cu121) ---
|
|
@@ -42,42 +40,33 @@ RUN python3 -m pip install --no-cache-dir --index-url https://download.pytorch.o
|
|
| 42 |
# --- App deps ---
|
| 43 |
COPY --chown=user requirements.txt ./requirements.txt
|
| 44 |
RUN python3 -m pip install --no-cache-dir -r requirements.txt
|
| 45 |
-
# Optional nice fallback
|
| 46 |
RUN python3 -m pip install --no-cache-dir mediapipe==0.10.14
|
| 47 |
|
| 48 |
-
# --- Third-party repos
|
| 49 |
# SAM2
|
| 50 |
RUN git clone --depth=1 https://github.com/facebookresearch/segment-anything-2.git third_party/sam2 && \
|
| 51 |
cd third_party/sam2 && \
|
| 52 |
if [ "${SAM2_SHA}" != "__PIN_ME__" ]; then git fetch --depth=1 origin ${SAM2_SHA} && git checkout ${SAM2_SHA}; fi
|
| 53 |
-
|
| 54 |
-
# Show what we got
|
| 55 |
-
RUN echo "=== DEBUG: SAM2 contents ===" && \
|
| 56 |
-
ls -la third_party/sam2/ && \
|
| 57 |
-
echo "=== DEBUG: SAM2 configs ===" && \
|
| 58 |
-
(ls -la third_party/sam2/configs/sam2/ || echo "configs missing")
|
| 59 |
-
|
| 60 |
-
# Install SAM2 (editable ok)
|
| 61 |
RUN cd third_party/sam2 && python3 -m pip install --no-cache-dir -e .
|
| 62 |
|
| 63 |
-
# --- App code last
|
| 64 |
COPY --chown=user . /home/user/app
|
| 65 |
|
| 66 |
-
# Verify SAM2
|
| 67 |
RUN echo "=== DEBUG: After COPY (SAM2) ===" && \
|
| 68 |
ls -la third_party/sam2/ && \
|
| 69 |
(ls -la third_party/sam2/configs/sam2/ || echo "SAM2 configs missing")
|
| 70 |
|
| 71 |
-
#
|
| 72 |
RUN rm -rf third_party/matanyone && \
|
| 73 |
git clone --depth=1 https://github.com/pq-yang/MatAnyone.git third_party/matanyone && \
|
| 74 |
cd third_party/matanyone && \
|
| 75 |
git fetch --tags --depth=1 && \
|
| 76 |
git checkout ${MATANYONE_SHA} && \
|
| 77 |
if [ -f requirements.txt ]; then python3 -m pip install --no-cache-dir -r requirements.txt; fi
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
|
| 82 |
# --- Runtime environment ---
|
| 83 |
ENV PYTHONUNBUFFERED=1 \
|
|
@@ -87,7 +76,7 @@ ENV PYTHONUNBUFFERED=1 \
|
|
| 87 |
TORCH_HOME=/data/.cache/torch \
|
| 88 |
MPLCONFIGDIR=/data/.cache/matplotlib \
|
| 89 |
PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128 \
|
| 90 |
-
PYTHONPATH="
|
| 91 |
FFMPEG_BIN=ffmpeg \
|
| 92 |
THIRD_PARTY_SAM2_DIR=/home/user/app/third_party/sam2 \
|
| 93 |
THIRD_PARTY_MATANY_DIR=/home/user/app/third_party/matanyone \
|
|
@@ -95,11 +84,6 @@ ENV PYTHONUNBUFFERED=1 \
|
|
| 95 |
MATANY_CHECKPOINT="" \
|
| 96 |
ENABLE_MATANY=1
|
| 97 |
|
| 98 |
-
# Do NOT set PORT here; Spaces injects it.
|
| 99 |
EXPOSE 7860
|
| 100 |
-
|
| 101 |
-
# Optional: basic health check to see if the server bound
|
| 102 |
HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD wget -qO- "http://127.0.0.1:${PORT:-7860}/" || exit 1
|
| 103 |
-
|
| 104 |
-
# Use exec form + unbuffered
|
| 105 |
CMD ["python3","-u","app.py"]
|
|
|
|
| 2 |
# BackgroundFX Pro — Dockerfile (Hardened for Spaces GPU)
|
| 3 |
# ===============================
|
| 4 |
|
|
|
|
| 5 |
FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
|
| 6 |
|
| 7 |
# --- Build args (optional pins) ---
|
|
|
|
| 17 |
ENV HOME=/home/user
|
| 18 |
ENV PATH=/home/user/.local/bin:$PATH
|
| 19 |
|
|
|
|
| 20 |
RUN mkdir -p /home/user/app/third_party /data/.cache && \
|
| 21 |
chown -R user:user /home/user /data
|
| 22 |
WORKDIR /home/user/app
|
|
|
|
| 29 |
libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev libgomp1 \
|
| 30 |
&& rm -rf /var/lib/apt/lists/*
|
| 31 |
|
| 32 |
+
# Switch to non-root
|
| 33 |
USER user
|
| 34 |
|
| 35 |
# --- Python + Torch (cu121) ---
|
|
|
|
| 40 |
# --- App deps ---
|
| 41 |
COPY --chown=user requirements.txt ./requirements.txt
|
| 42 |
RUN python3 -m pip install --no-cache-dir -r requirements.txt
|
|
|
|
| 43 |
RUN python3 -m pip install --no-cache-dir mediapipe==0.10.14
|
| 44 |
|
| 45 |
+
# --- Third-party repos ---
|
| 46 |
# SAM2
|
| 47 |
RUN git clone --depth=1 https://github.com/facebookresearch/segment-anything-2.git third_party/sam2 && \
|
| 48 |
cd third_party/sam2 && \
|
| 49 |
if [ "${SAM2_SHA}" != "__PIN_ME__" ]; then git fetch --depth=1 origin ${SAM2_SHA} && git checkout ${SAM2_SHA}; fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
RUN cd third_party/sam2 && python3 -m pip install --no-cache-dir -e .
|
| 51 |
|
| 52 |
+
# --- App code last ---
|
| 53 |
COPY --chown=user . /home/user/app
|
| 54 |
|
| 55 |
+
# Verify SAM2 after COPY
|
| 56 |
RUN echo "=== DEBUG: After COPY (SAM2) ===" && \
|
| 57 |
ls -la third_party/sam2/ && \
|
| 58 |
(ls -la third_party/sam2/configs/sam2/ || echo "SAM2 configs missing")
|
| 59 |
|
| 60 |
+
# ✅ MatAnyone AFTER COPY so it persists
|
| 61 |
RUN rm -rf third_party/matanyone && \
|
| 62 |
git clone --depth=1 https://github.com/pq-yang/MatAnyone.git third_party/matanyone && \
|
| 63 |
cd third_party/matanyone && \
|
| 64 |
git fetch --tags --depth=1 && \
|
| 65 |
git checkout ${MATANYONE_SHA} && \
|
| 66 |
if [ -f requirements.txt ]; then python3 -m pip install --no-cache-dir -r requirements.txt; fi
|
| 67 |
+
# Sanity check: package folder must exist
|
| 68 |
+
RUN echo "=== DEBUG: MatAnyone package ===" && \
|
| 69 |
+
ls -la third_party/matanyone/matanyone || (echo "MISSING matanyone package dir!" && exit 2)
|
| 70 |
|
| 71 |
# --- Runtime environment ---
|
| 72 |
ENV PYTHONUNBUFFERED=1 \
|
|
|
|
| 76 |
TORCH_HOME=/data/.cache/torch \
|
| 77 |
MPLCONFIGDIR=/data/.cache/matplotlib \
|
| 78 |
PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128 \
|
| 79 |
+
PYTHONPATH="/home/user/app:/home/user/app/third_party:/home/user/app/third_party/sam2:/home/user/app/third_party/matanyone:${PYTHONPATH}" \
|
| 80 |
FFMPEG_BIN=ffmpeg \
|
| 81 |
THIRD_PARTY_SAM2_DIR=/home/user/app/third_party/sam2 \
|
| 82 |
THIRD_PARTY_MATANY_DIR=/home/user/app/third_party/matanyone \
|
|
|
|
| 84 |
MATANY_CHECKPOINT="" \
|
| 85 |
ENABLE_MATANY=1
|
| 86 |
|
|
|
|
| 87 |
EXPOSE 7860
|
|
|
|
|
|
|
| 88 |
HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD wget -qO- "http://127.0.0.1:${PORT:-7860}/" || exit 1
|
|
|
|
|
|
|
| 89 |
CMD ["python3","-u","app.py"]
|