论文:Sparse Instance Activation for Real-Time Instance Segmentation
原本官方提供dockerfile文件为:
FROM pytorch/pytorch:1.11.0-cuda11.3-cudnn8-devel
LABEL Service="SparseInstanceActivation"
ENV TZ=Europe/Moscow
ENV DETECTRON_TAG=v0.3
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-key del 7fa2af80 && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
RUN apt update && apt install vim git g++ python3-tk ffmpeg libsm6 libxext6 -y
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir opencv-python opencv-contrib-python scipy
WORKDIR /workspace
RUN git clone https://github.com/facebookresearch/detectron2.git && \
cd detectron2/ && git checkout tags/${DETECTRON_TAG} && python3 setup.py build develop
RUN python3 -m pip uninstall -y iopath fvcore portalocker yacs && \
python3 -m pip install --no-cache-dir iopath fvcore portalocker yacs timm pyyaml==5.1 shapely
RUN git clone https://github.com/hustvl/SparseInst
WORKDIR /workspace/SparseInst
RUN ln -s /usr/bin/python3 /usr/bin/python
ENTRYPOINT bash
执行
docker build -t my_custom_image .
1.执行后报错
gcc: error: pycocotools/_mask.c: No such file or directory
查询后得知是没安装cython导致,在dockerfile文件里加上安装cython。
2.报错变为
FutureWarning: Cython directive 'language_level' not set, using '3str' for now (Py3)
提前安装pycocotools=2.0.8解决
3.然后遇到报错
Collecting pyyaml==5.1
Downloading PyYAML-5.1.tar.gz (274 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 274.2/274.2 kB 5.0 MB/s eta 0:00:00
error: subprocess-exited-with-error
安装pyyaml==6.0.1版本可正确执行
4.进入docker环境后执行以下指令报错,说detectron2不存在
python tools/test_net.py --config-file configs/sparse_inst_r50_giam_fp16.yaml --fp16 MODEL.WEIGHTS model_final.pth
去detectron2官方找到了新的下载安装方式,写入dockerfile文件。发现还是不行,需要进入容器之后执行
git clone https://github.com/facebookresearch/detectron2.git
这样就能顺利了
5.将coco数据集放在正确路径之后,报错RuntimeError: nvrtc: error: invalid value for --gpu-architecture (-arch)
原因:torch版本不对,应该将torch升级到13.0或者以上的版本,我升级到了13.1
6.numpy版本2.1太高
更改numpy版本为1.23.5
解决后的dockerfile文件:
FROM pytorch/pytorch:1.13.1-cuda11.6-cudnn8-devel
LABEL Service="SparseInstanceActivation"
ENV TZ=Europe/Moscow
ENV DETECTRON_TAG=v0.6
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-key del 7fa2af80 && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/3bf863cc.pub && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/7fa2af80.pub
RUN apt update && apt install vim git g++ python3-tk ffmpeg libsm6 libxext6 -y
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
python3 -m pip install --no-cache-dir opencv-python opencv-contrib-python scipy cython
WORKDIR /workspace
RUN git clone https://github.com/facebookresearch/detectron2.git && python3 -m pip install -e detectron2
RUN python3 -m pip uninstall -y iopath fvcore portalocker yacs && \
python3 -m pip install --no-cache-dir iopath fvcore portalocker yacs timm pyyaml==6.0.1 shapely
RUN python3 -m pip install --no-cache-dir numpy==1.23.5
RUN git clone https://github.com/hustvl/SparseInst
WORKDIR /workspace/SparseInst
RUN ln -s /usr/bin/python3 /usr/bin/python
ENTRYPOINT bash