AI Based Object Redaction - Getting Started - Building librrobjectredaction

From RidgeRun Developer Wiki
Revision as of 23:43, 24 January 2024 by Kcarvajal (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Index





Installing dependencies

In the following sections, you can see how to install the dependencies required to build librrobjectredaction.

CUDA L4T pacakge (NPPI library)

Installation guide for CUDA:

1. You will need to know which distribution version you are using:

lsb_release -a

2. Depending on your platform follow the next instructions:

Jetson platforms

The Jetpack default installation will flash and install all the necessary CUDA packages, including NPPI library. This section describes how to perform a manual installation, which is typically __NOT__ needed
  • Depending on what Jetpack release you have installed on your Jetson, you might want to download the corresponding CUDA Toolkit version, including NPPI library. In the following table you can see which one you need. Click on the link and follow the selection menu.
Jetpack Release CUDA Toolkit version
JetPack 4.x Get CUDA 10.2 Toolkit
JetPack 5.x Get CUDA 11.4 Toolkit

x86 platforms

3. Select the version depending on the lsb_release command executed above. We recommend using the deb (local) option for the installation.

4. Once you have selected your system setup, NVIDIA will show you the installation instructions for those requirements.

OpenCV

To install OpenCV for C++, please use:

sudo apt install libopencv-dev

ONNX Runtime

In this section you will find instructions to install ONNX for JetPack versions: 5.1.X and 4.6.X.

Jetpack 5.1.X

1.Install all the dependencies needed:

sudo apt-get install nvidia-l4t-cuda
sudo apt-get install nvidia-cudnn8
sudo apt-get install nvidia-tensorrt
sudo apt-get install apt-transport-https ca-certificates
sudo apt install -y --no-install-recommends \
   build-essential software-properties-common libopenblas-dev \
   libpython3.8-dev python3-pip python3-dev python3-setuptools python3-wheel
sudo apt-get install libssl-dev openssl openssl1.1 
sudo apt-get install libcusparse-11-4 libcusparse-dev-11-4
sudo apt-get install libcurand-11-4 libcurand-dev-11-4

2. Install cmake 3.18+ (tested with 3.27)

wget https://github.com/Kitware/CMake/releases/download/v3.27.1/cmake-3.27.1-linux-aarch64.tar.gz
tar -xvf cmake-3.27.1-linux-aarch64.tar.gz
cd cmake-3.27.1-linux-aarch64
sudo cp -r * /usr/local/


3. Get Onnx

 git clone --recursive --branch v1.12.1 https://github.com/microsoft/onnxruntime

This specific version needs a wheel version 0.35.1 or greater.

pip install wheel==0.35.1

4. Prepare environment (It might not be needed if you already have access to the nvmm binary and /usr/local/cuda path already exists).

sudo ln -s /usr/local/cuda-11.4 /usr/local/cuda
export CUDACXX="/usr/local/cuda/bin/nvcc"
export PATH="/usr/local/cuda/bin:${PATH}"

5. Build

cd onnxruntime
 ./build.sh --config Release --update --build --parallel --build_wheel \
 --use_tensorrt --use_cuda --cuda_home /usr/local/cuda --cudnn_home /usr/lib/aarch64-linux-gnu \
 --tensorrt_home /usr/lib/aarch64-linux-gnu --build_shared_lib --skip_tests --parallel 4

6. Install

cd build/Linux/Release
sudo make install

JetPack 4.6.X

1.Install all the dependencies:

sudo apt-get install nvidia-l4t-cuda
sudo apt-get install nvidia-cudnn8
sudo apt-get install nvidia-tensorrt
sudo apt-get install apt-transport-https ca-certificates
sudo apt install -y --no-install-recommends \
   build-essential software-properties-common libopenblas-dev \
   libpython3.6-dev python3-pip python3-dev python3-setuptools python3-wheel
sudo apt-get install libssl-dev openssl openssl1.0
sudo apt-get install libcusparse-10-2 libcusparse-dev-10-2
sudo apt-get install libcurand-10-2 libcurand-dev-10-2

2. Install cmake 3.18+ (tested with 3.23)

wget https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-linux-aarch64.tar.gz
tar -xvf cmake-3.23.1-linux-aarch64
cd cmake-3.23.1
sudo cp -r * /usr/local/

3. Get Onnx

 git clone --recursive --branch v1.10.0 https://github.com/microsoft/onnxruntime

4. Prepare environment (It might not be needed if you already have access to the nvmm binary and /usr/local/cuda path already exists).

sudo ln -s /usr/local/cuda-10.2 /usr/local/cuda
export CUDACXX="/usr/local/cuda/bin/nvcc"
export PATH="/usr/local/cuda/bin:${PATH}"

5. Build

cd onnxruntime
 ./build.sh --config Release --update --build --parallel --build_wheel \
 --use_tensorrt --use_cuda --cuda_home /usr/local/cuda --cudnn_home /usr/lib/aarch64-linux-gnu \
 --tensorrt_home /usr/lib/aarch64-linux-gnu --build_shared_lib --skip_tests --parallel 4

6. Install

cd build/Linux/Release
sudo make install

GstCUDA

If you already own a professional version of this plugin, skip to the cuda undistort element below.

To install this plugin follow the instructions found in the Installation guide

Documentation (optional)

For the documentation, consider the following dependency:

  • doxygen

Please, install it using (in Debian-based systems):

sudo apt install -y     \
    doxygen

Tests (optional)

For building tests, consider the following dependency:

  • cpputest

Please, install it using (in Debian-based systems):

sudo apt install -y     \
    cpputest

Meson building system

At the building system level:

  • ninja-build
  • python3-pip
  • pkg-config
  • meson: version <=1.2.3

Please, install them using (in Debian-based systems):

sudo pip3 install meson==1.2.3
sudo apt install -y \
     python3        \
     python3-pip    \
     ninja-build    \
     pkg-config

The process should be similar in other systems, not based on Debian.

Building the project

Once fulfilled the dependencies, you can run a default compilation with:

meson build --optimization 3 --prefix /usr -Ddocs=disabled -Ddeveloper-mode=false -Denable-tests=disabled
ninja -C build
sudo ninja -C build install

For additional customization, you may refer to the following table of options:


Configure Option Description
-Ddeveloper-mode=false Disable developer mode. Enabled by default.
-Ddocs=Enable Documentation generation. Enabled by default. Values: disable and only. Choose "only" to build documentation only.
-Dgst=enabled Build GStreamer elements. Disabled by default.
-Denable-tests=disabled Build tests. Enabled by default.
-Dtrt_engine_cache_path Path for cache directory for TensorRT. Default value: "~/.redaction".
--prefix /usr Set the installation path of the library.
--optimization 3 Set the optimization level to the maximum
Table 1. Librrobjectredaction configuration options (Meson)

Check element installation

After building the project using the -Dgst=enabled option, test that the plugin is being properly picked up by GStreamer by running:

gst-inspect-1.0 rrobjectredaction

The expected output is:

#gst-inspect-1.0 rrobjectredaction
Plugin Details:
  Name                     rrobjectredaction
  Description              Object redaction plugin
  Filename                 /usr/lib/aarch64-linux-gnu/gstreamer-1.0/libgstrrobjectredaction.so
  Version                  0.1.0
  License                  Proprietary
  Source module            rrobjectredaction
  Binary package           rrobjectredaction
  Origin URL               https://www.ridgerun.com/

  rrfacedetector: GstCUDA Face Detector
  rrobjectredactor: Gst CUDA Object Redactor

  2 features:
  +-- 2 elements

Also run:

gst-inspect-1.0 | grep rrobjectredaction

The expected output is:

rrobjectredaction:  rrfacedetector: GstCUDA Face Detector
rrobjectredaction:  rrobjectredactor: Gst CUDA Object Redactor


Index