Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .dockerignore
Empty file.
39 changes: 39 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
repos:
- repo: https://github.com/PyCQA/flake8.git
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/autoflake
rev: v2.2.1
hooks:
- id: autoflake
args: [--remove-all-unused-imports, --in-place]
- repo: https://github.com/PyCQA/isort.git
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-yapf.git
rev: v0.32.0
hooks:
- id: yapf
additional_dependencies: [toml]
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- id: end-of-file-fixer
- id: double-quote-string-fixer
- id: check-merge-conflict
- id: fix-encoding-pragma
args: ["--remove"]
- id: mixed-line-ending
args: ["--fix=lf"]
- repo: https://github.com/codespell-project/codespell.git
rev: v2.2.6
hooks:
- id: codespell
exclude: >
(?x)^(
.*\.toml
)$
272 changes: 272 additions & 0 deletions Dockerfile.cuda
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
# syntax=docker/dockerfile:1

# Does not work because of RTSP connection
# FROM nvcr.io/nvidia/pytorch:23.09-py3 AS base

# Variables used at build time.
## Base CUDA version. See all supported version at https://hub.docker.com/r/nvidia/cuda/tags?page=2&name=-devel-ubuntu
ARG CUDA_VERSION=11.8.0
## Base Ubuntu version.
ARG OS_VERSION=22.04

# Define base image.
FROM nvidia/cuda:${CUDA_VERSION}-cudnn8-devel-ubuntu${OS_VERSION} AS base

# Duplicate args because of the visibility zone
# https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
ARG CUDA_VERSION
ARG OS_VERSION

## Base TensorRT version.
ARG TRT_VERSION=8.6.1.6
## Base PyTorch version.
ARG TORCH_VERSION=2.2.0
## Base TorchVision version.
ARG TORCHVISION_VERSION=0.17.0
## Base OpenCV version.
ARG OPENCV_VERSION=4.8.0.74
## Base CMake version.
ARG CMAKE_VERSION=3.26.0
## Base Timezone
ARG TZ=Europe/Moscow

# Set environment variables.
## Set non-interactive to prevent asking for user inputs blocking image creation.
ENV DEBIAN_FRONTEND=noninteractive \
## Set timezone as it is required by some packages.
TZ=${TZ} \
## CUDA Home, required to find CUDA in some packages.
CUDA_HOME="/usr/local/cuda" \
## Set LD_LIBRARY_PATH for local libs (glog etc.)
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:/usr/local/lib" \
## Accelerate compilation flags (use all cores)
MAKEFLAGS=-j$(nproc) \
## Torch GPU arch list
TORCH_CUDA_ARCH_LIST="6.0 6.1 7.0 7.5 8.0 8.6 8.9"

RUN apt-get update && \
apt-get install \
--no-install-recommends \
--yes \
# Basics
gcc \
g++ \
yasm \
unzip \
git \
wget \
libx264-dev \
libgnutls28-dev \
python3 \
python3-pip \
python3-dev \
python3-setuptools \
# Requirements from ultralytics
libgl1 \
libglib2.0-0 \
gnupg \
libusb-1.0-0 \
# Linux security updates
# https://security.snyk.io/vuln/SNYK-UBUNTU1804-OPENSSL-3314796
openssl \
tar \
# Image I/O libs
libjpeg-dev \
libpng-dev \
libtiff-dev \
# Parallelism library C++ for CPU
libtbb-dev \
# Optimization libraries for OpenCV
libatlas-base-dev \
gfortran \
# Video/Audio Libs - FFMPEG, GSTREAMER, x264 and so on.
## AV Lib [does not work with tensor_stream]
# libavcodec-dev \
# libavformat-dev \
# libswscale-dev \
## Gstreamer
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev && \
## Clean cached files
ln -s /usr/bin/python3 /usr/bin/python && \
apt-get clean --yes && \
apt-get autoremove --yes && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /var/cache/apt/archives/* && \
## Set timezone
ln -snf /usr/share/zoneinfo/${TZ} /etc/localtime && \
echo ${TZ} > /etc/timezone

SHELL ["/bin/bash", "-c"]

# Install CMake
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /usr/bin/cmake \
&& /tmp/cmake-install.sh --skip-license --prefix=/usr/bin/cmake \
&& rm /tmp/cmake-install.sh

ENV PATH="/usr/bin/cmake/bin:${PATH}"

# Install TensorRT
## Now only supported for Ubuntu 22.04
## Cannot install via pip because cuda-based errors
RUN v="${TRT_VERSION}-1+cuda${CUDA_VERSION%.*}" distro="ubuntu${OS_VERSION//./}" arch=$(uname -m) && \
wget https://developer.download.nvidia.com/compute/cuda/repos/${distro}/${arch}/cuda-archive-keyring.gpg && \
mv cuda-archive-keyring.gpg /usr/share/keyrings/cuda-archive-keyring.gpg && \
echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/${distro}/${arch}/ /" | \
tee /etc/apt/sources.list.d/cuda-${distro}-${arch}.list && \
apt-get update && \
apt-get install \
libnvinfer-headers-dev=${v} \
libnvinfer-dispatch8=${v} \
libnvinfer-lean8=${v} \
libnvinfer-dev=${v} \
libnvinfer-headers-plugin-dev=${v} \
libnvinfer-lean-dev=${v} \
libnvinfer-dispatch-dev=${v} \
libnvinfer-plugin-dev=${v} \
libnvinfer-vc-plugin-dev=${v} \
libnvparsers-dev=${v} \
libnvonnxparsers-dev=${v} \
libnvinfer8=${v} \
libnvinfer-plugin8=${v} \
libnvinfer-vc-plugin8=${v} \
libnvparsers8=${v} \
libnvonnxparsers8=${v} && \
apt-get install \
python3-libnvinfer=${v} \
tensorrt-dev=${v} && \
apt-mark hold tensorrt-dev

# Build nvidia codec headers
RUN git clone -b sdk/11.1 --single-branch https://git.videolan.org/git/ffmpeg/nv-codec-headers.git && \
cd nv-codec-headers && make install && \
cd .. && rm -rf nv-codec-headers

# Build ffmpeg with nvenc support
RUN git clone --depth 1 -b release/6.0 --single-branch https://github.com/FFmpeg/FFmpeg.git && \
cd FFmpeg && \
mkdir ffmpeg_build && cd ffmpeg_build && \
../configure \
--enable-cuda \
--enable-shared \
--enable-decoder=aac \
--enable-decoder=h264 \
--enable-decoder=h264_cuvid \
--enable-decoder=rawvideo \
--enable-indev=lavfi \
--enable-encoder=libx264 \
--enable-encoder=h264_nvenc \
--enable-demuxer=mov \
--enable-muxer=mp4 \
--enable-filter=scale \
--enable-filter=testsrc2 \
--enable-protocol=file \
--enable-protocol=https \
--enable-network \
--enable-protocol=tcp \
--enable-protocol=udp \
--enable-protocol=rtp \
--enable-demuxer=rtsp \
--enable-gnutls \
--enable-shared \
--enable-gpl \
--enable-nonfree \
--enable-libx264 \
--enable-nvenc \
--enable-cuvid \
--enable-nvdec \
--disable-static \
--disable-doc \
--extra-cflags='-I/usr/local/cuda/include' \
--extra-ldflags='-L/usr/local/cuda/lib64' \
--extra-libs=-lpthread \
--nvccflags="-arch=sm_60 \
-gencode=arch=compute_60,code=sm_60 \
-gencode=arch=compute_61,code=sm_61 \
-gencode=arch=compute_70,code=sm_70 \
-gencode=arch=compute_75,code=sm_75 \
-gencode=arch=compute_80,code=sm_80 \
-gencode=arch=compute_86,code=sm_86 \
-gencode=arch=compute_89,code=sm_89 \
-gencode=arch=compute_89,code=compute_89" && \
make clean && make -j$(nproc) && make install && ldconfig && \
cd ../.. && rm -rf FFmpeg

# Install torch
RUN python3 -m pip install \
--upgrade \
--no-cache \
pip \
wheel \
setuptools \
packaging \
ninja && \
## Install pytorch and submodules
CUDA_VER=${CUDA_VERSION%.*} && CUDA_VER=${CUDA_VER//./} && \
python3 -m pip install \
--no-cache \
torch==${TORCH_VERSION} \
torchvision==${TORCHVISION_VERSION} \
torchaudio==${TORCH_VERSION} \
--index-url https://download.pytorch.org/whl/cu${CUDA_VER}

# Create working directory
WORKDIR /usr/src/

# Install OpenCV with CUDA
RUN python3 -m pip uninstall \
--yes \
opencv-contrib-python \
opencv-python-headless \
opencv-python && \
ln -s /usr/include/x86_64-linux-gnu/cudnn_version_v8.h /usr/include/x86_64-linux-gnu/cudnn_version.h && \
git clone --depth 1 -b ${OPENCV_VERSION%.*} https://github.com/opencv/opencv.git /usr/src/opencv && \
git clone --depth 1 -b ${OPENCV_VERSION%.*} https://github.com/opencv/opencv_contrib.git /usr/src/opencv_contrib && \
cd /usr/src/opencv && \
mkdir build && \
cd build && \
cmake \
-D CPACK_BINARY_DEB=ON \
-D BUILD_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_opencv_cudacodec=ON \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D BUILD_opencv_java=OFF \
-D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D CUDA_ARCH_BIN=6.0,6.1,7.0,7.5,8.0,8.6,8.9 \
-D CUDA_ARCH_PTX= \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D CUDNN_INCLUDE_DIR=/usr/include/x86_64-linux-gnu \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D WITH_EIGEN=ON \
-D ENABLE_NEON=OFF \
-D OPENCV_DNN_CUDA=ON \
-D OPENCV_ENABLE_NONFREE=ON \
-D OPENCV_EXTRA_MODULES_PATH=/usr/src/opencv_contrib/modules \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D WITH_CUBLAS=ON \
-D WITH_CUDA=ON \
-D WITH_CUDNN=ON \
-D WITH_GSTREAMER=ON \
-D WITH_LIBV4L=ON \
-D WITH_OPENGL=ON \
-D WITH_OPENCL=OFF \
-D WITH_IPP=OFF \
-D WITH_TBB=ON \
-D WITH_TIFF=ON \
-D WITH_JPEG=ON \
-D WITH_PNG=ON \
-D BUILD_PERF_TESTS=OFF \
-D BUILD_TESTS=OFF \
-D WITH_QT=OFF \
-D BUILD_DOCS=OFF \
.. && \
make -j$(nproc) && \
make install && \
ldconfig
Loading