43
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

3D PoseEstimation (Multi-Person) by OpenVINO + Corei7 CPU only [14 FPS-18 FPS]

Last updated at Posted at 2020-03-21

1.Introduction

OpenVINO を使用して 3D PoseEstimationCPU only で実行します。 プログラムも何も作らずにビルドだけ通してすぐに味見することができます。 一応、 複数人の同時検出が可能なモデルです。 全ての作業は 10分〜15分ほどで実施可能です。 注意点は、最新の OpenVINO 2020 R1 を導入しておくこと、ぐらいです。 日本国内からであれば、上のニコチャンマークの先の私のリポジトリ経由でインストーラを高速にダウンロード可能です。 ちなみに皆さんはよくご存知かと思いますが、 GPU を使用したほうが遅いです。 シングルパーソン+動画撮影なし、の条件で11FPSほどしか出ません。 GPU + FP16指定で 18FPS でした。 あまりメリットは無いですね。

2.Environment

3.Procedure

端的に言うと、トレーニング済みモデルをダウンロードして、一部の部品を自力ビルドして実行するだけ、です。

3D骨格検出モデルのダウンロード
$ cd ~
$ mkdir git && cd git
$ git clone --depth 1 https://github.com/opencv/open_model_zoo.git
$ cd open_model_zoo/tools/downloader
$ ./downloader.py --name human-pose-estimation-3d-0001
ダウンロード結果
################|| Downloading models ||################

========== Downloading ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/human-pose-estimation-3d-0001.tar.gz
... 100%, 17990 KB, 12013 KB/s, 1 seconds passed

################|| Post-processing ||################

========== Unpacking ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/human-pose-estimation-3d-0001.tar.gz

Screenshot 2020-03-21 10:44:56.png

ダウンロードされてくるモデルは Pytorch のモデル .pth ですので、 OpenVINOIRモデル へ変換します。 といってもコマンド一行ではい終わり、という感じです。 苦戦する部分は何もありません。

Pytorch_to_IRmodel
$ ./converter.py --name human-pose-estimation-3d-0001
コンバート結果
========= Converting human-pose-estimation-3d-0001 to IR (FP16)
Conversion command: /usr/bin/python3 -- /opt/intel/openvino_2020.1.023/deployment_tools/model_optimizer/mo.py --framework=onnx --data_type=FP16 --output_dir=${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP16 --model_name=human-pose-estimation-3d-0001 --input=data '--mean_values=data[128.0,128.0,128.0]' '--scale_values=data[255.0,255.0,255.0]' --output=features,heatmaps,pafs --input_model=${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/human-pose-estimation-3d-0001.onnx

Model Optimizer arguments:
Common parameters:
    - Path to the Input Model:  ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/human-pose-estimation-3d-0001.onnx
    - Path for generated IR:    ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP16
    - IR output name:   human-pose-estimation-3d-0001
    - Log level:    ERROR
    - Batch:    Not specified, inherited from the model
    - Input layers:     data
    - Output layers:    features,heatmaps,pafs
    - Input shapes:     Not specified, inherited from the model
    - Mean values:  data[128.0,128.0,128.0]
    - Scale values:     data[255.0,255.0,255.0]
    - Scale factor:     Not specified
    - Precision of IR:  FP16
    - Enable fusing:    True
    - Enable grouped convolutions fusing:   True
    - Move mean values to preprocess section:   False
    - Reverse input channels:   False
ONNX specific parameters:
Model Optimizer version:    2020.1.0-61-gd349c3ba4a

[ SUCCESS ] Generated IR version 10 model.
[ SUCCESS ] XML file: ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP16/human-pose-estimation-3d-0001.xml
[ SUCCESS ] BIN file: ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP16/human-pose-estimation-3d-0001.bin
[ SUCCESS ] Total execution time: 14.10 seconds. 
[ SUCCESS ] Memory consumed: 187 MB. 

========= Converting human-pose-estimation-3d-0001 to IR (FP32)
Conversion command: /usr/bin/python3 -- /opt/intel/openvino_2020.1.023/deployment_tools/model_optimizer/mo.py --framework=onnx --data_type=FP32 --output_dir=${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP32 --model_name=human-pose-estimation-3d-0001 --input=data '--mean_values=data[128.0,128.0,128.0]' '--scale_values=data[255.0,255.0,255.0]' --output=features,heatmaps,pafs --input_model=${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/human-pose-estimation-3d-0001.onnx

Model Optimizer arguments:
Common parameters:
    - Path to the Input Model:  ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/human-pose-estimation-3d-0001.onnx
    - Path for generated IR:    ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP32
    - IR output name:   human-pose-estimation-3d-0001
    - Log level:    ERROR
    - Batch:    Not specified, inherited from the model
    - Input layers:     data
    - Output layers:    features,heatmaps,pafs
    - Input shapes:     Not specified, inherited from the model
    - Mean values:  data[128.0,128.0,128.0]
    - Scale values:     data[255.0,255.0,255.0]
    - Scale factor:     Not specified
    - Precision of IR:  FP32
    - Enable fusing:    True
    - Enable grouped convolutions fusing:   True
    - Move mean values to preprocess section:   False
    - Reverse input channels:   False

ONNX specific parameters:
Model Optimizer version:    2020.1.0-61-gd349c3ba4a

[ SUCCESS ] Generated IR version 10 model.
[ SUCCESS ] XML file: ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP32/human-pose-estimation-3d-0001.xml
[ SUCCESS ] BIN file: ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP32/human-pose-estimation-3d-0001.bin
[ SUCCESS ] Total execution time: 14.66 seconds. 
[ SUCCESS ] Memory consumed: 188 MB. 

Screenshot 2020-03-21 10:50:23.png

Post-Process の処理部分だけは処理高速化のために C++ で設計されています。 また、OpenVINOの公式チュートリアルには何も書かれていませんが、C++の部品のみ自力でコンパイルしなければなりません。 ただ、踏むべき手順はたったの下記だけですのですぐに終わります。 Python.hNumpy のヘッダーファイルのincludeが必要ですので、 CMakeLists.txt を若干調整します。 /usr/include/python3.6m の部分はお使いのPythonのバージョンによってパスが異なる可能性がありますので、各自調整してください。

Post-Processの部品をビルド
$ cd ${HOME}/git/open_model_zoo/demos/python_demos/human_pose_estimation_3d_demo
$ export PYTHONPATH=$PYTHONPATH:${PWD}

$ nano pose_extractor/CMakeLists.txt
execute_process(
    #COMMAND "${PYTHON_EXECUTABLE}" -c "import numpy; print(numpy.get_include())"
    COMMAND python3 -c "import numpy; print(numpy.get_include())"

#target_include_directories(${target_name} PRIVATE src/ ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS})
target_include_directories(${target_name} PRIVATE src/ ${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDE_DIR} ${OpenCV_INCLUDE_DIRS} /usr/include/python3.6m)

$ sudo apt install python3-dev
$ sudo pip3 install numpy
$ mkdir -p pose_extractor/build && \
  cd pose_extractor/build && \
  cmake .. && \
  make -j8

$ cp pose_extractor.so ../.. && cd ../..

最後にサンプルプログラムを実行します。 Pythonプログラムを改造せずにそのまま実行した場合、 720p(HD, 1280x720) という高解像度で起動してしまうため動作が若干モッサリします。 低解像度で高速に動作させたい場合は自力でOpenCVのUSB Camera撮影解像度を調整してください。

3D_PoseEstimationの実行
$ python3 human_pose_estimation_3d_demo.py \
  -m ${HOME}/git/open_model_zoo/tools/downloader/public/human-pose-estimation-3d-0001/FP32/human-pose-estimation-3d-0001.xml \
  -d CPU \
  -i 0

Youtube: https://youtu.be/DgKw0Ty22PE

4.Finally

またつまらない記事を量産してしまいました。。。
記事作成時間:10分 :upside_down:

43
39
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
43
39

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?