HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2021/08/07

NVIDIA Jetsonの JetPack 4.6で MediaPipe v0.8.6のビルドとインストールをする方法 NVIDIA Jetsonの JetPack 4.6で MediaPipe v0.8.6のビルドとインストールをする方法

(Jetson Nanoに MediaPipe v0.8.6と Python Packageをビルドとインストールをする方法)

Tags: [Raspberry Pi], [電子工作], [ディープラーニング]




● Jetson Nano、Jetson Xavier NXの JetPack 4.6で MediaPipe v0.8.6のビルドとインストールをする方法

 Jetson Nano、Jetson Xavier NXに MediaPipe v0.8.6 Python Packageをビルドとインストールをする方法。

 Jetson Nano、Jetson Xavier NXで Tokyo2020-Pictogram-using-MediaPipeや Pictogram-san Appを動かす!

 動きました。

● NVIDIA Jetson Xavier + USB WebCameraでの実行例
 ※ CSI接続のカメラ(Xavier基板に直接接続するラズパイ カメラ)では画像取り込みができず動きませんでした

2021/08/07
NVIDIA Jetsonで Tokyo2020オリンピック風のピクトグラムを表示を動かす方法
NVIDIA Jetsonで Tokyo2020オリンピック風のピクトグラムを表示を動かす方法

  Jetsonに MediaPipeをインストールして Tokyo2020-Pictogram-using-MediaPipeを動かす
・NVIDIA Jetsonで Tokyo2020オリンピック風のピクトグラムを表示を動かす方法
NVIDIA Jetsonで Tokyo2020オリンピック風のピクトグラムを表示を動かす方法



● 東京五輪のピクトグラムさんになれるゲーム Pictogram Challenge

2021/08/07
NVIDIA Jetsonで 東京五輪のピクトグラムさんになれるゲーム Pictogram Challengeを動かす方法
NVIDIA Jetsonで 東京五輪のピクトグラムさんになれるゲーム Pictogram Challengeを動かす方法

  Jetsonの MediaPipeで Pictogram-sanで東京オリンピックのピクトグラムの連続パフォーマンスをキメる!
・NVIDIA Jetsonで 東京五輪のピクトグラムさんになれるゲーム Pictogram Challengeを動かす方法
NVIDIA Jetsonで 東京五輪のピクトグラムさんになれるゲーム Pictogram Challengeを動かす方法




● Jetson Nano、Jetson Xavier NXの便利スクリプト

2020/07/03
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト

  Jetsonの面倒な初期設定やミドルウェアのインストールを bashスクリプトの実行だけで簡単にできます


● Jetson Nano、Jetson Xavier NXの JetPack 4.6で MediaPipe v0.8.6のビルドとインストールをする方法

 ビルド環境
 ・Jetson Nano 4GB model or Jetson Xavier NX
 ・NVIDIA JetPack 4.6
 ・MediaPipe v0.8.6
 ・Bazel 3.7.2
 ・CMake 3.19.4
 ・gcc 8.4.0
 ・Protocol Buffers v3.17.3
 ・Python 3 v3.6.9 + Python Virtual environments + pip 21.2.3

$ uname -a
Linux ubuntu 4.9.253-tegra #1 SMP PREEMPT Mon Jul 26 12:13:06 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux


● Bazel 3.7.2を zipパッケージからインストールする
 ビルドの時間が不要なので時間短縮できる。
 上記の「Jetson Nano、Jetson Xavier NXの便利スクリプト」からダウンロードできます。
# https://github.com/FREEWING-JP/Jetson_Convenience_Script
cd
git clone https://github.com/FREEWING-JP/Jetson_Convenience_Script 00_deb -b 00_deb
mv ./00_deb/00_deb/* ./00_deb/
# */
ls -l ./00_deb

# Bazel 3.7.2
cd
bash ./Jetson_Convenience_Script/Bazel/inst_Bazel_372.sh
# Install from .zip package ? or Build Bazel ? (i/b):i
# iを入力で zip packageからのインストールが可能

下記の方法は Jetson Nano Xavierでは使えません。(Jetson Nano Xavierは ARM CPUなので)
# Install Bazelisk
# https://docs.bazel.build/versions/main/install-bazelisk.html

# Step 1: Add Bazel distribution URI as a package source
sudo apt install -y apt-transport-https curl gnupg
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

●# Step 2a: Install Bazel
sudo apt update
apt search bazel
sudo apt install bazel

●# Step 2b: Update Bazel
sudo apt update && sudo apt full-upgrade


● CMake 3.19.4を debパッケージからインストールする
 ビルドの時間が不要なので時間短縮できる。
 上記の「Jetson Nano、Jetson Xavier NXの便利スクリプト」からダウンロードできます。
# https://github.com/FREEWING-JP/Jetson_Convenience_Script

# CMake 3.19.4
cd
bash ./Jetson_Convenience_Script/CMake/inst_CMake.sh
# Install from .deb package ? or Build CMake ? (i/b):i
# iを入力で deb packageからのインストールが可能


● gcc 8.4.0
# Install gcc 8.4.0
# Mediapipe build error #1733
# https://github.com/google/mediapipe/issues/1733
cd
bash ./Jetson_Convenience_Script/gcc/inst_gcc_840.sh

gcc --version
# gcc (Ubuntu/Linaro 8.4.0-1ubuntu1~18.04) 8.4.0


● Protocol Buffers v3.17.3
 google/protobuf/any.proto: File not found エラー対策。
# Protocol Buffers v3.17.3
# google/protobuf/any.proto: File not found .
# Protocol Buffers - Google's data interchange format
# https://github.com/protocolbuffers/protobuf
cd
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.17.3/protobuf-all-3.17.3.tar.gz
tar -xvf protobuf-all-3.17.3.tar.gz
cd protobuf-3.17.3
./configure
# Out of Memory
# g++: fatal error: Killed signal terminated program cc1plus compilation terminated.
# make -j 6 core NG Killed (Jetson Xavier 8GB Memory)
# make -j4 4 core OK
time make -j4

# Jetson Xavier NX
# time make -j4
# real    14m4.393s
# user    51m46.404s
# sys     1m59.284s

# Jetson Nano 4GB
# time make -j2
# real    27m16.605s
# user    49m34.056s
# sys     2m4.132s

make check
# FAIL: protobuf-test
# Ignore this FAIL
# protobuf-test Failed: FAIL protobuf-test (exit status: 137) #7860
# https://github.com/protocolbuffers/protobuf/issues/7860

sudo make install

# protoc: error while loading shared libraries: libprotoc.so.28: cannot open shared object file: No such file or directory
sudo ldconfig

protoc --version
# libprotoc 3.17.3

● Install Python3 pip and venv Python Virtual environments
# NVIDIA JetPack 4.6 Ubuntu
python3 --version
# Python 3.6.9

# Install pip
sudo apt install -y python3-pip

# Update pip
pip3 -V
# pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)

sudo pip3 install pip --upgrade
pip3 -V
# pip 21.2.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

# WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
python3 -m pip --version
# pip 21.2.3 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

# Install Python3 pip and venv Python Virtual environments
sudo apt install -y python3-dev
sudo apt install -y python3-venv


● MediaPipe v0.8.6のビルドとインストール

Mediapipe

Installation - mediapipe

https://github.com/google/mediapipe/blob/master/docs/getting_started/install.md

# Installing MediaPipe on Debian and Ubuntu

# Checkout MediaPipe repository.
cd
# git clone https://github.com/google/mediapipe --depth 1
git clone https://github.com/google/mediapipe --depth 1 -b v0.8.6

# Change directory into MediaPipe root directory
cd mediapipe

# Install OpenCV and FFmpeg.
# Moreover, for Nvidia Jetson and Raspberry Pi devices with ARM Ubuntu, the library path needs to be modified like the following:
# sed -i "s/x86_64-linux-gnu/aarch64-linux-gnu/g" third_party/opencv_linux.BUILD
grep x86_64 ./third_party/opencv_linux.BUILD
# sed -i "s/lib\/x86_64-linux-gnu/lib/g" ./third_party/opencv_linux.BUILD

# Option 2
sed -i "s/install cmake/install/g" setup_opencv.sh
sed -i "s/apt install /apt install -y /g" setup_opencv.sh
chmod +x setup_opencv.sh
time ./setup_opencv.sh

# Jetson Xavier NX
# real    23m46.025s
# user    94m49.204s
# sys     3m48.728s

# Jetson Nano 4GB
# real    35m10.627s
# user    101m53.784s
# sys     4m55.352s

ffmpeg -version
# ffmpeg version 3.4.8-0ubuntu0.2 Copyright (c) 2000-2020 the FFmpeg developers
# built with gcc 7 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)

opencv_version
# 3.4.15-dev

# Run the Hello World! in C++ example .
export GLOG_logtostderr=1

# CPU only
bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
    mediapipe/examples/desktop/hello_world:hello_world

# with GPU support enabled
bazel run --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
    mediapipe/examples/desktop/hello_world:hello_world

# Hello World!の行が沢山出れば MediaPipe成功!
INFO: Running command line: bazel-bin/mediapipe/examples/desktop/hello_world/helINFO: Build completed successfully, 1 total action
I20210810 03:11:31.883471 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.883751 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.883859 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.883939 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.884403 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.884481 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.884536 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.884733 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.884943 12747 hello_world.cc:57] Hello World!
I20210810 03:11:31.885159 12747 hello_world.cc:57] Hello World!


● MediaPipe Handsのサンプル
MediaPipe Hands

MediaPipe in C++
# Running on GPU
# Graph: mediapipe/graphs/hand_tracking/hand_tracking_desktop_live_gpu.pbtxt
# Target: mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu

cd
cd mediapipe
bazel build -c opt \
    --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
    mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu

export GLOG_logtostderr=1

bazel-bin/mediapipe/examples/desktop/hand_tracking/hand_tracking_gpu \
    --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_mobile.pbtxt
#     --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_desktop_live_gpu.pbtxt

# Equivalent
# CPU OK
COPT='--define MEDIAPIPE_DISABLE_GPU=1'
GRAPH=mediapipe/graphs/hand_tracking/hand_tracking_desktop_live.pbtxt
TARGET=mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu

# GPU NG ERROR FAILED Build did NOT complete successfully
# C++ compilation of rule '@org_tensorflow//tensorflow/lite/delegates/gpu/gl:gl_errors' failed
# Restart Jetson after GPU Build and Execute OK
COPT='--copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11'
GRAPH=mediapipe/graphs/hand_tracking/hand_tracking_desktop_live_gpu.pbtxt
TARGET=mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu

cd
cd mediapipe
export OPENBLAS_CORETYPE=ARMV8

bazel build -c opt $COPT $TARGET

export GLOG_logtostderr=1

TARGET_=`echo $TARGET | sed 's@:@/@'`
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH
 ※ Jetsonを再起動した後は GPUでも正常にビルドできて動いた。

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Hands Sample



● MediaPipe Hair Segmentationのサンプル

 頭部の髪の毛の部分を着色します。

MediaPipe Hair Segmentation
COPT='--copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11'
GRAPH=mediapipe/graphs/hair_segmentation/hair_segmentation_mobile_gpu.pbtxt
# NG GRAPH=mediapipe/graphs/hair_segmentation/hair_segmentation_desktop_live.pbtxt
TARGET=mediapipe/examples/desktop/hair_segmentation:hair_segmentation_gpu

cd
cd mediapipe
export OPENBLAS_CORETYPE=ARMV8

bazel build -c opt $COPT $TARGET
# Target //mediapipe/examples/desktop/hair_segmentation:hair_segmentation_gpu up-to-date:
#   bazel-bin/mediapipe/examples/desktop/hair_segmentation/hair_segmentation_gpu
# INFO: Elapsed time: 2198.308s, Critical Path: 879.24s
# INFO: 2322 processes: 5 internal, 2317 linux-sandbox.
# INFO: Build completed successfully, 2322 total actions

export GLOG_logtostderr=1

TARGET_=`echo $TARGET | sed 's@:@/@'`
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH

・NVIDIA Jetson Nano Google MediaPipe v0.8.6 Hair Segmentation Sample
NVIDIA Jetson Nano Google MediaPipe v0.8.6 Hair Segmentation Sample
 アニメ フィギュアの髪の毛(黄色)も認識してピンク色で表示します。

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Hair Segmentation Sample

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Hair Segmentation Sample


● MediaPipe Hair Segmentationの髪の毛の着色の色を変える方法
#      color { r: 0 g: 0 b: 255 }

mediapipe/graphs/hair_segmentation/hair_segmentation_mobile_gpu.pbtxt
# Colors the hair segmentation with the color specified in the option.
node {
  calculator: "RecolorCalculator"
  input_stream: "IMAGE_GPU:throttled_input_video"
  input_stream: "MASK_GPU:hair_mask"
  output_stream: "IMAGE_GPU:output_video"
  node_options: {
    [type.googleapis.com/mediapipe.RecolorCalculatorOptions] {
      color { r: 0 g: 0 b: 255 }
      mask_channel: RED
    }
  }
}


● MediaPipe Face Landmarkのサンプル

https://google.github.io/mediapipe/solutions/face_mesh.html

# Face Landmark Example
# Running on GPU
COPT='--copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11'
GRAPH=mediapipe/graphs/face_mesh/face_mesh_desktop_live_gpu.pbtxt
TARGET=mediapipe/examples/desktop/face_mesh:face_mesh_gpu

cd
cd mediapipe
export OPENBLAS_CORETYPE=ARMV8

bazel build -c opt $COPT $TARGET

export GLOG_logtostderr=1

TARGET_=`echo $TARGET | sed 's@:@/@'`
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Face Mesh Sample

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Face Mesh Sample



● MediaPipe Objectronのサンプル

MediaPipe Objectron

cd
cd mediapipe
export OPENBLAS_CORETYPE=ARMV8

bazel build -c opt \
  --define MEDIAPIPE_DISABLE_GPU=1 \
  mediapipe/examples/desktop/object_detection_3d:objectron_cpu

# Category Shoe
BOX_LANDMARK_MODEL_PATH=mediapipe/modules/objectron/object_detection_3d_sneakers.tflite
ALLOWED_LABELS=Footwear
VIDEO=Legs-1610.mp4

# Category Camera
BOX_LANDMARK_MODEL_PATH=mediapipe/modules/objectron/object_detection_3d_camera.tflite
ALLOWED_LABELS=Camera
VIDEO=Photographer-50176.mp4

GLOG_logtostderr=1 \
bazel-bin/mediapipe/examples/desktop/object_detection_3d/objectron_cpu \
  --calculator_graph_config_file=mediapipe/graphs/object_detection_3d/objectron_desktop_cpu.pbtxt \
  --input_side_packets=input_video_path=$VIDEO,\
output_video_path=./out-$VIDEO,\
box_landmark_model_path=$BOX_LANDMARK_MODEL_PATH,\
allowed_labels=$ALLOWED_LABELS

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Objectron Sample

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Objectron Sample



● MediaPipe Holisticのサンプル

MediaPipe Holistic

cd
cd mediapipe
export OPENBLAS_CORETYPE=ARMV8

# Running on GPU NG
COPT='--copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11'
GRAPH=mediapipe/graphs/holistic_tracking/holistic_tracking_gpu.pbtxt
TARGET=mediapipe/examples/desktop/holistic_tracking:holistic_tracking_gpu

bazel build -c opt $COPT $TARGET
# INFO: Elapsed time: 1829.398s, Critical Path: 1085.36s
# INFO: 2227 processes: 74 internal, 2153 linux-sandbox.
# INFO: Build completed successfully, 2227 total actions

export GLOG_logtostderr=1

TARGET_=`echo $TARGET | sed 's@:@/@'`

VIDEO=Woman-83863.mp4
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH \
  --input_video_path="./$VIDEO" \
  --output_video_path="./out-$VIDEO"
# Segmentation fault (core dumped) Jetson Nano
# Segmentation fault (core dumped) Jetson Xavier NX

# Running on CPU OK
COPT='--define MEDIAPIPE_DISABLE_GPU=1'
GRAPH=mediapipe/graphs/holistic_tracking/holistic_tracking_cpu.pbtxt
TARGET=mediapipe/examples/desktop/holistic_tracking:holistic_tracking_cpu

bazel build -c opt $COPT $TARGET
# INFO: Elapsed time: 1169.837s, Critical Path: 464.14s
# INFO: 1853 processes: 2 internal, 1851 linux-sandbox.
# INFO: Build completed successfully, 1853 total actions

bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH \
  --input_video_path="./$VIDEO" \
  --output_video_path="./out-$VIDEO"

NVIDIA Jetson Nano Google MediaPipe v0.8.6 Holistic Sample



● MediaPipeのサンプルで使用した動画

高品質なフリー動画素材 Pixtabay

モデル 美しさ ビューティー サロン - Pixabayの無料動画
Model-21147.mp4

モデル 口紅 メイクアップ - Pixabayの無料動画
Model-46450.mp4

サロン 髪 ヘアコンサルタント - Pixabayの無料動画
Salon-50735.mp4

足 靴 赤 - Pixabayの無料動画
Legs-1610.mp4

カメラマン カメラ レンズ - Pixabayの無料動画
Photographer-50176.mp4

女性 ハッピー 笑顔 - Pixabayの無料動画
Woman-83863.mp4

マッサージ ウェルネス レクリエーション - Pixabayの無料動画
Massage-701.mp4


● MediaPipeで動画ファイルを入力して動画ファイルを書き出す方法

  --input_video_path="INPUT_VIDEO.mp4" \
  --output_video_path="OUTPUT_VIDEO.mp4"
# Sample
COPT='--copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11'
GRAPH=mediapipe/graphs/hair_segmentation/hair_segmentation_mobile_gpu.pbtxt
TARGET=mediapipe/examples/desktop/hair_segmentation:hair_segmentation_gpu

export GLOG_logtostderr=1

TARGET_=`echo $TARGET | sed 's@:@/@'`

VIDEO=Girl-46948.mp4
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH \
  --input_video_path="./$VIDEO" \
  --output_video_path="./out-$VIDEO"

VIDEO=Salon-50735.mp4
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH \
  --input_video_path="./$VIDEO" \
  --output_video_path="./out-$VIDEO"

VIDEO=Woman-61893.mp4
bazel-bin/$TARGET_ --calculator_graph_config_file=$GRAPH \
  --input_video_path="./$VIDEO" \
  --output_video_path="./out-$VIDEO"


● MediaPipeを画面無しで動かす方法

 Using MediaPipe headless mode without Screen

 VNC接続不要で SSH接続だけで MediaPipeを実行できる。

how to run solution samples for desktop on headless device? [no display connected] #1950
W20210812 00:26:59.606438 21116 gl_context_egl.cc:168] Creating a context with OpenGL ES 3 failed: UNKNOWN: ; eglChooseConfig() returned no matching EGL configuration for RGBA8888 D16 ES3 request.
W20210812 00:26:59.606465 21116 gl_context_egl.cc:169] Fall back on OpenGL ES 2.
E20210812 00:26:59.607151 21116 demo_run_graph_main_gpu.cc:197] Failed to run the graph: ; eglChooseConfig() returned no matching EGL configuration for RGBA8888 D16 ES2 request.

Solution export DISPLAY=:0
cd /tmp/.X11-unix && for x in X*; do echo ":${x#X}"; done ; cd -
export DISPLAY=:0
echo $DISPLAY
 ※ VNCで仮想ディスプレイの有効化は必要


● MediaPipeの Pythonパッケージのビルド
 Building MediaPipe Python Package

Building MediaPipe Python Package

https://github.com/google/mediapipe/blob/master/docs/getting_started/python.md

# Debian or Ubuntu
# sudo apt install -y protobuf-compiler
# protoc --version
# libprotoc 3.0.0

protoc --version
# libprotoc 3.17.3

# /usr/bin/ld.gold: error: cannot find -lavresample
sudo apt install libavresample-dev

# In the virtual environment, go to the MediaPipe repo directory.
cd
cd mediapipe
# Activate a Python virtual environment.
python3 -m venv mp_env && source mp_env/bin/activate

# Update pip
pip3 -V
# pip 9.0.1 from /home/jetson/mediapipe/mp_env/lib/python3.6/site-packages (python 3.6)
python3 -m pip install --upgrade pip
pip3 -V
# pip 21.2.3 from /home/jetson/mediapipe/mp_env/lib/python3.6/site-packages/pip (python 3.6)

pip3 list

# Install the required Python packages.

# ModuleNotFoundError No module named 'Cython'
pip3 install --no-binary :all: --no-cache-dir Cython

# ModuleNotFoundError: No module named 'numpy'
# numpy-1.21.1 RuntimeError Python version >= 3.7 required
pip3 install numpy==1.19.5
python3 -c "import numpy as np; print(np.__version__); print(np.__path__); print(np.get_include()); np.show_config();"
# Illegal instruction (core dumped) numpy-1.19.5 bug
# set OPENBLAS_CORETYPE environment variable to ARMV8
export OPENBLAS_CORETYPE=ARMV8

# matplotlib>=3.0.0 RuntimeError Python version >= 3.7 required
# ERROR: Command errored out with exit status -4:
pip3 install pyparsing==2.4.7
pip3 install python-dateutil==2.8.2
pip3 install pytz==2021.1
pip3 install six==1.16.0

pip3 install matplotlib==2.2.5
# Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-2.2.5 pyparsing-2.4.7 python-dateutil-2.8.2 pytz-2021.1 six-1.16.0

# ModuleNotFoundError: No module named 'skbuild'
pip3 install scikit-build

# opencv-contrib-python
# https://pypi.org/project/opencv-contrib-python/3.4.15.55/
opencv_version
# 3.4.15-dev
pip3 install opencv-contrib-python==3.4.15.55
# opencv_contrib_python-4.5.3.56
# pip3 install opencv-contrib-python==4.5.3.56

# Modify requirements.txt
sed -i -e "s/numpy$/numpy==1.19.5/g" requirements.txt
sed -i -e "s/matplotlib$/matplotlib==2.2.5/g" requirements.txt
sed -i -e "s/six$/six==1.16.0/g" requirements.txt
sed -i -e "s/opencv-contrib-python$/opencv-contrib-python==3.4.15.55/g" requirements.txt

pip3 install -r requirements.txt

# Delete and Clean Bazel Cache
# Cleaning build outputs
# https://docs.bazel.build/versions/main/user-manual.html
bazel clean --expunge_async

# fix
# third_party/BUILD
        "WITH_OPENEXR": "OFF",
        "WITH_IPP": "OFF",
        "ENABLE_NEON": "OFF",
        "WITH_TENGINE": "OFF",

sed -i -e 's/# Optimization flags/"WITH_OPENEXR": "OFF",\
        "WITH_IPP": "OFF",\
        "ENABLE_NEON": "OFF",\
        "WITH_TENGINE": "OFF",\
        # Optimization flags/g' third_party/BUILD

# third_party/BUILD
# /usr/bin/ld.gold: error: cannot find -lIlmThread
sed -i -e "/-lImath/d" third_party/BUILD
sed -i -e "/-lIlmImf/d" third_party/BUILD
sed -i -e "/-lIex/d" third_party/BUILD
sed -i -e "/-lHalf/d" third_party/BUILD
sed -i -e "/-lIlmThread/d" third_party/BUILD

# mediapipe/framework/tool/BUILD
 93 cc_binary(
 94     name = "encode_as_c_string",
 95     srcs = ["encode_as_c_string.cc"],
 96     visibility = ["//visibility:public"],
 97     deps = [
 98         "@com_google_absl//absl/strings",
 99     ],
100 +    linkopts = ["-lm"],
100 )

sed -i -e 's/name = "encode_as_c_string",/linkopts = ["-lm"],\
    name = "encode_as_c_string",/g' mediapipe/framework/tool/BUILD

# Generate and install MediaPipe package.
python3 setup.py gen_protos

# error: invalid command 'bdist_wheel'
pip3 install wheel

time python3 setup.py bdist_wheel
# removing build/bdist.linux-aarch64/wheel

# Jetson Xavier NX
# real    67m6.204s
# user    0m7.176s
# sys     0m2.152s

# Jetson Nano 4GB
# real    80m1.382s
# user    0m8.940s
# sys     0m2.188s

ls -l dist
# -rw-rw-r-- 1 jetson jetson 32107596 Aug 11 05:36 mediapipe-0.8-cp36-cp36m-linux_aarch64.whl
# -rw-rw-r-- 1 jetson jetson 32107624 Aug 12 03:52 mediapipe-0.8-cp36-cp36m-linux_aarch64.whl

python3 -c "import mediapipe as mp; print(mp.__path__);"
# ['/home/jetson/mediapipe/mediapipe']

# Exit Python virtualenv
deactivate

● Install MediaPipe v0.8.6 Python package from whl package file
# Install MediaPipe Python package

# opencv-contrib-python
# https://pypi.org/project/opencv-contrib-python/3.4.15.55/
opencv_version
# 3.4.15-dev
pip3 install opencv-contrib-python==3.4.15.55

# Install MediaPipe Python package
pip3 install ./mediapipe/dist/mediapipe-0.8-cp36-cp36m-linux_aarch64.whl
# Successfully installed absl-py-0.13.0 attrs-21.2.0 mediapipe-0.8 numpy-1.19.5 protobuf-3.17.3

● Building MediaPipe Python Package
cd
cd mediapipe
python3 -m venv mp_env && source mp_env/bin/activate
$ pip3 list
Package               Version
--------------------- ---------
absl-py               0.13.0
attrs                 21.2.0
cycler                0.10.0
Cython                0.29.24
distro                1.6.0
kiwisolver            1.3.1
matplotlib            2.2.5
numpy                 1.19.5
opencv-contrib-python 3.4.15.55
packaging             21.0
pip                   21.2.3
pkg_resources         0.0.0
protobuf              3.17.3
pyparsing             2.4.7
python-dateutil       2.8.2
pytz                  2021.1
scikit-build          0.12.0
setuptools            39.0.1
six                   1.16.0
wheel                 0.37.0


● MediaPipe Build CUDA GPU Support

MediaPipe Build CUDA GPU Support

https://github.com/google/mediapipe/blob/master/docs/getting_started/gpu_support.md

It’s recommended to verify the installation of CUPTI, CUDA, CuDNN, and NVCC:

ls /usr/local/cuda/*/*/*/* | grep libcupti.so
/usr/local/cuda/targets/aarch64-linux/lib/libcupti.so
/usr/local/cuda/targets/aarch64-linux/lib/libcupti.so.10.2
/usr/local/cuda/targets/aarch64-linux/lib/libcupti.so.10.2.175

ls /usr/local/cuda-10.2
ls /usr/local/cuda-10
ls /usr/local/cuda-10/lib64

nvcc -V
# nvcc: NVIDIA (R) Cuda compiler driver
# Copyright (c) 2005-2021 NVIDIA Corporation
# Built on Sun_Feb_28_22:34:44_PST_2021
# Cuda compilation tools, release 10.2, V10.2.300
# Build cuda_10.2_r440.TC440_70.29663091_0

which nvcc
# /usr/local/cuda/bin/nvcc

ls /usr/lib/aarch64-linux-gnu/  | grep libcudnn.so
# libcudnn.so
# libcudnn.so.8
# libcudnn.so.8.2.1
export TF_CUDA_PATHS=/usr/local/cuda-10,/usr/lib/aarch64-linux-gnu,/usr/include

echo $LD_LIBRARY_PATH
# /usr/local/cuda/lib64:

export LD_LIBRARY_PATH=/usr/local/cuda/targets/aarch64-linux/lib,/usr/local/cuda-10/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
echo $LD_LIBRARY_PATH

sudo ldconfig


● NVIDIA JetPack 4.6 PR Production Release

2021/08 JetPack 4.6 PR Production Release

 NVIDIA JetPack 4.6は 2021年のリリースなのに、未だに cmakeが 3.10.2の超古いバージョンで悲しい。
# NVIDIA JetPack 4.6 PR Production Release

$ uname -a
Linux ubuntu 4.9.253-tegra #1 SMP PREEMPT Mon Jul 26 12:19:28 PDT 2021 aarch64 aarch64 aarch64 GNU/Linux

$ cat /etc/nv_tegra_release
# R32 (release), REVISION: 6.1, GCID: 27863751, BOARD: t186ref, EABI: aarch64, DATE: Mon Jul 26 19:36:31 UTC 2021

# cmake version 3.10.2
 未だに cmakeが 3.10.2の超古いバージョン
$ cmake --version
cmake version 3.10.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

# OpenCV 4.1.1
$ opencv_version
4.1.1


● MediaPipe Build Error

MediaPipe Troubleshooting

MediaPipe Troubleshooting

Mediapipe build error #1733
INFO: Found 1 target...
ERROR: /home/jetson/mediapipe/mediapipe/calculators/tensor/BUILD:601:11: C++ compilation of rule '//mediapipe/calculators/tensor:image_to_tensor_converter_opencv' failed (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 60 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 60 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
mediapipe/calculators/tensor/image_to_tensor_converter_opencv.cc: In member function 'virtual absl::lts_2020_09_23::StatusOr mediapipe::{anonymous}::OpenCvProcessor::Convert(const mediapipe::Image&, const mediapipe::RotatedRect&, const mediapipe::Size&, float, float)':
mediapipe/calculators/tensor/image_to_tensor_converter_opencv.cc:106:12: error: could not convert 'tensor' from 'mediapipe::Tensor' to 'absl::lts_2020_09_23::StatusOr<mediapipe::Tensor>'
     return tensor;
            ^~~~~~
Target //mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 242.559s, Critical Path: 201.21s
INFO: 720 processes: 129 internal, 591 linux-sandbox.
FAILED: Build did NOT complete successfully

$ gcc --version
gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Update gcc to version 8

ERROR: /home/jetson/.cache/bazel/_bazel_jetson/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/external/zlib/BUILD.bazel:5:11: undeclared inclusion(s) in rule '@zlib//:zlib':
this rule is missing dependency declarations for the following files included by 'zlib/uncompr.c':
  '/usr/lib/gcc/aarch64-linux-gnu/8/include/stddef.h'
  '/usr/lib/gcc/aarch64-linux-gnu/8/include-fixed/limits.h'
  '/usr/lib/gcc/aarch64-linux-gnu/8/include-fixed/syslimits.h'
  '/usr/lib/gcc/aarch64-linux-gnu/8/include/stdarg.h'
Target //mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 12.074s, Critical Path: 0.61s
INFO: 190 processes: 189 internal, 1 linux-sandbox.
FAILED: Build did NOT complete successfully

rm -rf ~/.cache/bazel/_bazel_jetson/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

INFO: Found 1 target...
ERROR: /home/jetson/.cache/bazel/_bazel_jetson/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/BUILD:239:11: C++ compilation of rule '@org_tensorflow//tensorflow/lite/delegates/gpu/gl:gl_errors' failed (Exit 1): gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 25 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE -fstack-protector -Wall -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer -g0 -O2 '-D_FORTIFY_SOURCE=1' -DNDEBUG -ffunction-sections ... (remaining 25 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
In file included from /usr/include/EGL/eglplatform.h:134,
                 from /usr/include/EGL/egl.h:39,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/portable_egl.h:19,
                 from external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_errors.cc:23:
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_errors.cc:61:7: error: expected unqualified-id before 'int'
 absl::Status GetOpenGlErrors() {
       ^~~~~~
external/org_tensorflow/tensorflow/lite/delegates/gpu/gl/gl_errors.cc:77:7: error: expected unqualified-id before 'int'
 absl::Status GetEglError() {
       ^~~~~~
Target //mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 587.404s, Critical Path: 531.52s
INFO: 803 processes: 267 internal, 536 linux-sandbox.
FAILED: Build did NOT complete successfully

FAIL: protobuf-test
PASS: protobuf-lazy-descriptor-test
PASS: protobuf-lite-test
PASS: google/protobuf/compiler/zip_output_unittest.sh
PASS: google/protobuf/io/gzip_stream_unittest.sh
PASS: protobuf-lite-arena-test
PASS: no-warning-test
============================================================================
Testsuite summary for Protocol Buffers 3.17.3
============================================================================
# TOTAL: 7
# PASS:  6
# SKIP:  0
# XFAIL: 0
# FAIL:  1
# XPASS: 0
# ERROR: 0
============================================================================
See src/test-suite.log
Please report to protobuf@googlegroups.com
============================================================================
Makefile:8013: recipe for target 'test-suite.log' failed
make[3]: *** [test-suite.log] Error 1
make[3]: Leaving directory '/home/jetson/protobuf-3.17.3/src'
Makefile:8119: recipe for target 'check-TESTS' failed
make[2]: *** [check-TESTS] Error 2
make[2]: Leaving directory '/home/jetson/protobuf-3.17.3/src'
Makefile:8237: recipe for target 'check-am' failed
make[1]: *** [check-am] Error 2
make[1]: Leaving directory '/home/jetson/protobuf-3.17.3/src'
Makefile:1909: recipe for target 'check-recursive' failed
make: *** [check-recursive] Error 1

INFO: Found 1 target...
ERROR: /home/jetson/mediapipe/mediapipe/python/BUILD:19:17: Linking of rule '//mediapipe/python:_framework_bindings.so' failed (Exit 1): gcc failed: error executing command /usr/bin/gcc @bazel-out/aarch64-opt/bin/mediapipe/python/_framework_bindings.so-2.params

Use --sandbox_debug to see verbose messages from the sandbox gcc failed: error executing command /usr/bin/gcc @bazel-out/aarch64-opt/bin/mediapipe/python/_framework_bindings.so-2.params

Use --sandbox_debug to see verbose messages from the sandbox
/usr/bin/ld.gold: error: cannot find -lImath
/usr/bin/ld.gold: error: cannot find -lIlmImf
/usr/bin/ld.gold: error: cannot find -lIex
/usr/bin/ld.gold: error: cannot find -lHalf
/usr/bin/ld.gold: error: cannot find -lIlmThread
/usr/bin/ld.gold: error: cannot find -lavresample
collect2: error: ld returned 1 exit status
Target //mediapipe/python:_framework_bindings.so failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 95.496s, Critical Path: 89.92s
INFO: 32 processes: 10 internal, 22 linux-sandbox.
FAILED: Build did NOT complete successfully
error: command 'bazel' failed with exit status 1

Solution
third_party/BUILD
         "WITH_PNG": "ON",
         "WITH_TIFF": "ON",
         "WITH_WEBP": "OFF",
+        "WITH_OPENEXR": "OFF",
+        "WITH_IPP": "OFF",
         # Optimization flags
         "CV_ENABLE_INTRINSICS": "ON",
         "WITH_EIGEN": "ON",

# opencv/3rdparty/openexr/
https://github.com/opencv/opencv/tree/master/3rdparty/openexr


# OPENCV_SHARED_LIBS = True
sed -i -e "/-lImath/d" third_party/BUILD
sed -i -e "/-lIlmImf/d" third_party/BUILD
sed -i -e "/-lIex/d" third_party/BUILD
sed -i -e "/-lHalf/d" third_party/BUILD
sed -i -e "/-lIlmThread/d" third_party/BUILD

Pose detection in python with CUDA support #2041

mediapipe/framework/tool/BUILD
107  cc_binary(
108      name = "encode_as_c_string",
109      srcs = ["encode_as_c_string.cc"],
110      visibility = ["//visibility:public"],
111      deps = [
112          "@com_google_absl//absl/strings",
113      ],
114 +    linkopts = ["-lm"],
115  )
/usr/bin/ld.gold: error: cannot find -lavresample

Solution
sudo apt install libavresample-dev

ImportError: /usr/local/lib/python3.6/dist-packages/mediapipe/python/_framework_bindings.cpython-36m-aarch64-linux-gnu.so: undefined symbol: _ZN12carotene_o4t7rgb2hsvERKNS_6Size2DEPKhlPhli

https://github.com/google/mediapipe/issues/1437

third_party/BUILD
+   "ENABLE_NEON": "OFF",
+   "WITH_TENGINE": "OFF",

 Pythonの pipとか nodejsの npmとかのパッケージマネージャ、環境のバージョンやモジュール間のバージョンの整合性を自動解決しない、全然マネージしてくれない役立たずの馬鹿アプリ。

 お馬鹿な例)
 Python 3.6の環境に Python 3.7以降対応のパッケージのバージョンをインストールしようとしてエラーで落ちるな!馬鹿!
 Python 3.6に対応のバージョンに溯ってインストールしろ!

 ビルドエラーばっかりで死ねる。。。
 ビルド環境くらい書いておいてくれ。環境のバージョンを合わせる位は努力するから。


● NVIDIA Jetson Nano、Xavier NXで Vino VNC リモートデスクトップ環境の有効化

2020/06/28
Jetson Nano、Xavier NXに Vino VNC Remote接続をして、Jetsonには何も画面を繋がないで GUIアプリを動かす!
Jetson Nano、Xavier NXに Vino VNC Remote接続をして、Jetsonには何も画面を繋がないで GUIアプリを動かす!

  NVIDIA Jetsonを完全 HEADLESS MODEで VNC接続でリモート デスクトップ接続をして GUI環境で使う、VNCサーバを自動起動する方法


● 【2021年】NVIDIA Jetsonの Ubuntsuデスクトップのスクリーンセーバーを無効にする方法

2021/02/27
【2021年】NVIDIA Jetsonの Ubuntsuデスクトップのスクリーンセーバーを無効にする方法
【2021年】NVIDIA Jetsonの Ubuntsuデスクトップのスクリーンセーバーを無効にする方法

  Jetsonの Ubuntsu GONOME Desktopの Screen Saverを無効にする方法



Tags: [Raspberry Pi], [電子工作], [ディープラーニング]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト
【2020年版】NVIDIA Jetson Nano、Jetson Xavier NXの便利スクリプト

  Jetsonの面倒な初期設定やミドルウェアのインストールを bashスクリプトの実行だけで簡単にできます

NVIDIA Jetsonで Tokyo2020オリンピック風のピクトグラムを表示を動かす方法
NVIDIA Jetsonで Tokyo2020オリンピック風のピクトグラムを表示を動かす方法

  Jetsonに MediaPipeをインストールして Tokyo2020-Pictogram-using-MediaPipeを動かす

NVIDIA Jetsonで 東京五輪のピクトグラムさんになれるゲーム Pictogram Challengeを動かす方法
NVIDIA Jetsonで 東京五輪のピクトグラムさんになれるゲーム Pictogram Challengeを動かす方法

  Jetsonの MediaPipeで Pictogram-sanで東京オリンピックのピクトグラムの連続パフォーマンスをキメる!

Jetson Nano、Xavier NXに Vino VNC Remote接続をして、Jetsonには何も画面を繋がないで GUIアプリを動かす!
Jetson Nano、Xavier NXに Vino VNC Remote接続をして、Jetsonには何も画面を繋がないで GUIアプリを動かす!

  NVIDIA Jetsonを完全 HEADLESS MODEで VNC接続でリモート デスクトップ接続をして GUI環境で使う、VNCサーバを自動起動する方法

【2021年】NVIDIA Jetsonの Ubuntsuデスクトップのスクリーンセーバーを無効にする方法
【2021年】NVIDIA Jetsonの Ubuntsuデスクトップのスクリーンセーバーを無効にする方法

  Jetsonの Ubuntsu GONOME Desktopの Screen Saverを無効にする方法

【2020年】Jetson Xavier NX 開発者キットが安かったので衝動買いした件、標準販売価格5万円が4万4千円!
【2020年】Jetson Xavier NX 開発者キットが安かったので衝動買いした件、標準販売価格5万円が4万4千円!

  【ザビエル元年】Jetson Xavier NX 開発者キットを最安値で購入で、しかも国内在庫で注文から翌日で到着、ザビエル開封レビュー

NVIDIA Jetson Nano 開発者キットを買ってみた。メモリ容量 4GB LPDDR4 RAM
NVIDIA Jetson Nano 開発者キットを買ってみた。メモリ容量 4GB LPDDR4 RAM

  Jetson Nanoで TensorFlow PyTorch Caffe/Caffe2 Keras MXNet等を GPUパワーで超高速で動かす!

【2021年】NVIDIA Jetsonで NumPyモジュールのバグで苦戦!
【2021年】NVIDIA Jetsonで NumPyモジュールのバグで苦戦!

  NumPyモジュールの最近の一部のバージョンには相性問題(不具合?)で地雷バージョンが有ります

【メモリ8GB】Raspberry Pi 4 Model B 8GBを KSYで最安値で購入。ベンチマークレビュー
【メモリ8GB】Raspberry Pi 4 Model B 8GBを KSYで最安値で購入。ベンチマークレビュー

  【技適取得】ラズパイ4B 8GBモデルを入手。従来の Pi3、Pi3B+と速度比較

【Vulkan】Raspberry Pi 4 Model Bで Vulkanドライバをビルドして 3Dグラフィックのデモを動かす
【Vulkan】Raspberry Pi 4 Model Bで Vulkanドライバをビルドして 3Dグラフィックのデモを動かす

  【v3dv】ラズパイ4Bで Vulkan APIを動かす、VK_ICD_FILENAMES broadcom_icd.armv7l.json

PIP機能付きの 4K対応の 4入力 1出力の HDMIセレクターを買ってみた、HDMI機器が複数有る場合に便利
PIP機能付きの 4K対応の 4入力 1出力の HDMIセレクターを買ってみた、HDMI機器が複数有る場合に便利

  ピクチャ イン ピクチャ機能付き 4K入力対応の 4入力 1出力 HDMI切り換え機 HDSFX0401P

EDID保持機能付きの 4K対応の 4入力 2出力の マトリックス切り替え HDMIセレクター、液晶画面 2台と使用で最強
EDID保持機能付きの 4K対応の 4入力 2出力の マトリックス切り替え HDMIセレクター、液晶画面 2台と使用で最強

  TESmart HMA0402A30 マトリックス切り替えで液晶画面 2台に接続できて更に EDID保持の便利機能付き HDMI切り換え機

機械学習用に画像検索の結果一覧のサムネイル画像を JavaScriptで全自動で一括で取得する方法
機械学習用に画像検索の結果一覧のサムネイル画像を JavaScriptで全自動で一括で取得する方法

  画像検索結果一括ダウンローダ、JavaScript言語を使って、ブラウザの開発者モードのコンソールで動かします、ググれ勝つ




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2021 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/raspberry_pi/nvidia_jetson_build_mediapipe_python_package/