Linux环境下安装mmdetection
环境准备:
- Linux系统
- Python 3.5+
- PyTorch 1.1 或更高
- CUDA9.0 或更高
- NCCL2
- GCC 4.9 或更高
- mmcv
安装 mmdetection
a. 创建 conda 虚拟环境并激活。
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
b. 安装 PyTorch and torchvision, 可参考官方教程
conda install pytorch torchvision -c pytorch
c. 克隆 mmdetection 代码.
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
d. 安装依赖环境
pip install -r requirements/build.txt
pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
e. 安装mmdetection
pip install -v -e . # or "python setup.py develop"
使用这个命令,mmdetetion以dev模式安装,本地修改不用重新install,如果代码提交了commit或者pull更新了代码,则需要再次执行上面语句。
另外在requirements/
下还有其他依赖环境可以安装。
构建mmdetection的Docker镜像
环境准备
- docker
- nvidia-docker(如果是19.03及以后,不需要安装nvidia-docker)
- nvidia-driver(建议是最新版)
基于Dockerfile构建镜像
根据官方提供的Dockerfile 构建。
# build an image with PyTorch 1.3, CUDA 10.1 and CUDNN 7
docker build -t mmdetection docker/
Dockerfile内容如下:
ARG PYTORCH="1.3"
ARG CUDA="10.1"
ARG CUDNN="7"
FROM pytorch/pytorch:${PYTORCH}-cuda${CUDA}-cudnn${CUDNN}-devel
ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0+PTX"
ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
ENV CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"
RUN apt-get update && apt-get install -y libglib2.0-0 libsm6 libxrender-dev libxext6 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install mmdetection
RUN conda clean --all
RUN git clone https://github.com/open-mmlab/mmdetection.git /mmdetection
WORKDIR /mmdetection
ENV FORCE_CUDA="1"
RUN pip install --no-cache-dir -e .