Skip to content

Dockerfile changes to facilitate Ubuntu 20 so as to tackle python version mismatch and resolved dependencies #5449

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 39 additions & 24 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04
# use an older system (18.04) to avoid opencv incompatibility (issue#3524)
# Using Ubuntu 20.04 is creating an overall better impact in the download and installation
# The previous Dockerfile with 18.04 ubuntu was causing multiple errors
# This script creates a Docker image that can directly be run to get the output
FROM nvidia/cuda:11.1.1-cudnn8-devel-ubuntu20.04

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update && apt-get install -y \
python3-opencv ca-certificates python3-dev git wget sudo ninja-build
# Setting non-interactive terminal to avoid input during process
ENV DEBIAN_FRONTEND=noninteractive

# Installing necessary deps
# A virtual environment gives better support overall
RUN apt-get update && apt-get install -y python3-opencv python3-venv ca-certificates python3-dev git wget sudo ninja-build
RUN ln -sv /usr/bin/python3 /usr/bin/python

# create a non-root user
Expand All @@ -14,34 +19,44 @@ USER appuser
WORKDIR /home/appuser

ENV PATH="/home/appuser/.local/bin:${PATH}"
RUN wget https://bootstrap.pypa.io/pip/3.6/get-pip.py && \
python3 get-pip.py --user && \
rm get-pip.py

# install dependencies
# See https://pytorch.org/ for other options if you use a different version of CUDA
RUN pip install --user tensorboard cmake onnx # cmake from apt-get is too old
RUN pip install --user torch==1.10 torchvision==0.11.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html

RUN pip install --user 'git+https://github.com/facebookresearch/fvcore'
# install detectron2
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
# set FORCE_CUDA because during `docker build` cuda is not accessible
ENV FORCE_CUDA="1"
# This will by default build detectron2 for all common cuda architectures and take a lot more time,
# because inside `docker build`, there is no way to tell which architecture will be used.
# Create a virtual env in the /tmp directory
# Change path if you want
RUN python3 -m venv /tmp/detectron_env

# Set the Virtual ENV and Cuda ENV paths and add them to the base env PATHs
# Add LD Library Path as well
ENV VIRTUAL_ENV=/tmp/detectron_env
ENV CUDA_HOME=/usr/local/cuda-11.1
ENV PATH="$CUDA_HOME/bin:$VIRTUAL_ENV/bin:$PATH"
ENV LD_LIBRARY_PATH="$CUDA_HOME/lib64"

# Define all necessary CUDA architectures
ARG TORCH_CUDA_ARCH_LIST="Kepler;Kepler+Tesla;Maxwell;Maxwell+Tegra;Pascal;Volta;Turing"
ENV TORCH_CUDA_ARCH_LIST="${TORCH_CUDA_ARCH_LIST}"

RUN pip install --user -e detectron2_repo
# Install all necessary packages using pip in our virtual environment
RUN pip install tensorboard cmake onnx # cmake from apt-get is too old
RUN pip install torch==1.10 torchvision==0.11.1 -f https://download.pytorch.org/whl/cu111/torch_stable.html
RUN pip install opencv-python
RUN pip install 'git+https://github.com/facebookresearch/fvcore'

# Clone detectron repo install detectron2
RUN git clone https://github.com/facebookresearch/detectron2 detectron2_repo
RUN pip install -e detectron2_repo

# Set a fixed model cache directory.
ENV FVCORE_CACHE="/tmp"
WORKDIR /home/appuser/detectron2_repo

# The demo file does not run for some reason so omit that
# If anyone does make changes to demo.py, make sure to let me know at [email protected]

# run detectron2 under user "appuser":
# wget http://images.cocodataset.org/val2017/000000439715.jpg -O input.jpg
# python3 demo/demo.py \
#--config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
#--input input.jpg --output outputs/ \
#--opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
# RUN wget http://images.cocodataset.org/val2017/000000439715.jpg -O input.jpg
# RUN python3 demo/demo.py \
# --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
# --input input.jpg --output outputs/ \
# --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl