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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS True)

# set(CMAKE_POSITION_INDEPENDENT_CODE True)

SET(GCC_COMPILE_FLAGS "")
SET(GCC_COMPILE_FLAGS "-Wno-psabi")
SET(GCC_LINK_FLAGS "-lprotobuf -lopencv_core -lopencv_highgui -lopencv_features2d -lopencv_flann -lopencv_imgcodecs -lopencv_dnn -lopencv_videoio -lopencv_imgproc -lopencv_ml -lopencv_photo -lprotobuf")

SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}")
Expand Down
87 changes: 49 additions & 38 deletions docker/Dockerfile.arm
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
FROM arm64v8/ubuntu:22.04

ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive
ARG PYTHON_VERSION
ARG CMAKE_VERSION
ARG BOOST_VERSION
ARG LIBTORCH_VERSION
ARG TORCHVISION_VERSION
ARG MAVSDK_VERSION

# Needed to spawn up a GUI in headless mode for matplotplus to work
ENV QT_QPA_PLATFORM="vnc"
Expand Down Expand Up @@ -59,8 +65,8 @@ RUN apt-get install -y cpplint
ENV PYENV_ROOT="/.pyenv"
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH"
RUN curl https://pyenv.run | bash
RUN pyenv install 3.11
RUN pyenv global 3.11
RUN pyenv install ${PYTHON_VERSION}
RUN pyenv global ${PYTHON_VERSION}
RUN pip3 install typing-extensions PyYAML cpplint numpy

RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
Expand All @@ -71,29 +77,33 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& wget https://github.com/Kitware/CMake/releases/download/v3.27.7/cmake-3.27.7-linux-aarch64.sh \
&& wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-aarch64.sh \
-q -O /tmp/cmake-install.sh \
&& chmod u+x /tmp/cmake-install.sh \
&& mkdir /opt/cmake-3.24.1 \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
&& mkdir /opt/cmake-${CMAKE_VERSION} \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VERSION} \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin
&& ln -s /opt/cmake-${CMAKE_VERSION}/bin/* /usr/local/bin

# Download and install Boost 1.87.0
RUN wget https://github.com/boostorg/boost/releases/download/boost-1.87.0/boost-1.87.0-b2-nodocs.tar.gz \
&& tar -xzf boost-1.87.0-b2-nodocs.tar.gz \
&& cd boost-1.87.0 \
# Download and install Boost
WORKDIR /tmp
RUN wget https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-b2-nodocs.tar.gz \
&& tar -xzf boost-${BOOST_VERSION}-b2-nodocs.tar.gz \
&& cd boost-${BOOST_VERSION} \
&& ./bootstrap.sh \
&& ./b2 install \
&& cd .. \
&& rm -rf boost-1.87.0 boost-1.87.0-b2-nodocs.tar.gz
&& cd /tmp \
&& rm -rf boost-${BOOST_VERSION} boost-${BOOST_VERSION}-b2-nodocs.tar.gz

# install MAVSDK from source
RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v3.15.0 --single-branch \
WORKDIR /tmp
RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v${MAVSDK_VERSION} --single-branch \
&& cd MAVSDK \
&& git submodule update --init --recursive \
&& cmake -DCMAKE_BUILD_TYPE=Release -Bbuild/default -H. \
&& cmake --build build/default -j4 --target install
&& cmake --build build/default -j4 --target install \
&& cd /tmp \
&& rm -rf MAVSDK

# the official docs say also these
# https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
Expand All @@ -102,13 +112,12 @@ RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v3.15.0 -

# Make sure to install the same version of torchvision as the version of
# libtorch we built in the Jetson
ARG LIBTORCH_VERSION=2.3.1
ARG LIBTORCH_INSTALL_DIR=/libtorch-tmp
WORKDIR ${LIBTORCH_INSTALL_DIR}
RUN git clone --recursive --branch v${LIBTORCH_VERSION} https://github.com/pytorch/pytorch.git
RUN mkdir pytorch-build
RUN cd pytorch-build && \
USE_CUDA=0 \
WORKDIR /tmp
RUN git clone --recursive --branch v${LIBTORCH_VERSION} https://github.com/pytorch/pytorch.git \
&& cd pytorch \
&& mkdir build \
&& cd build \
&& USE_CUDA=0 \
USE_CUDNN=0 \
USE_NCCL=0 \
BUILD_TORCH=ON \
Expand Down Expand Up @@ -136,11 +145,10 @@ RUN cd pytorch-build && \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DPYTHON_EXECUTABLE:PATH=$(which python3) \
-DCMAKE_INSTALL_PREFIX=${LIBTORCH_INSTALL_DIR}/libtorch \
-DCMAKE_INSTALL_PREFIX=/opt/libtorch \
-DBUILD_CUSTOM_PROTOBUF=OFF \
../pytorch
RUN cd pytorch-build && \
USE_CUDA=0 \
.. \
&& USE_CUDA=0 \
USE_CUDNN=0 \
USE_NCCL=0 \
BUILD_TORCH=ON \
Expand All @@ -151,28 +159,31 @@ RUN cd pytorch-build && \
BUILD_CAFFE2_OPS=0 \
BUILD_CAFFE2=0 \
cmake --build . -j4 --target install \
&& rm -f ${LIBTORCH_INSTALL_DIR}/libtorch/bin/protoc \
&& rm -rf ${LIBTORCH_INSTALL_DIR}/libtorch/lib/libprotobuf* \
&& rm -rf ${LIBTORCH_INSTALL_DIR}/libtorch/lib/libprotoc* \
&& rm -rf ${LIBTORCH_INSTALL_DIR}/libtorch/include/google/protobuf
&& rm -f /opt/libtorch/bin/protoc \
&& rm -rf /opt/libtorch/lib/libprotobuf* \
&& rm -rf /opt/libtorch/lib/libprotoc* \
&& rm -rf /opt/libtorch/include/google/protobuf \
&& cd /tmp \
&& rm -rf pytorch

ENV CMAKE_PREFIX_PATH="${LIBTORCH_INSTALL_DIR}/libtorch"
ENV CMAKE_PREFIX_PATH="/opt/libtorch"

ARG TORCHVISION_VERSION=0.18.1
ARG TORCHVISION_INSTALL_DIR=/torchvision-tmp
WORKDIR ${TORCHVISION_INSTALL_DIR}
WORKDIR /tmp
RUN wget "https://github.com/pytorch/vision/archive/refs/tags/v${TORCHVISION_VERSION}.zip" \
&& unzip "v${TORCHVISION_VERSION}.zip" \
&& mkdir -p "${TORCHVISION_INSTALL_DIR}/vision-${TORCHVISION_VERSION}/build" \
&& cd "${TORCHVISION_INSTALL_DIR}/vision-${TORCHVISION_VERSION}/build" \
&& cd vision-${TORCHVISION_VERSION} \
&& mkdir build \
&& cd build \
&& cmake -DWITH_CUDA=off -D_GLIBCXX_USE_CXX11_ABI=1 -DCMAKE_BUILD_TYPE=Release .. \
&& make -j4 \
&& make install
&& make install \
&& cd /tmp \
&& rm -rf vision-${TORCHVISION_VERSION} v${TORCHVISION_VERSION}.zip

RUN pip3 install gdown
ENV PATH="${PATH}:/root/.local/bin"

# login as non-root user
USER $USERNAME

ENV PATH="${PATH}:/home/${USERNAME}/.local/bin"
ENV HOME="/home/${USERNAME}"
ENV PATH="${PATH}:${HOME}/.local/bin"
33 changes: 20 additions & 13 deletions docker/Dockerfile.jetson
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
FROM dustynv/l4t-pytorch:r36.2.0

ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive
ARG BOOST_VERSION
ARG TORCHVISION_VERSION
ARG MAVSDK_VERSION

# Needed to spawn up a GUI in headless mode for matplotplus to work
ENV QT_QPA_PLATFORM="vnc"
Expand Down Expand Up @@ -58,45 +61,49 @@ RUN pip3 install --no-cache-dir --index-url https://pypi.org/simple typing-exten
RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
&& chmod 0440 /etc/sudoers.d/$USERNAME

# Download and install Boost 1.87.0
RUN wget https://github.com/boostorg/boost/releases/download/boost-1.87.0/boost-1.87.0-b2-nodocs.tar.gz \
&& tar -xzf boost-1.87.0-b2-nodocs.tar.gz \
&& cd boost-1.87.0 \
# Download and install Boost
WORKDIR /tmp
RUN wget https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-b2-nodocs.tar.gz \
&& tar -xzf boost-${BOOST_VERSION}-b2-nodocs.tar.gz \
&& cd boost-${BOOST_VERSION} \
&& ./bootstrap.sh \
&& ./b2 install \
&& cd .. \
&& rm -rf boost-1.87.0 boost-1.87.0-b2-nodocs.tar.gz
&& cd /tmp \
&& rm -rf boost-${BOOST_VERSION} boost-${BOOST_VERSION}-b2-nodocs.tar.gz

# install MAVSDK from source
ENV PIP_INDEX_URL=https://pypi.org/simple
RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v3.15.0 --single-branch \
WORKDIR /tmp
RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v${MAVSDK_VERSION} --single-branch \
&& cd MAVSDK \
&& git submodule update --init --recursive \
&& cmake -DCMAKE_BUILD_TYPE=Release -Bbuild/default -H. \
&& cmake --build build/default -j`nproc` --target install
&& cmake --build build/default -j`nproc` --target install \
&& cd /tmp \
&& rm -rf MAVSDK

ARG TORCHVISION_VERSION=0.18.1
# Space separated list of CUDA architecture versions.
# The version nubmers depend on the NVIDIA GPU model we're using and the installed CUDA version.
# For the Jetson Orin Nano with the "Ampere" architecture and CUDA 12.1 we can use version 8.6 (written as 86 in CUDA_ARCH_LIST).
# Can also run "nvcc --list-gpu-arch" on the Jetson to verify.
# See https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#gpu-feature-list
# and https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
# and https://stackoverflow.com/a/74962874
ARG TORCHVISION_INSTALL_DIR=/tmp/torchvision
ARG CUDA_ARCH_LIST="5.0 5.2 5.3 6.0 6.1 6.2 7.0 7.2 7.5 8.0 8.6 8.7 8.9 9.0"
WORKDIR ${TORCHVISION_INSTALL_DIR}
WORKDIR /tmp
RUN wget "https://github.com/pytorch/vision/archive/refs/tags/v${TORCHVISION_VERSION}.zip" \
&& unzip "v${TORCHVISION_VERSION}.zip" \
&& cd vision-${TORCHVISION_VERSION} \
&& mkdir build \
&& cd build \
&& cmake -DWITH_CUDA=1 -DTORCH_CUDA_ARCH_LIST="${CUDA_ARCH_LIST}" -DCUDA_HAS_FP16=1 -DCUDA_NO_HALF_OPERATORS=1 -DCUDA_NO_HALF_CONVERSIONS=1 -DCUDA_NO_HALF2_OPERATORS=1 -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="/usr/local/lib/python3.10/dist-packages/torch/share/cmake/Torch" .. \
&& make -j`nproc` \
&& make install
&& make install \
&& cd /tmp \
&& rm -rf vision-${TORCHVISION_VERSION} v${TORCHVISION_VERSION}.zip

RUN pip3 install gdown
ENV PATH="${PATH}:${HOME}/.local/bin"
ENV PATH="${PATH}:/root/.local/bin"

WORKDIR /obcpp
COPY . .
Expand Down
86 changes: 49 additions & 37 deletions docker/Dockerfile.x86
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
FROM amd64/ubuntu:22.04

ARG USERNAME=tuas USER_UID=1000 USER_GID=1000 DEBIAN_FRONTEND=noninteractive
ARG PYTHON_VERSION
ARG CMAKE_VERSION
ARG BOOST_VERSION
ARG LIBTORCH_VERSION
ARG TORCHVISION_VERSION
ARG MAVSDK_VERSION

# Needed to spawn up a GUI in headless mode for matplotplus to work
ENV QT_QPA_PLATFORM="vnc"
Expand Down Expand Up @@ -58,8 +64,8 @@ ENV PYENV_ROOT="/.pyenv"
RUN curl https://pyenv.run | bash
ENV PATH="${PATH}:${PYENV_ROOT}/bin"
RUN eval "$(pyenv init -)"
RUN pyenv install 3.11
RUN pyenv global 3.11
RUN pyenv install ${PYTHON_VERSION}
RUN pyenv global ${PYTHON_VERSION}
RUN pip3 install typing-extensions PyYAML cpplint numpy

RUN echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
Expand All @@ -70,22 +76,23 @@ RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
--mount=target=/var/cache/apt,type=cache,sharing=locked \
rm -f /etc/apt/apt.conf.d/docker-clean \
&& apt-get update \
&& wget https://github.com/Kitware/CMake/releases/download/v3.27.7/cmake-3.27.7-linux-x86_64.sh \
&& 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 /opt/cmake-3.24.1 \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-3.24.1 \
&& mkdir /opt/cmake-${CMAKE_VERSION} \
&& /tmp/cmake-install.sh --skip-license --prefix=/opt/cmake-${CMAKE_VERSION} \
&& rm /tmp/cmake-install.sh \
&& ln -s /opt/cmake-3.24.1/bin/* /usr/local/bin
&& ln -s /opt/cmake-${CMAKE_VERSION}/bin/* /usr/local/bin

# Download and install Boost 1.87.0
RUN wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz \
&& tar -xzf boost_1_87_0.tar.gz \
&& cd boost_1_87_0 \
# Download and install Boost
WORKDIR /tmp
RUN wget https://github.com/boostorg/boost/releases/download/boost-${BOOST_VERSION}/boost-${BOOST_VERSION}-b2-nodocs.tar.gz \
&& tar -xzf boost-${BOOST_VERSION}-b2-nodocs.tar.gz \
&& cd boost-${BOOST_VERSION} \
&& ./bootstrap.sh \
&& ./b2 install \
&& cd .. \
&& rm -rf boost_1_87_0 boost_1_87_0.tar.gz
&& cd /tmp \
&& rm -rf boost-${BOOST_VERSION} boost-${BOOST_VERSION}-b2-nodocs.tar.gz

# the official docs say also these
# https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html
Expand All @@ -96,13 +103,12 @@ RUN wget https://archives.boost.io/release/1.87.0/source/boost_1_87_0.tar.gz \

# Make sure to install the same version of torchvision as the version of
# libtorch we built in the Jetson
ARG LIBTORCH_VERSION=2.3.1
ARG LIBTORCH_INSTALL_DIR=/libtorch-tmp
WORKDIR ${LIBTORCH_INSTALL_DIR}
RUN git clone --recursive --branch v${LIBTORCH_VERSION} https://github.com/pytorch/pytorch.git
RUN mkdir pytorch-build
RUN cd pytorch-build && \
USE_CUDA=0 \
WORKDIR /tmp
RUN git clone --recursive --branch v${LIBTORCH_VERSION} https://github.com/pytorch/pytorch.git \
&& cd pytorch \
&& mkdir build \
&& cd build \
&& USE_CUDA=0 \
USE_CUDNN=0 \
USE_NCCL=0 \
BUILD_TORCH=ON \
Expand Down Expand Up @@ -130,11 +136,10 @@ RUN cd pytorch-build && \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DCMAKE_BUILD_TYPE:STRING=Release \
-DPYTHON_EXECUTABLE:PATH=$(which python3) \
-DCMAKE_INSTALL_PREFIX=${LIBTORCH_INSTALL_DIR}/libtorch \
-DCMAKE_INSTALL_PREFIX=/opt/libtorch \
-DBUILD_CUSTOM_PROTOBUF=OFF \
../pytorch
RUN cd pytorch-build && \
USE_CUDA=0 \
.. \
&& USE_CUDA=0 \
USE_CUDNN=0 \
USE_NCCL=0 \
BUILD_TORCH=ON \
Expand All @@ -145,38 +150,45 @@ RUN cd pytorch-build && \
BUILD_CAFFE2_OPS=0 \
BUILD_CAFFE2=0 \
cmake --build . -j$(nproc) --target install \
&& rm -f ${LIBTORCH_INSTALL_DIR}/libtorch/bin/protoc \
&& rm -rf ${LIBTORCH_INSTALL_DIR}/libtorch/lib/libprotobuf* \
&& rm -rf ${LIBTORCH_INSTALL_DIR}/libtorch/lib/libprotoc* \
&& rm -rf ${LIBTORCH_INSTALL_DIR}/libtorch/include/google/protobuf
&& rm -f /opt/libtorch/bin/protoc \
&& rm -rf /opt/libtorch/lib/libprotobuf* \
&& rm -rf /opt/libtorch/lib/libprotoc* \
&& rm -rf /opt/libtorch/include/google/protobuf \
&& cd /tmp \
&& rm -rf pytorch

ENV CMAKE_PREFIX_PATH="${LIBTORCH_INSTALL_DIR}/libtorch"
ENV CMAKE_PREFIX_PATH="/opt/libtorch"

# pull and build torchvision
# refer to this page for version compatibilty with pytorch (libtorch) https://github.com/pytorch/pytorch/wiki/PyTorch-Versions
ARG TORCHVISION_VERSION=0.18.1
ARG TORCHVISION_INSTALL_DIR=/torchvision-tmp
WORKDIR ${TORCHVISION_INSTALL_DIR}
WORKDIR /tmp
RUN wget "https://github.com/pytorch/vision/archive/refs/tags/v${TORCHVISION_VERSION}.zip" \
&& unzip "v${TORCHVISION_VERSION}.zip" \
&& mkdir -p "${TORCHVISION_INSTALL_DIR}/vision-${TORCHVISION_VERSION}/build" \
&& cd "${TORCHVISION_INSTALL_DIR}/vision-${TORCHVISION_VERSION}/build" \
&& cd vision-${TORCHVISION_VERSION} \
&& mkdir build \
&& cd build \
&& cmake -DWITH_CUDA=off -D_GLIBCXX_USE_CXX11_ABI=1 -DCMAKE_BUILD_TYPE=Release .. \
&& make -j$(nproc) \
&& make install
&& make install \
&& cd /tmp \
&& rm -rf vision-${TORCHVISION_VERSION} v${TORCHVISION_VERSION}.zip

# install MAVSDK from source
RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v3.15.0 --single-branch \
WORKDIR /tmp
RUN git clone --depth 1 https://github.com/mavlink/MAVSDK.git --branch v${MAVSDK_VERSION} --single-branch \
&& cd MAVSDK \
&& git submodule update --init --recursive \
&& cmake -DCMAKE_BUILD_TYPE=Release -Bbuild/default -H. \
&& cmake --build build/default -j$(nproc) --target install
&& cmake --build build/default -j$(nproc) --target install \
&& cd /tmp \
&& rm -rf MAVSDK

RUN pip3 install gdown
ENV PATH="${PATH}:${HOME}/.local/bin"
ENV PATH="${PATH}:/root/.local/bin"

# login as non-root user
USER $USERNAME
ENV HOME="/home/${USERNAME}"

RUN pip3 install gdown
ENV PATH="${PATH}:${HOME}/.local/bin"
Loading