由于外网源下载问题,将官方Dockerfile做部分修改:
FROM nvcr.io/nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04
# use an older system (18.04) to avoid opencv incompatibility (issue#3524)
ENV DEBIAN_FRONTEND noninteractive
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys xxxxxxxxxxxxx
ADD sources.list /etc/apt/
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get update && apt-get install -y \
python3-opencv ca-certificates python3-dev git wget sudo ninja-build
RUN ln -sv /usr/bin/python3 /usr/bin/python
# create a non-root user
ARG USER_ID=1000
RUN useradd -m --no-log-init --system --uid ${USER_ID} appuser -g sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
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 # 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 --default-timeout=1000 install --index-url https://mirrors.aliyun.com/pypi/simple torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
# RUN pip install --user 'git+git://github.com/facebookresearch/fvcore'
RUN pip install -U 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.
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
# Set a fixed model cache directory.
ENV FVCORE_CACHE="/tmp"
WORKDIR /home/appuser/detectron2_repo
# 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
主要修改说明如下:
1、基础官方镜像源拉取不成功,将nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04 修改为 nvcr.io/nvidia/cuda:11.1.1-cudnn8-devel-ubuntu18.04
2、
GPG error: The following signatures couldn't be verified because the public key XXXXXX is not available
添加以下语句(添加key即为以上提示中的key):
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys xxxxxxxxx
3、无法获取源:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
新建一个sources.list放置于docker构建目录下,源链接参考 国内源,然后在Dockerfile添加以下语句:
ADD sources.list /etc/apt/
RUN apt-get update -y && apt-get upgrade -y
4、torch安装,detectron2需要高版本torch,torch安装时使用官方源非常慢且易断联,故更改为以下语句:
RUN pip --default-timeout=1000 install --index-url https://mirrors.aliyun.com/pypi/simple torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
5、fvcore包下载安装失败,直接
RUN pip install -U fvcore