### This Dockerfile is modified from MMDeploy to build MMDeploy for GPU devices ### We update the tensorrt version and cuda version to 11.8 FROM nvcr.io/nvidia/tensorrt:23.08-py3 ARG CUDA=11.8 ARG PYTHON_VERSION=3.10 ARG TORCH_VERSION=2.0.0 ARG TORCHVISION_VERSION=0.15.1 ARG ONNXRUNTIME_VERSION=1.15.1 ARG PPLCV_VERSION=0.7.0 ENV FORCE_CUDA="1" ARG MMCV_VERSION="==2.0.0" ARG MMENGINE_VERSION="==0.8.4" ENV DEBIAN_FRONTEND=noninteractive ### change the system source for installing libs ARG USE_SRC_INSIDE=false RUN if [ ${USE_SRC_INSIDE} == true ] ; \ then \ sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list ; \ sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list ; \ echo "Use aliyun source for installing libs" ; \ else \ echo "Keep the download source unchanged" ; \ fi ### update apt and install libs RUN apt-get update &&\ apt-get install -y vim libsm6 libxext6 libxrender-dev libgl1-mesa-glx git wget libssl-dev libopencv-dev libspdlog-dev --no-install-recommends &&\ rm -rf /var/lib/apt/lists/* RUN curl -fsSL -v -o ~/miniconda.sh -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ chmod +x ~/miniconda.sh && \ bash ~/miniconda.sh -b -p /opt/conda && \ rm ~/miniconda.sh && \ /opt/conda/bin/conda install -y python=${PYTHON_VERSION} conda-build pyyaml numpy ipython cython typing typing_extensions mkl mkl-include ninja && \ /opt/conda/bin/conda clean -ya ### change the pip source for installing packages RUN if [ ${USE_SRC_INSIDE} == true ] ; \ then \ /opt/conda/bin/pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple; \ echo "pip using tsinghua source" ; \ else \ echo "Keep pip the download source unchanged" ; \ fi ### install pytorch openmim RUN /opt/conda/bin/conda install pytorch==${TORCH_VERSION} torchvision==${TORCHVISION_VERSION} cudatoolkit=${CUDA} -c pytorch -c conda-forge -y \ && /opt/conda/bin/pip install --no-cache-dir openmim ### pytorch mmcv onnxruntime RUN /opt/conda/bin/mim install --no-cache-dir "mmcv"${MMCV_VERSION} onnxruntime-gpu==${ONNXRUNTIME_VERSION} mmengine${MMENGINE_VERSION} ENV PATH /opt/conda/bin:$PATH WORKDIR /root/workspace ### get onnxruntime RUN wget https://github.com/microsoft/onnxruntime/releases/download/v${ONNXRUNTIME_VERSION}/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz \ && tar -zxvf onnxruntime-linux-x64-${ONNXRUNTIME_VERSION}.tgz ### cp trt from pip to conda RUN cp -r /usr/local/lib/python${PYTHON_VERSION}/dist-packages/tensorrt* /opt/conda/lib/python${PYTHON_VERSION}/site-packages/ ### install mmdeploy ENV ONNXRUNTIME_DIR=/root/workspace/onnxruntime-linux-x64-${ONNXRUNTIME_VERSION} ENV TENSORRT_DIR=/workspace/tensorrt ARG VERSION RUN git clone -b main https://github.com/open-mmlab/mmdeploy &&\ cd mmdeploy &&\ if [ -z ${VERSION} ] ; then echo "No MMDeploy version passed in, building on main" ; else git checkout tags/v${VERSION} -b tag_v${VERSION} ; fi &&\ git submodule update --init --recursive &&\ mkdir -p build &&\ cd build &&\ cmake -DMMDEPLOY_TARGET_BACKENDS="ort;trt" .. &&\ make -j$(nproc) &&\ cd .. &&\ /opt/conda/bin/mim install -e . ### build sdk # RUN git clone https://github.com/openppl-public/ppl.cv.git &&\ # cd ppl.cv &&\ # git checkout tags/v${PPLCV_VERSION} -b v${PPLCV_VERSION} &&\ # ./build.sh cuda ENV BACKUP_LD_LIBRARY_PATH=$LD_LIBRARY_PATH ENV LD_LIBRARY_PATH=/usr/local/cuda/compat/lib.real/:$LD_LIBRARY_PATH RUN cd /root/workspace/mmdeploy &&\ rm -rf build/CM* build/cmake-install.cmake build/Makefile build/csrc &&\ mkdir -p build && cd build &&\ cmake .. \ -DMMDEPLOY_BUILD_EXAMPLES=ON \ -DCMAKE_CXX_COMPILER=g++ \ -DTENSORRT_DIR=${TENSORRT_DIR} \ -DONNXRUNTIME_DIR=${ONNXRUNTIME_DIR} \ -DMMDEPLOY_BUILD_SDK_PYTHON_API=ON \ -DMMDEPLOY_TARGET_DEVICES="cuda;cpu" \ -DMMDEPLOY_TARGET_BACKENDS="ort;trt" \ -DMMDEPLOY_CODEBASES=all &&\ make -j$(nproc) && make install &&\ export SPDLOG_LEVEL=warn &&\ if [ -z ${VERSION} ] ; then echo "Built MMDeploy for GPU devices successfully!" ; else echo "Built MMDeploy version v${VERSION} for GPU devices successfully!" ; fi # -DMMDEPLOY_BUILD_SDK=ON \ # -Dpplcv_DIR=/root/workspace/ppl.cv/cuda-build/install/lib/cmake/ppl \ ENV LD_LIBRARY_PATH="/root/workspace/mmdeploy/build/lib:${BACKUP_LD_LIBRARY_PATH}" ENV CUDA_HOME /usr/local/cuda-11.8/ RUN rm -rf /var/lib/apt/lists/* RUN apt-get update -y RUN apt-get install ffmpeg libsm6 libxext6 -y RUN apt-get clean -y RUN pip install --upgrade pip RUN useradd -m -u 1000 user RUN chown -R user:user /root/workspace USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH WORKDIR $HOME/app COPY --chown=user . $HOME/app USER root RUN mkdir -p /data && mv ./data /data/human_detection RUN pip install --no-cache-dir --upgrade -r requirements.txt RUN mim install mmdet==3.1.0 RUN mim install mmpose==1.1.0 RUN mim install mmyolo==0.6.0 RUN pip install cython-bbox==0.1.3 RUN pip install lap RUN pip install gradio RUN python setup.py develop USER user RUN echo 'export PYTHONPATH=$PYTHONPATH:./' >> ~/.bashrc CMD /bin/bash -c "cd projects/human_detection && ./export_onnx_trt/export_trt_mmyolov8.sh && gradio app.py"