File size: 2,053 Bytes
4607d95
f5f3936
bf103bf
f5f3936
bf103bf
 
 
 
f5f3936
bf103bf
 
4607d95
bf103bf
9820c02
bf103bf
602c04e
 
bf103bf
f5f3936
bf103bf
f5f3936
4607d95
f5f3936
7b813cc
f5f3936
 
 
4607d95
f5f3936
 
 
 
 
 
 
 
 
 
4607d95
f5f3936
 
4607d95
 
 
f5f3936
4607d95
eb0aef1
 
4607d95
 
f5f3936
 
7b813cc
f5f3936
 
7b813cc
 
 
4607d95
7b813cc
f5f3936
4607d95
f5f3936
4607d95
 
 
 
7b813cc
4607d95
 
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
# Stage 1: Base Python image
FROM python:3.9 as base

# Create a user and set environment variables
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# Set working directory
WORKDIR /app

# Copy Python dependencies and install them
COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir scikit-build
RUN pip install --no-cache-dir --upgrade -r requirements.txt
RUN pip install 'git+https://github.com/facebookresearch/detectron2.git'


# Copy application files
COPY --chown=user . /app

# Stage 2: CUDA and Detectron2
FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 as cuda

# Use noninteractive mode for apt-get
ENV DEBIAN_FRONTEND=noninteractive

# Install system dependencies
RUN apt-get update && apt-get install -y \
    python3-opencv \
    python3-pip \
    ca-certificates \
    python3-dev \
    git \
    wget \
    sudo \
    ninja-build

# Link Python and Pip commands
RUN ln -sv /usr/bin/python3 /usr/bin/python && ln -sv /usr/bin/pip3 /usr/bin/pip

# Copy dependencies from the base stage
COPY --from=base /home/user/.local /home/user/.local
COPY --from=base /app /app

# Install additional Python packages
RUN pip install --no-cache-dir scikit-build
RUN pip install --no-cache-dir --upgrade -r requirements.txt
RUN pip install --no-cache-dir tensorboard cmake onnx
RUN pip install --no-cache-dir 'git+https://github.com/facebookresearch/fvcore'

# Clone Detectron2 repository
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo

# Set environment variables for Detectron2
ENV FORCE_CUDA="1"
ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"
ENV FVCORE_CACHE="/tmp"

# Install Detectron2 in editable mode
RUN pip install --no-cache-dir -e detectron2_repo

# Set the working directory and environment
USER user
ENV HOME=/home/user
WORKDIR $HOME/app

# Expose application port and set default command
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]