File size: 3,179 Bytes
9f36f2f
 
bbc3fdc
 
 
 
 
 
f054fb1
 
bbc3fdc
3968781
 
 
 
 
 
 
bbc3fdc
 
3968781
 
bbc3fdc
 
3968781
 
bbc3fdc
3968781
 
 
bbc3fdc
 
3968781
bbc3fdc
 
 
3968781
 
bbc3fdc
e317b3c
 
3968781
e317b3c
3968781
 
 
 
 
 
c05ac4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e219ce4
f7e2564
c05ac4f
 
 
 
 
3968781
 
 
bbc3fdc
c05ac4f
 
 
 
 
 
 
 
 
42ce71e
 
bbc3fdc
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Base image with CUDA compiler tools (needed for C++ extensions)
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04

ENV DEBIAN_FRONTEND=noninteractive
ENV CUDA_HOME=/usr/local/cuda
ENV PATH=${CUDA_HOME}/bin:${PATH}
ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}

# Only build for T4 (7.5) - reduces compilation memory by 50%
ENV TORCH_CUDA_ARCH_LIST="7.5"

# Install minimal runtime dependencies
# Remove problematic CUDA repo and install packages
RUN rm -f /etc/apt/sources.list.d/cuda*.list /etc/apt/sources.list.d/*.list && \
    apt-get update && apt-get install -y --no-install-recommends --allow-unauthenticated \
    ca-certificates \
    && apt-get clean && rm -rf /var/lib/apt/lists/* && \
    apt-get update && apt-get install -y --no-install-recommends \
    python3.10 \
    python3-pip \
    git \
    libgl1 \
    libglib2.0-0 \
    libgomp1 \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Set python as default
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1 && \
    update-alternatives --install /usr/bin/python python /usr/bin/python3.10 1

# Upgrade pip
RUN python3 -m pip install --no-cache-dir --upgrade pip

WORKDIR /app

# Install PyTorch (smallest CUDA 11.8 build)
RUN pip install --no-cache-dir torch==2.1.0 torchvision==0.16.0 --index-url https://download.pytorch.org/whl/cu118

# Install only essential requirements
# Pin NumPy to 1.x for CUDA extension compatibility
RUN pip install --no-cache-dir \
    "numpy<2" \
    gradio>=4.0.0 \
    opencv-python-headless>=4.8.0 \
    Pillow>=10.0.0 \
    huggingface-hub>=0.20.0 \
    && pip cache purge

# Install build dependencies (keep them for faster HuggingFace builds)
# Install BEFORE nvdiffrast because it needs python3.10-dev
RUN apt-get update && apt-get install -y --no-install-recommends \
    cmake \
    build-essential \
    ninja-build \
    libeigen3-dev \
    python3.10-dev \
    libboost-system-dev \
    libboost-program-options-dev \
    pybind11-dev \
    && rm -rf /var/lib/apt/lists/*

# Install FoundationPose dependencies
RUN pip install --no-cache-dir \
    trimesh==4.2.2 \
    scipy==1.12.0 \
    scikit-image==0.22.0 \
    kornia==0.7.2 \
    einops==0.7.0 \
    timm==0.9.16 \
    transformations==2024.6.1 \
    pyyaml==6.0.1 \
    joblib==1.4.0 \
    psutil==6.1.1 \
    && pip cache purge

# Note: nvdiffrast will be built in final Dockerfile on HuggingFace (needs GPU)

# Clone FoundationPose
RUN git clone --depth 1 https://github.com/NVlabs/FoundationPose.git /app/FoundationPose && \
    cd /app/FoundationPose/bundlesdf/mycuda && \
    sed -i 's/-std=c++14/-std=c++17/g' setup.py

# Build mycpp (non-GPU C++ code - can be built without GPU)
WORKDIR /app/FoundationPose
RUN cd mycpp && mkdir -p build && cd build && cmake .. && make

# Download model weights (246MB)
WORKDIR /app
RUN python3 -c "from huggingface_hub import snapshot_download; \
snapshot_download(repo_id='gpue/foundationpose-weights', local_dir='weights', repo_type='model')"

# Note: Application files (app.py, client.py, estimator.py) are copied in main Dockerfile
# This allows updates without rebuilding the entire base image

EXPOSE 7860