Skip to content

Commit 39a9562

Browse files
authored
refact: downgrade cuda driver requirement for docker image (#364)
* refact: downgrade cuda driver requirement for docker image * feat: add a Python2/3 compatible and dependency-free dependency checker for container execution * refact: detailed instructions for nvidia-docker installation
1 parent 7129943 commit 39a9562

File tree

5 files changed

+96
-22
lines changed

5 files changed

+96
-22
lines changed

.dockerignore

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
.git
1+
.git*
22
*build*
33
data
4-
3rdparty
4+
3rdparty
5+
docs
6+
.clang-format
7+
.readthedocs.yml
8+
Dockerfile

Dockerfile

+21-17
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,34 @@
22

33
# docker build .
44

5-
# Based on CUDA11.0 & CuDNN8
6-
FROM nvidia/cuda:10.2-devel-ubuntu18.04
5+
# Based on CUDA10.0 & CuDNN7
6+
FROM nvidia/cuda:10.0-cudnn7-devel-ubuntu18.04
77

8-
# Test connection
9-
RUN apt update --allow-unauthenticated && apt install -y wget && wget www.google.com
8+
# Set apt-get to automatically retry if a package download fails
9+
RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/99AcquireRetries
10+
11+
# apt update
12+
RUN apt update --allow-unauthenticated
1013

1114
# Install Non-GPU Dependencies.
12-
RUN version="7.0.0-1+cuda10.2" ; \
15+
RUN version="7.0.0-1+cuda10.0" ; \
1316
apt install -y \
1417
libnvinfer7=${version} libnvonnxparsers7=${version} libnvparsers7=${version} \
1518
libnvinfer-plugin7=${version} libnvinfer-dev=${version} libnvonnxparsers-dev=${version} \
16-
libnvparsers-dev=${version} libnvinfer-plugin-dev=${version} python-libnvinfer=${version} \
17-
python3-libnvinfer=${version} && \
19+
libnvparsers-dev=${version} libnvinfer-plugin-dev=${version} && \
1820
apt-mark hold \
19-
libnvinfer7 libnvonnxparsers7 libnvparsers7 libnvinfer-plugin7 libnvinfer-dev libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev python-libnvinfer python3-libnvinfer
20-
21-
# Set apt-get to automatically retry if a package download fails
22-
RUN echo 'Acquire::Retries "5";' > /etc/apt/apt.conf.d/99AcquireRetries
21+
libnvinfer7 libnvonnxparsers7 libnvparsers7 libnvinfer-plugin7 libnvinfer-dev libnvonnxparsers-dev libnvparsers-dev libnvinfer-plugin-dev \
22+
# && apt install -yt python-libnvinfer=${version} python3-libnvinfer=${version} && apt-mark hold python-libnvinfer python3-libnvinfer
2323

2424
# Install OpenCV Dependencies
2525
RUN apt install -y software-properties-common || apt install -y software-properties-common && \
2626
add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main" && \
27-
APT_DEPS="git cmake libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev x264 v4l-utils python3-dev python3-pip libcanberra-gtk-module libcanberra-gtk3-module" && \
27+
APT_DEPS="git cmake wget zip libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev x264 v4l-utils python3-dev python3-pip libcanberra-gtk-module libcanberra-gtk3-module" && \
2828
apt install -y $APT_DEPS || apt install -y $APT_DEPS && \
2929
python3 -m pip install numpy
3030

3131
# Compile OpenCV
32-
RUN apt install -y zip && wget https://github.com/opencv/opencv/archive/refs/tags/4.4.0.zip && unzip 4.4.0.zip && \
32+
RUN wget https://github.com/opencv/opencv/archive/refs/tags/4.4.0.zip && unzip 4.4.0.zip && \
3333
cd opencv-4.4.0 && mkdir build && cd build && \
3434
cmake .. -DCMAKE_BUILD_TYPE=Release \
3535
-DCMAKE_INSTALL_PREFIX=/usr/local \
@@ -44,13 +44,17 @@ RUN apt install -y python3-dev python3-pip subversion libgflags-dev
4444

4545
COPY . /hyperpose
4646

47-
# Get models
47+
# Get models: we first see if there's existing models here. If not install it throught network.
4848
# NOTE: if you cannot install the models due to network issues:
4949
# 1 Manually install ONNX and UFF models through: https://drive.google.com/drive/folders/1w9EjMkrjxOmMw3Rf6fXXkiv_ge7M99jR
5050
# 2 Put all models into `${GIT_DIR}/pre_installed_models`
51-
# 3.1 `RUN /hyperpose/scripts/download-test-data.sh`
52-
# 3.2 `RUN mv /hyperpose/pre_installed_models /hyperpose/data/models`
53-
RUN for file in $(find /hyperpose/scripts -type f -iname 'download*.sh'); do sh $file; done
51+
# 3 Re-build this docker image.
52+
RUN ( [ `find /hyperpose/pre_installed_models -regex '.*\.\(onnx\|uff\)' | wc -l` > 0 ] && \
53+
mkdir -p /hyperpose/data && mv /hyperpose/pre_installed_models/ /hyperpose/data/models ) || \
54+
for file in $(find /hyperpose/scripts -type f -iname 'download-*-model.sh'); do sh $file; done
55+
56+
# Install test data.
57+
RUN /hyperpose/scripts/download-test-data.sh
5458

5559
# Build Repo
5660
RUN cd hyperpose && mkdir build && cd build && \

docs/markdown/install/prediction.md

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ HyperPose is developed and frequently tested on Linux platforms. Hence, we recom
77

88
To ease the installation, you can use HyperPose library in our docker image where the environment is pre-installed.
99

10+
### Prerequisites
11+
12+
You can simply run `python scripts/check_docker_run.py` to check your environment and get related instructions.
13+
14+
- [CUDA Driver >= 410.48](https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#driver-installation)
15+
- [NVidia Docker >= 2.0](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#pre-requisites)
16+
- [Docker >= 19.03](https://docs.docker.com/engine/install/)
17+
1018
### Official Docker Image
1119

1220
NVidia docker support is required to execute our docker image.

scripts/auto-format.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ set -e
22

33
export CLANG_FORMAT=clang-format
44

5-
[ $(which $CLANG_FORMAT) ] || python3 -m pip install clang-format
5+
command -v $CLANG_FORMAT || python3 -m pip install clang-format
66

77
format_dir() {
8-
find $1 -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec $CLANG_FORMAT -style=file -i {} \;
8+
find "$1" -regex '.*\.\(cpp\|hpp\|cc\|cxx\)' -exec $CLANG_FORMAT -style=file -i {} \;
99
}
1010

11-
cd $(dirname $0)/..
11+
cd "$(dirname "$0")"/..
1212

1313
format_dir ./examples
1414
format_dir ./include

scripts/check_docker_run.py

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
import unittest
3+
import re
4+
from distutils.version import StrictVersion
5+
6+
7+
class LinuxCheck(unittest.TestCase):
8+
def test_cuda_driver(self):
9+
p = os.popen('cat /proc/driver/nvidia/version')
10+
output = p.read()
11+
p.close()
12+
self.assertTrue('NVIDIA' in output.upper(), 'NVIDIA Driver not found. Please visit '
13+
'https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index'
14+
'.html '
15+
'#driver-installation')
16+
if 'NVIDIA' in output.upper():
17+
version_code = None
18+
for line in output.splitlines():
19+
if 'NVIDIA' in line:
20+
for item in line.split(' '):
21+
m = re.search('[0-9][0-9][0-9].[0-9][0-9].[0-9][0-9]', item)
22+
if m is not None:
23+
version_code = m.group(0)
24+
break
25+
self.assertNotEqual(version_code, None, 'NVIDIA version not found...')
26+
if version_code is not None:
27+
self.assertGreaterEqual(StrictVersion(version_code), StrictVersion('410.48'), 'Your CUDA driver is '
28+
'old. Please upgrade it '
29+
'to >= 410.48 according '
30+
'to '
31+
'https://docs.nvidia'
32+
'.com/cuda/cuda'
33+
'-installation-guide'
34+
'-linux/index.html'
35+
'#driver-installation')
36+
37+
def test_docker_version(self):
38+
p = os.popen("docker version --format '{{.Client.Version}}'")
39+
version_code = p.read()
40+
return_code = p.close()
41+
self.assertEqual(return_code, None, 'docker command not found...')
42+
self.assertNotEqual(version_code, None, 'Docker version cannot be found...')
43+
self.assertGreaterEqual(StrictVersion(version_code), StrictVersion('19.03'), 'Your docker version is too old '
44+
'to support "--gpus" flag... '
45+
'Please install a newer version '
46+
'(>= 19.03) via '
47+
'https://docs.docker.com/engine'
48+
'/install/')
49+
50+
def test_nvidia_docker(self):
51+
return_code = os.system("docker run --rm --gpus all nvidia/cuda:10.0-base nvidia-smi")
52+
self.assertEqual(return_code, 0, 'Docker with CUDA functionality cannot run properly. Please visit '
53+
'https://docs.nvidia.com/datacenter/cloud-native/container-toolkit'
54+
'/install-guide.html#pre-requisites to install latest nvidia container')
55+
56+
57+
if __name__ == '__main__':
58+
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)