From fa5871bae9a6b389c7ad9352cb52496072d55b86 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Thu, 19 Jan 2023 10:49:43 +0100 Subject: [PATCH] Dockerfile for Alphapose --- .dockerignore | 1 + Dockerfile | 69 ++++++++++++++++++++++++++++++++++ README.md | 24 ++++++++++++ detector/yolo/data/.gitignore | 4 ++ detector/yolox/data/.gitignore | 4 ++ pretrained_models/.gitignore | 4 ++ 6 files changed, 106 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.md create mode 100644 detector/yolo/data/.gitignore create mode 100644 detector/yolox/data/.gitignore create mode 100644 pretrained_models/.gitignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12625c9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,69 @@ +# thanks to Paul DeCoursey (optimuspaul@github.com) for inspiration +# see: https://github.com/MVIG-SJTU/AlphaPose/issues/1057 + +#FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 +#FROM nvidia/cuda:11.6.0-cudnn8-devel-ubuntu22.04 +FROM nvidia/cuda:11.6.0-devel-ubuntu20.04 + +RUN apt clean + +RUN DEBIAN_FRONTEND=noninteractive apt update && DEBIAN_FRONTEND=noninteractive apt install -y --allow-change-held-packages \ + ffmpeg \ + git \ + build-essential \ + ninja-build \ + cuda-libraries-11-6 \ + mesa-common-dev \ + libosmesa6 libosmesa6-dev \ + libgles2-mesa-dev \ + libglu1-mesa-dev \ + libgles2-mesa-dev \ + libcublas-11-6 \ + libcublas-dev-11-6 \ + libcusparse-dev-11-6 \ + cuda-nvcc-11-6 \ + libcusolver-dev-11-6 \ + cuda-nvrtc-dev-11-6 \ + libcurand-dev-11-6 \ + cuda-nvml-dev-11-6 \ + libcufft-dev-11-6 \ + cuda-toolkit-11-6 \ + nvidia-cuda-toolkit \ + libyaml-dev + +ENV CUDA_HOME='/usr/local/cuda' + +RUN DEBIAN_FRONTEND=noninteractive apt -y install python3 python3-pip + +RUN pip install "torch==1.12.1+cu116" "torchvision==0.13.1+cu116" "torchaudio==0.12.1" --extra-index-url https://download.pytorch.org/whl/cu116 +RUN pip install opencv-contrib-python-headless +RUN pip install pip --upgrade + +RUN pip install cython pycocotools + +RUN python3 -c "import torch; print(torch.version.cuda)" + +RUN mkdir /build +RUN cd /build && git clone https://github.com/HaoyiZhu/HalpeCOCOAPI.git +RUN cd /build && git clone https://github.com/WildflowerSchools/AlphaPose.git + +RUN cd /build/HalpeCOCOAPI/PythonAPI && python3 setup.py build develop --user + +WORKDIR /build/AlphaPose + +RUN TORCH_CUDA_ARCH_LIST="6.1;7.5;8.6" python3 setup.py build develop --user + +RUN apt install bc -y && \ + pip install boto3 && \ + python3 -c "import torchvision.models as tm; tm.resnet152(pretrained=True)" + +RUN pip install "cython_bbox==0.1.3" +# TODO: when working, move this dependency up +RUN pip install "numpy==1.22.4" +RUN apt install -y python3-tk + +# Resnet 50 is needed for some of the AlphaPose models +# TODO: alternatively make this a build param/tag for resnet50/152 +# see: https://stackoverflow.com/questions/33935807/how-to-define-a-variable-in-a-dockerfile#37639938 +RUN python3 -c "import torchvision.models as tm; tm.resnet50(pretrained=True)" + diff --git a/README.md b/README.md new file mode 100644 index 0000000..b32d600 --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# AlphaPose Docker + +Create a docker image for [AlphaPose](http://mvig.org/research/alphapose.html) ([code at GitHub](https://github.com/MVIG-SJTU/AlphaPose)). + +## Building the image + +```bash +docker build --tag alphapose . +``` + +## Usage + +Before the repository can be used, it is necessary to download the required auxilary models, as per [the AlphaPose installation guide](https://github.com/MVIG-SJTU/AlphaPose/blob/master/docs/INSTALL.md#models). + +1. YOLOv3 Object detector can be place in the `detector/yolo/data` repository. +2. (Optionally) YOLOX models go in the `detector/yolox/data` repository. +3. A pretrained AlphaPose model can be place in the `pretrained_models` directory. See their [Model Zoo](https://github.com/MVIG-SJTU/AlphaPose/blob/master/docs/MODEL_ZOO.md) for the various options. +4. For pose tracking, see the [pose tracking module](https://github.com/MVIG-SJTU/AlphaPose/tree/master/trackers). Make sure to add the necessary folder as a volume to the `docker run` command. + +### Running + +``` +docker run --rm --gpus all -v `pwd`/out:/out -v `pwd`/detector/yolox/data:/build/AlphaPose/detector/yolox/data -v `pwd`/detector/yolo/data:/build/AlphaPose/detector/yolo/data -v `pwd`/pretrained_models:/build/AlphaPose/pretrained_models alphapose python3 scripts/demo_inference.py --cfg configs/coco/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/fast_res50_256x192.pth --gpus 0 --indir examples/demo/ --save_img --vis_fast --outdir /out +``` diff --git a/detector/yolo/data/.gitignore b/detector/yolo/data/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/detector/yolo/data/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/detector/yolox/data/.gitignore b/detector/yolox/data/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/detector/yolox/data/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/pretrained_models/.gitignore b/pretrained_models/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/pretrained_models/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore