MogensR commited on
Commit
2bb75df
·
1 Parent(s): b8ff20a

MatA fix 2.1

Browse files
Files changed (1) hide show
  1. Dockerfile +31 -39
Dockerfile CHANGED
@@ -2,26 +2,25 @@
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) ---
8
  ARG SAM2_SHA=__PIN_ME__
9
- ARG MATANYONE_SHA=v1.0.0
10
  ARG SAM2_MODEL_ID=facebook/sam2
11
  ARG SAM2_VARIANT=sam2_hiera_large
12
- ARG MATANY_REPO_ID=PeiqingYang/MatAnyone
13
- ARG MATANY_FILENAME=matanyone_v1.0.pth
14
 
15
- # --- Non-root user (HF expects uid 1000) ---
16
  RUN useradd -m -u 1000 user
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
23
 
24
- # --- System packages ---
25
  USER root
26
  RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
27
  git ffmpeg python3 python3-pip python3-venv \
@@ -29,46 +28,36 @@ RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
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) ---
36
  RUN python3 -m pip install --no-cache-dir --upgrade pip
 
37
  RUN python3 -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 \
38
  torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1
39
 
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 \
73
  OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 NUMEXPR_NUM_THREADS=1 \
74
  TOKENIZERS_PARALLELISM=false \
@@ -76,14 +65,17 @@ 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 \
83
- MATANY_REPO_ID=PeiqingYang/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"]
 
2
  # BackgroundFX Pro — Dockerfile (Hardened for Spaces GPU)
3
  # ===============================
4
 
5
+ # ===== CHAPTER 1: Base image & user =====
6
  FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
7
 
8
+ # Optional pins (SAM2 commit etc.)
9
  ARG SAM2_SHA=__PIN_ME__
 
10
  ARG SAM2_MODEL_ID=facebook/sam2
11
  ARG SAM2_VARIANT=sam2_hiera_large
 
 
12
 
13
+ # Create non-root user (HF expects uid 1000)
14
  RUN useradd -m -u 1000 user
15
  ENV HOME=/home/user
16
  ENV PATH=/home/user/.local/bin:$PATH
17
+ WORKDIR /home/user/app
18
 
19
+ # Pre-create app dir + caches with correct ownership
20
  RUN mkdir -p /home/user/app/third_party /data/.cache && \
21
  chown -R user:user /home/user /data
 
22
 
23
+ # ===== CHAPTER 2: System packages (root) =====
24
  USER root
25
  RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
26
  git ffmpeg python3 python3-pip python3-venv \
 
28
  libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender-dev libgomp1 \
29
  && rm -rf /var/lib/apt/lists/*
30
 
31
+ # ===== CHAPTER 3: Python & core wheels (root) =====
 
 
 
32
  RUN python3 -m pip install --no-cache-dir --upgrade pip
33
+ # Torch cu121 wheels (pin runtime)
34
  RUN python3 -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 \
35
  torch==2.3.1 torchvision==0.18.1 torchaudio==2.3.1
36
 
37
+ # ===== CHAPTER 4: App deps + MatAnyone (root) =====
38
  COPY --chown=user requirements.txt ./requirements.txt
39
  RUN python3 -m pip install --no-cache-dir -r requirements.txt
40
  RUN python3 -m pip install --no-cache-dir mediapipe==0.10.14
41
+ # ✅ Install MatAnyone from main (ships pyproject; importable as a normal package)
42
+ RUN python3 -m pip install --no-cache-dir "git+https://github.com/pq-yang/MatAnyone@main"
43
 
44
+ # ===== CHAPTER 5: App code (user) =====
45
+ USER user
 
 
 
 
 
 
46
  COPY --chown=user . /home/user/app
47
 
48
+ # ===== CHAPTER 6: Third-party — SAM2 (editable, after COPY so it won’t be overwritten) =====
49
+ RUN rm -rf third_party/sam2 && \
50
+ 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
+ python3 -m pip install --no-cache-dir -e .
54
 
55
+ # Optional: quick listing
56
+ RUN echo "=== DEBUG: SAM2 contents ===" && \
57
+ ls -la third_party/sam2/ | head -n 200 && \
58
+ (ls -la third_party/sam2/configs/sam2/ || echo "SAM2 configs missing")
 
 
 
 
 
 
59
 
60
+ # ===== CHAPTER 7: Runtime environment =====
61
  ENV PYTHONUNBUFFERED=1 \
62
  OMP_NUM_THREADS=1 OPENBLAS_NUM_THREADS=1 MKL_NUM_THREADS=1 NUMEXPR_NUM_THREADS=1 \
63
  TOKENIZERS_PARALLELISM=false \
 
65
  TORCH_HOME=/data/.cache/torch \
66
  MPLCONFIGDIR=/data/.cache/matplotlib \
67
  PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128 \
68
+ PYTHONPATH="/home/user/app:/home/user/app/third_party:/home/user/app/third_party/sam2:${PYTHONPATH}" \
69
  FFMPEG_BIN=ffmpeg \
70
  THIRD_PARTY_SAM2_DIR=/home/user/app/third_party/sam2 \
 
 
 
71
  ENABLE_MATANY=1
72
 
73
+ # (Keep SAM2 model selection in Space Variables, not here)
74
+ # SAM2_MODEL_ID=facebook/sam2
75
+ # SAM2_VARIANT=sam2_hiera_large
76
+
77
  EXPOSE 7860
78
+
79
+ # ===== CHAPTER 8: Healthcheck & CMD =====
80
  HEALTHCHECK --interval=30s --timeout=5s --retries=5 CMD wget -qO- "http://127.0.0.1:${PORT:-7860}/" || exit 1
81
  CMD ["python3","-u","app.py"]