reidddd commited on
Commit
4607d95
·
1 Parent(s): 251a789

update import detectron2

Browse files
Files changed (1) hide show
  1. Dockerfile +19 -18
Dockerfile CHANGED
@@ -1,4 +1,4 @@
1
- # Base image with Python 3.9 for app dependencies
2
  FROM python:3.9 as base
3
 
4
  # Create a user and set environment variables
@@ -9,23 +9,20 @@ ENV PATH="/home/user/.local/bin:$PATH"
9
  # Set working directory
10
  WORKDIR /app
11
 
12
- # Copy and install Python dependencies
13
  COPY --chown=user ./requirements.txt requirements.txt
14
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
15
 
16
  # Copy application files
17
  COPY --chown=user . /app
18
 
19
- # Expose application port and set default command
20
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
21
-
22
- # Base image for CUDA support
23
  FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 as cuda
24
 
25
  # Use noninteractive mode for apt-get
26
  ENV DEBIAN_FRONTEND=noninteractive
27
 
28
- # Install dependencies
29
  RUN apt-get update && apt-get install -y \
30
  python3-opencv \
31
  python3-pip \
@@ -36,15 +33,16 @@ RUN apt-get update && apt-get install -y \
36
  sudo \
37
  ninja-build
38
 
39
- # Link Python and Pip to default commands
40
  RUN ln -sv /usr/bin/python3 /usr/bin/python && ln -sv /usr/bin/pip3 /usr/bin/pip
41
 
42
- # Install Python packages
43
- RUN pip install --no-cache-dir --upgrade -r requirements.txt
44
- RUN pip install --user tensorboard cmake onnx
45
 
46
- # Install fvcore
47
- RUN pip install --user 'git+https://github.com/facebookresearch/fvcore'
 
48
 
49
  # Clone Detectron2 repository
50
  RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
@@ -53,12 +51,15 @@ RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
53
  ENV FORCE_CUDA="1"
54
  ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
55
  ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"
 
56
 
57
  # Install Detectron2 in editable mode
58
- RUN pip install --user -e detectron2_repo
59
 
60
- # Set fvcore cache directory
61
- ENV FVCORE_CACHE="/tmp"
 
 
62
 
63
- # Set working directory
64
- WORKDIR /home/user/detectron2_repo
 
1
+ # Stage 1: Base Python image
2
  FROM python:3.9 as base
3
 
4
  # Create a user and set environment variables
 
9
  # Set working directory
10
  WORKDIR /app
11
 
12
+ # Copy Python dependencies and install them
13
  COPY --chown=user ./requirements.txt requirements.txt
14
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
15
 
16
  # Copy application files
17
  COPY --chown=user . /app
18
 
19
+ # Stage 2: CUDA and Detectron2
 
 
 
20
  FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 as cuda
21
 
22
  # Use noninteractive mode for apt-get
23
  ENV DEBIAN_FRONTEND=noninteractive
24
 
25
+ # Install system dependencies
26
  RUN apt-get update && apt-get install -y \
27
  python3-opencv \
28
  python3-pip \
 
33
  sudo \
34
  ninja-build
35
 
36
+ # Link Python and Pip commands
37
  RUN ln -sv /usr/bin/python3 /usr/bin/python && ln -sv /usr/bin/pip3 /usr/bin/pip
38
 
39
+ # Copy dependencies from the base stage
40
+ COPY --from=base /home/user/.local /home/user/.local
41
+ COPY --from=base /app /app
42
 
43
+ # Install additional Python packages
44
+ RUN pip install --no-cache-dir tensorboard cmake onnx
45
+ RUN pip install --no-cache-dir 'git+https://github.com/facebookresearch/fvcore'
46
 
47
  # Clone Detectron2 repository
48
  RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
 
51
  ENV FORCE_CUDA="1"
52
  ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
53
  ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"
54
+ ENV FVCORE_CACHE="/tmp"
55
 
56
  # Install Detectron2 in editable mode
57
+ RUN pip install --no-cache-dir -e detectron2_repo
58
 
59
+ # Set the working directory and environment
60
+ USER user
61
+ ENV HOME=/home/user
62
+ WORKDIR $HOME/app
63
 
64
+ # Expose application port and set default command
65
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]