1.首先用dockerfile创建docker镜像
以下是dockerfile文件的内容:
FROM pytorch/pytorch:1.11.0-cuda11.3-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
RUN python3 -m pip install --no-cache-dir pycocotools>=2.0.2
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==6.0.1 shapely
RUN git clone https://github.com/hustvl/SparseInst
WORKDIR /workspace/SparseInst
RUN ln -s /usr/bin/python3 /usr/bin/python
ENTRYPOINT bash
在该dockerfile文件的目录下打开终端
然后在终端里执行(要挂梯子)
docker build -t my_custom_image .
经过一段时间的下载之后就能看到镜像
2.打开vscode安装docker和dev Containers插件
3.然后将刚刚的docker镜像运行为容器,有两种方式:
1.
2.使用指令,将docker镜像运行为容器。可以顺带把docker容器里的文件对应到本机目录下的文件,方便之后调试代码(推荐方式)
docker run -it --gpus all --name gpu_test -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all -v I:\Code\PythonCode\GithubPrioject\SparseInst-main:/workspace --name SparseInst my_custom_image:latest bash
#docker run -it --gpus all --name gpu_test -e NVIDIA_DRIVER_CAPABILITIES=compute,utility -e NVIDIA_VISIBLE_DEVICES=all -v [本地目录]:[容器目录] [镜像名字]
成功运行起来之后会看到有个绿色的三角形在自己创建的容器名字旁边:
4.用vscode在运行docker容器里的代码
按图点击,会出现弹窗
然后就能愉快跑项目了