Can you provide a dockerfile to set up cuda 11.8 ubuntu with conda mmdet and mmcv 1.1.7
- User
Can you provide a dockerfile to set up cuda 11.8 ubuntu with conda mmdet and mmcv 1.1.7
- Assistant
Can you provide a dockerfile to set up cuda 11.8 ubuntu with conda mmdet and mmcv 1.1.7
Certainly! Below is a Dockerfile that sets up an Ubuntu environment with CUDA 11.8, installs Miniconda, and sets up the mmdetection and mmcv versions you specified (mmcv version 1.1.7). This Dockerfile ensures compatibility with CUDA 11.8 by building mmcv from source.
Please note that mmcv version 1.1.7 is quite old, and pre-built binaries for this version may not be available for CUDA 11.8. Therefore, the Dockerfile builds mmcv from source to ensure compatibility.
# Use the NVIDIA CUDA 11.8 base image
FROM nvidia/cuda:11.8.0-devel-ubuntu20.04
# Set non-interactive mode for apt-get
ENV DEBIAN_FRONTEND=noninteractive
# Install essential packages
RUN apt-get update && apt-get install -y --no-install-recommends \
wget \
git \
build-essential \
libopenblas-dev \
libblas-dev \
libopencv-dev \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
# Install Miniconda
WORKDIR /tmp
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \
chmod +x Miniconda3-latest-Linux-x86_64.sh && \
./Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda && \
rm Miniconda3-latest-Linux-x86_64.sh
# Update PATH
ENV PATH /opt/conda/bin:$PATH
# Create a conda environment
RUN conda create -n open-mmlab python=3.8 -y
# Activate the environment
SHELL ["conda", "run", "-n", "open-mmlab", "/bin/bash", "-c"]
# Install PyTorch with CUDA 11.8 support
RUN conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia -y
# Install MMCV from source
RUN pip install Cython
RUN git clone -b v1.1.7 https://github.com/open-mmlab/mmcv.git /mmcv
WORKDIR /mmcv
# Install dependencies
RUN pip install -r requirements/build.txt
# Build mmcv-full
RUN MMCV_WITH_OPS=1 pip install -e .
# Install MMDetection
RUN git clone https://github.com/open-mmlab/mmdetection.git /mmdetection
WORKDIR /mmdetection
# Install MMDetection dependencies
RUN pip install -r requirements.txt
# Install MMDetection
RUN pip install -e .
# Set the working directory
WORKDIR /workspace
# Default command
CMD ["/bin/bash"]
Base Image: Starts from nvidia/cuda:11.8.0-devel-ubuntu20.04 to ensure CUDA 11.8 with Ubuntu 20.04.
Essential Packages: Installs necessary system packages required to build Python packages and mmcv from source.
Miniconda Installation: Downloads and installs Miniconda to manage Python environments and packages.
Conda Environment: Creates a new conda environment named open-mmlab with Python 3.8.
PyTorch Installation: Installs PyTorch with CUDA 11.8 support from the official pytorch and nvidia channels.
conda install pytorch torchvision torchaudio pytorch-cuda=11.8 -c pytorch -c nvidia -y
MMCV Installation:
mmcv repository at version v1.1.7.Cython and other build requirements.mmcv-full from source with CUDA extensions by setting MMCV_WITH_OPS=1.MMDetection Installation:
mmdetection repository.mmdetection in editable mode.Compatibility:
mmcv Version: Version 1.1.7 is from 2020 and might not officially support CUDA 11.8 or PyTorch 2.x. Building from source helps ensure compatibility with the newer CUDA version.
mmdetection Version: The latest version of mmdetection might not be compatible with mmcv 1.1.7. You may need to check out a version of mmdetection that is compatible with mmcv 1.1.7.
For example, to check out mmdetection version 2.3.0, which is from around the same time as mmcv 1.1.7:
RUN git checkout v2.3.0
Add this line after cloning the mmdetection repository.
PyTorch Version:
mmcv and mmdetection. If you encounter issues, you might need to specify an older version of PyTorch that was contemporary with mmcv 1.1.7 and compatible with CUDA 11.8.Testing:
mmcv and mmdetection work as expected.Save the Dockerfile to a file named Dockerfile, and build the image using:
docker build -t mmdetection-cuda11.8 .
Run the container with:
docker run --gpus all -it mmdetection-cuda11.8
This command enables GPU access within the container using NVIDIA Container Toolkit.
NVIDIA Container Toolkit: Ensure that your system has the NVIDIA Container Toolkit installed to provide GPU support inside Docker containers.
Version Conflicts: If you encounter version conflicts or runtime errors, consider adjusting the versions of mmcv, mmdetection, or PyTorch to ensure compatibility.
If you face difficulties with mmcv 1.1.7 and CUDA 11.8, consider using a newer version of mmcv that officially supports CUDA 11.8. You can adjust the Dockerfile accordingly:
# Install MMCV (latest version compatible with CUDA 11.8)
RUN pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html
Replace the MMCV installation section with the above command and adjust the mmdetection version as needed.
I hope this Dockerfile helps you set up your environment! Let me know if you have any questions or need further assistance.