Open6
UString のエクスポート試行 + mmdetection v1.1.0 + PyTorch 1.10.1 + CUDA11.4.2 + cuDNN 8 環境の構築
ARG CUDA="11.4.2"
ARG CUDNN="8"
ARG OSVER="20.04"
FROM nvidia/cuda:${CUDA}-cudnn${CUDNN}-devel-ubuntu${OSVER}
ENV DEBIAN_FRONTEND=noninteractive
ENV TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 8.6+PTX"
ENV TORCH_NVCC_FLAGS="-Xfatbin -compress-all"
ENV CMAKE_PREFIX_PATH="$(dirname $(which conda))/../"
ARG WKDIR=/home/user
WORKDIR ${WKDIR}
# Install dependencies
RUN apt-get update \
&& apt-get install -y \
ffmpeg libsm6 libxext6 git ninja-build \
libglib2.0-0 libsm6 libxrender-dev libxext6 \
python3-pip wget zip unzip nano sudo \
python-is-python3 \
&& sed -i 's/# set linenumbers/set linenumbers/g' /etc/nanorc \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install pip --upgrade \
&& pip install setuptools --upgrade \
&& pip install ninja --upgrade \
&& pip install gdown --upgrade \
&& pip install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio==0.10.1+cu113 \
-f https://download.pytorch.org/whl/cu113/torch_stable.html \
&& pip install mmcv==0.4.2
# Create a user who can sudo in the Docker container
ENV USERNAME=user
RUN echo "root:root" | chpasswd \
&& adduser --disabled-password --gecos "" "${USERNAME}" \
&& echo "${USERNAME}:${USERNAME}" | chpasswd \
&& echo "%${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/${USERNAME} \
&& chmod 0440 /etc/sudoers.d/${USERNAME}
USER ${USERNAME}
RUN sudo chown ${USERNAME}:${USERNAME} ${WKDIR}
docker build -t test .
git clone https://github.com/Cogito2012/UString.git && cd UString
git checkout 98b2d5a3f8cacedaa9a540806bd6da6a56bdaa77
docker run --gpus all -it --rm \
-v `pwd`:/home/user/workdir \
test:latest
cd /home/user/workdir \
&& git clone https://github.com/open-mmlab/mmdetection.git \
&& cd mmdetection \
&& git checkout v1.1.0 \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/nms/src/nms_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/roi_align/src/roi_align_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/roi_pool/src/roi_pool_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/dcn/src/deform_conv_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/dcn/src/deform_pool_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/masked_conv/src/masked_conv2d_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/carafe/src/carafe_cuda.cpp \
&& sed -i 's/AT_CHECK/TORCH_CHECK/g' mmdet/ops/carafe/src/carafe_naive_cuda.cpp \
&& sudo pip install -v -e . \
&& sudo python setup.py install \
&& sudo gdown --id 1133YZYrhUpAC7S8Om0jgqPZJYRMYhmHm \
&& tar -zxvf Cascade_R-CNN.tar.gz \
&& sudo rm Cascade_R-CNN.tar.gz \
&& sudo cp -f -r Cascade_R-CNN/* ./ \
&& sudo rm -rf Cascade_R-CNN
# https://github.com/open-mmlab/OpenPCDet/issues/284#issuecomment-874171209
# https://github.com/open-mmlab/mmdetection/issues/2905
# https://github.com/open-mmlab/mmdetection/issues/281
# https://forums.developer.nvidia.com/t/no-cuda-runtime-is-found-using-cuda-home-usr-local-cuda/170143/5
cd /home/user/workdir
run_demo.sh
#!/bin/bash
# command input (video file)
VIDEO_PATH=$1
GPUS=0
VIDEO_FILENAME="${VIDEO_PATH##*/}" # ./demo/000821.mp4
DIR="${VIDEO_PATH%/*}" # ./demo
VID="${VIDEO_FILENAME%.*}" # 000821
FEAT_FILE="$DIR/$VID"_feature.npz
RESULT_FILE="$DIR/$VID"_result.npz
VIS_FILE="$DIR/$VID"_vis.avi
if [ ! -f "$RESULT_FILE" ]; then
if [ ! -f "$FEAT_FILE" ]; then
# feature extraction task
echo "Run feature extraction..."
CUDA_VISIBLE_DEVICES=$GPUS python demo.py \
--video_file $VIDEO_PATH \
--task extract_feature \
--gpu_id $GPUS \
--mmdetection lib/mmdetection
echo "Saved in: $FEAT_FILE"
fi
# run inference
echo "Run accident inference..."
CUDA_VISIBLE_DEVICES=$GPUS python demo.py \
--task inference \
--feature_file $FEAT_FILE \
--ckpt_file demo/final_model_ccd.pth \
--gpu_id $GPUS
echo "Saved in: $RESULT_FILE"
fi
# visualize
echo "Run result visualization..."
CUDA_VISIBLE_DEVICES=$GPUS python demo.py \
--task visualize \
--video_file $VIDEO_PATH \
--result_file $RESULT_FILE \
--vis_file $VIS_FILE
echo "Saved in: $VIS_FILE"
sed -i 's/out = op(src, index, 0, None, dim_size, fill_value)/out = op(src, index, 0, None, dim_size)/g' src/Models.py
bash run_demo.sh demo/000821.mp4