MVIG-SJTU / AlphaPose

Real-Time and Accurate Full-Body Multi-Person Pose Estimation&Tracking System
http://mvig.org/research/alphapose.html
Other
7.96k stars 1.97k forks source link

Create Dockerfile for Installation #1057

Open pranavgundewar opened 2 years ago

pranavgundewar commented 2 years ago

As title mentions, can we have a dockerfile for codebase installation?

Thank you!

optimuspaul commented 2 years ago

I had one that worked for a while. But now I can't get Alphapose to build at all. #1002

Here is what I have so far

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 torchaudio --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)"

edit: updated with my latest that actually builds fully.

H4dr1en commented 1 year ago

Updated Dockerfile, works as of today (also will download some model weights for you)

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 python3-tk

RUN pip install "torch==1.12.1+cu116" "torchvision==0.13.1" "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/MVIG-SJTU/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" \
    PATH=/usr/local/cuda/bin/:$PATH \
    LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH  \
    python3 setup.py build develop --user

# Fix compatibility issue with numpy >= 1.20
RUN pip install git+https://github.com/H4dr1en/cython_bbox.git@patch-1

RUN apt install bc -y && \
    pip install boto3 && \
    python3 -c "import torchvision.models as tm; tm.resnet152(pretrained=True)"

# Download weights, adapt to what you need
RUN pip install gdown && \
    mkdir -p detector/yolo/data && \
    gdown 1D47msNOOiJKvPOXlnpyzdKA3k6E97NTC -O detector/yolo/data/yolov3-spp.weights && \
    gdown 1S-ROA28de-1zvLv-hVfPFJ5tFBYOSITb -O pretrained_models/halpe26_fast_res50_256x192.pth

Use:

docker build -t alphapose .
docker run --rm --gpus all -it alphapose /bin/bash

Test:

python3 scripts/demo_inference.py --cfg configs/halpe_26/resnet/256x192_res50_lr1e-3_1x.yaml --checkpoint pretrained_models/halpe26_fast_res50_256x192.pth --indir examples/demo/ --save_img
EthannHongg commented 1 year ago

I tried both and can't get them to work. I changed cuda:11.6.0 to 11.6.2 because it keeps telling me it's not found. It keeps giving me "IndexError: list index out of range" for when I don't use setup build in PythonAPI. But if I do build in PythonAPI it keeps telling me " x86_64-linux-gnu-gcc: error: ../common/maskApi.c: No such file or directory" but I have verified that the file does exist using "RUN ls /build/HalpeCOCOAPI/PythonAPI/common/maskApi.c". Is there an updated version for the dockerfile?

vuxminhan commented 1 year ago

This works for me as of today


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-8 \
    mesa-common-dev \
    libosmesa6 libosmesa6-dev \
    libgles2-mesa-dev \
    libglu1-mesa-dev \
    libgles2-mesa-dev \
    libcublas-11-8 \
    libcublas-dev-11-8 \
    libcusparse-dev-11-8 \
    cuda-nvcc-11-8 \
    libcusolver-dev-11-8 \
    cuda-nvrtc-dev-11-8 \
    libcurand-dev-11-8 \
    cuda-nvml-dev-11-8 \
    libcufft-dev-11-8 \
    cuda-toolkit-11-8 \
    nvidia-cuda-toolkit \
    libyaml-dev

ENV CUDA_HOME='/usr/local/cuda'

RUN DEBIAN_FRONTEND=noninteractive apt -y install python3 python3-pip python3-tk
RUN pip install pyyaml==5.2
RUN pip install scipy
RUN pip install numpy
RUN pip3 install torch torchvision --extra-index-url https://download.pytorch.org/whl/cu113
# RUN pip install opencv-contrib-python-headless
# RUN pip install pip --upgrade
# RUN pip install wheel

# RUN pip install git+https://github.com/Ambrosiussen/HalpeCOCOAPI.git#subdirectory=PythonAPI

RUN python3 -c "import torch; print(torch.version.cuda)" 

RUN mkdir /build
RUN cd /build && git clone https://github.com/HaoyiZhu/HalpeCOCOAPI.git
RUN echo "from setuptools import setup, Extension\n\
import numpy as np\n\
\n\
# To compile and install locally run \"python setup.py build_ext --inplace\"\n\
# To install library to Python site-packages run \"python setup.py build_ext install\"\n\
\n\
ext_modules = [\n\
    Extension(\n\
        'halpecocotools._mask',\n\
        sources=['common/maskApi.c'],\n\
        include_dirs = [np.get_include(), 'common'],\n\
        extra_compile_args=[],\n\
    )\n\
]\n\
\n\
setup(\n\
    name='halpecocotools',\n\
    packages = ['halpecocotools'],\n\
    package_dir = {'halpecocotools': 'halpecocotools'},\n\
    install_requires=[\n\
        'setuptools>=18.0',\n\
        'cython>=0.27.3',\n\
        'matplotlib>=2.1.0',\n\
    ],\n\
    version='0.0.0',\n\
    description=\"COCO API for Halpe-Fullbody dataset\",\n\
    url=\"https://github.com/HaoyiZhu/HalpeCOCOAPI\",\n\
    ext_modules= ext_modules\n\
)" > /build/HalpeCOCOAPI/PythonAPI/setup.py

RUN cd /build/HalpeCOCOAPI/PythonAPI && python3 setup.py build develop --user
# Fix compatibility issue with numpy >= 1.20

RUN pip install cython
RUN pip install git+https://github.com/H4dr1en/cython_bbox.git@patch-1
RUN cd /build && git clone https://github.com/MVIG-SJTU/AlphaPose.git
WORKDIR /build/AlphaPose
# RUN python3 setup.py build develop
RUN TORCH_CUDA_ARCH_LIST="6.1;7.5;8.6" \
    PATH=/usr/local/cuda/bin/:$PATH \
    LD_LIBRARY_PATH=/usr/local/cuda/lib64/:$LD_LIBRARY_PATH  \
    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)"

# Download weights, adapt to what you need
RUN pip install gdown && \
    mkdir -p detector/yolo/data && \
    gdown 1D47msNOOiJKvPOXlnpyzdKA3k6E97NTC -O detector/yolo/data/yolov3-spp.weights && \
    gdown 1S-ROA28de-1zvLv-hVfPFJ5tFBYOSITb -O pretrained_models/halpe26_fast_res50_256x192.pth
213pk commented 1 month ago

Could you provide the version for cuda 12.0? Thanks!