LoginSignup
8
14

More than 3 years have passed since last update.

Windows10 on CPU でOpenVINO™ toolkitを用いた人検出

Last updated at Posted at 2019-09-19

はじめに

お高いGPUがおうちに無くとも、CPUで高速にDeep Learningが扱える
OpenVINO™ toolkitで人を検出してみた記事です。
本記事では、公開されているモデルを利用し、動作するところまでを確認します。

インストール手順は下記サイトに則り、記載しています。
https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_windows.html#set-the-environment-variables

開発環境

【機器】
 Surface Pro(5th Gen) モデル 1796 i5
・OS : Windows 10 Pro Ver.1903 64bit
・CPU : Intel® Core™ i5-7300U @2.60GHz
・MEM : 8GB

【ソフトウェア】
・Microsoft Visual Studio 2019 with C++ (インストール済みの状態から始めました)
・OpenVINO™ toolkit:Ver.2019 R2.0.1
・Python:Ver.3.6
・CMake:Ver.3.15
※必要条件
 https://software.intel.com/en-us/openvino-toolkit/documentation/system-requirements

OpenVINO™ toolkitのインストール

1.ダウンロードページの「Register & Download」で、登録&ダウンロード
  https://software.intel.com/en-us/openvino-toolkit/choose-download/free-download-windows
キャプチャ.PNG

2.必要事項を記入して、「Submit」で登録
キャプチャ2.PNG
※私はCompanyをhomeにしました。

3.「Full Package」を選択し、インストーラをダウンロード
キャプチャ3.PNG

4.ダウンロードした「w_openvino_toolkit_p_2019.2.275.exe」を実行

5.解凍先を指定して、「Extract」

6.特に変更せずに、このまま「Next」
キャプチャ4.PNG
※約1GBぐらい領域が必要なようです。

7.Informationを読んで「Next」

8.環境に不足があれば、注意書きが表示されます。
  あとで環境を導入しましょう。今は、「Next」をクリック
 ※最初、私は以下の注意文が表示されました。
キャプチャ5.PNG

9.「Finish」で完了です

10.インストールが完了すると、環境変数設定に関するページがブラウザで開きます。

Python 3.*のインストール

1.「Windows x86-64 executable installer」でインストーラをダウンロード
  https://www.python.org/downloads/release/python-365/

2.「python-3.6.5-amd64.exe」を実行

3.「Add Python 3.6 to PATH」にチェックを入れ、
  「Install Now」をクリック
キャプチャ6.PNG

4.「Close」で完了

CMakeのインストール

1.下記サイトより、「cmake-3.15.3-win64-x64.msi」をダウンロード
  https://cmake.org/download/
 ※ バージョンは3.4以上が要件です。
 ※ Microsoft Visual Studio 2019を利用する場合、
   CMakeのバージョンは3.14をインストールする必要がある模様です。
 
2.「cmake-3.15.3-win64-x64.msi」を実行し、表示に従って進める

3.PATHの設定では「Add CMake to the system PATH for all users」を選択し、「Next」
キャプチャ7.PNG

4.あとは表示に従って進めるだけ

環境変数の設定

1.「OpenVINO™ toolkitのインストール」の最後に開いたページに従い、
   コマンドプロンプトを起動

2.下記コマンドを実行し、OpenVINOのインストール先に移動

cd C:\Program Files (x86)\IntelSWTools\openvino\bin\

3.下記コマンドで環境変数に関する設定を実行

setupvars.bat

※ 最初、Python 3.*系をインストールしていなかったので、怒られました。

Unsupported Python version. Please install Python 3.5 or 3.6 (64-bit) from https://www.python.org/downloads/

Model Optimizerのインストール

OpenVINO™ toolkitでは以下のDeep Leariningフレームワークに対応しており、
今回はすべてのフレームワークに対応するModel Optimizerをインストールします。

Caffe*, TensorFlow*, MXNet*, Kaldi*, ONNX*

コマンドプロンプトで下記コマンドを実行してください。

cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\model_optimizer\install_prerequisites
install_prerequisites.bat

※インストール中、下記エラーが発生してしましましたが、
 再度「install_prerequisites.bat」を実行することで、エラー無く完了しました。

Running setup.py install for wrapt ... error

インストールが完了すると、下記注意文が表示されてました。
このままだと、遅いという意味か・・・

Warning: please expect that Model Optimizer conversion might be slow.
You can boost conversion speed by installing protobuf-*.egg located in the
"model-optimizer\install_prerequisites" folder or building protobuf library from sources.
For more information please refer to Model Optimizer FAQ, question #80.

インストール検証

インストールが正常に実施されたか確認するために、デモを実行します。
本デモでは、以下3種のネットワークが実行されている模様です。
・ナンバープレート検知
・車両特徴識別
・ナンバープレート認識

コマンドプロンプトで下記を実行し、デモフォルダに移動します。

cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\demo\

下記を実行すると、しばらく処理が進みます。
2分ほどで、結果が表示されると成功です。

demo_security_barrier_camera.bat

・結果
キャプチャ8.PNG

※CPU内蔵のGPUを利用することで、多少早くなるようです。
 オプションに「-d GPU」を追加すれば、GPU実行が可能です。

demo_security_barrier_camera.bat -d GPU

キャプチャ9.PNG

デモ

それでは、人を検知します。
画像は以下を利用します。
0000000001.jpg
Jörg MöllerによるPixabayからの画像

この画像を下記フォルダに「0000000001.jpg」という名前で保存します。

C:\Program Files (x86)\IntelSWTools\openvino_2019.2.275\deployment_tools\demo

また、同じフォルダに下記のバッチファイルを「demo_human_detection.bat」という名前で保存します。
※下記、バッチファイルの
 set target_image_path=%ROOT_DIR%0000000001.jpg
 の行を変更すると、処理する画像を指定することができます。

demo_human_detection.bat
@echo off
setlocal enabledelayedexpansion

set TARGET=CPU
set SAMPLE_OPTIONS=-delay 0
set BUILD_FOLDER=%USERPROFILE%\Documents\Intel\OpenVINO

:: command line arguments parsing
:input_arguments_loop
if not "%1"=="" (
    if "%1"=="-d" (
        set TARGET=%2
        echo target = !TARGET!
        shift
    )
    if "%1"=="-sample-options" (
        set SAMPLE_OPTIONS=%2 %3 %4 %5 %6
        echo sample_options = !SAMPLE_OPTIONS!
        shift
    )
    if "%1"=="-help" (
        echo %~n0%~x0 is security barrier camera demo that showcases three models coming with the product
        echo.
        echo Options:
        echo -d name     Specify the target device to infer on; CPU, GPU, FPGA, HDDL or MYRIAD are acceptable. Sample will look for a suitable plugin for device specified
        exit /b
    )
    shift
    goto :input_arguments_loop
)

set ROOT_DIR=%~dp0

set target_image_path=%ROOT_DIR%0000000001.jpg


set TARGET_PRECISION=FP16


echo target_precision = !TARGET_PRECISION!

if exist "%ROOT_DIR%\..\..\bin\setupvars.bat" (
    call "%ROOT_DIR%\..\..\bin\setupvars.bat"
) else (
    echo setupvars.bat is not found, INTEL_OPENVINO_DIR can't be set
    goto error
)

echo INTEL_OPENVINO_DIR is set to %INTEL_OPENVINO_DIR%

:: Check if Python is installed
python --version 2>NUL
if errorlevel 1 (
   echo Error^: Python is not installed. Please install Python 3.5 ^(64-bit^) or higher from https://www.python.org/downloads/
   goto error
)

:: Check if Python version is equal or higher 3.4
for /F "tokens=* USEBACKQ" %%F IN (`python --version 2^>^&1`) DO (
   set version=%%F
)
echo %var%

for /F "tokens=1,2,3 delims=. " %%a in ("%version%") do (
   set Major=%%b
   set Minor=%%c
)

if "%Major%" geq "3" (
   if "%Minor%" geq "5" (
  set python_ver=okay
   )
)
if not "%python_ver%"=="okay" (
   echo Unsupported Python version. Please install Python 3.5 ^(64-bit^) or higher from https://www.python.org/downloads/
   goto error
)

:: install yaml python modules required for downloader.py
pip install --user pyyaml requests
if ERRORLEVEL 1 GOTO errorHandling


set models_path=%BUILD_FOLDER%\openvino_models\ir\%target_precision%
set models_cache=%BUILD_FOLDER%\openvino_models\ir\cache

set person_detection_model=person-detection-retail-0013
set person_reidentification_model=person-reidentification-retail-0031

set person_detection_model_path=%models_path%\Retail\object_detection\pedestrian\rmnet_ssd\0013\dldt\%target_precision%\%person_detection_model%
set person_reidentification_model_path=%models_path%\Retail\object_reidentification\pedestrian\rmnet_based\0031\dldt\%target_precision%\%person_reidentification_model%


if not exist %models_cache% (
  mkdir %models_cache%
)

echo python "%INTEL_OPENVINO_DIR%\deployment_tools\tools\model_downloader\downloader.py" --name %person_detection_model% --output_dir %models_path% --cache_dir %models_cache%
python "%INTEL_OPENVINO_DIR%\deployment_tools\tools\model_downloader\downloader.py" --name %person_detection_model% --output_dir %models_path% --cache_dir %models_cache%

echo python "%INTEL_OPENVINO_DIR%\deployment_tools\tools\model_downloader\downloader.py" --name %person_reidentification_model% --output_dir %models_path% --cache_dir %models_cache%
python "%INTEL_OPENVINO_DIR%\deployment_tools\tools\model_downloader\downloader.py" --name %person_reidentification_model% --output_dir %models_path% --cache_dir %models_cache%


echo.
echo ###############^|^| Generate VS solution for Inference Engine demos using cmake ^|^|###############
echo.
timeout 3

if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
   set "PLATFORM=x64"
) else (
   set "PLATFORM=Win32"
)

set VSWHERE="false"
if exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
   set VSWHERE="true"
   cd "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
) else if exist "%ProgramFiles%\Microsoft Visual Studio\Installer\vswhere.exe" (
      set VSWHERE="true"
      cd "%ProgramFiles%\Microsoft Visual Studio\Installer"
) else (
   echo "vswhere tool is not found"
)

set MSBUILD_BIN=
set VS_PATH=

if !VSWHERE! == "true" (
   for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
      set VS_PATH=%%i
   )
   if exist "!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=!VS_PATH!\MSBuild\14.0\Bin\MSBuild.exe"
   )
   if exist "!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=!VS_PATH!\MSBuild\15.0\Bin\MSBuild.exe"
   )
   if exist "!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=!VS_PATH!\MSBuild\Current\Bin\MSBuild.exe"
   )
)

if "!MSBUILD_BIN!" == "" (
   if exist "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
      set "MSBUILD_VERSION=14 2015"
   )
   if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe"
      set "MSBUILD_VERSION=15 2017"
   )
   if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"
      set "MSBUILD_VERSION=15 2017"
   )
   if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe" (
      set "MSBUILD_BIN=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe"
      set "MSBUILD_VERSION=15 2017"
   )
) else (
   if not "!MSBUILD_BIN:2019=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=16 2019"
   if not "!MSBUILD_BIN:2017=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=15 2017"
   if not "!MSBUILD_BIN:2015=!"=="!MSBUILD_BIN!" set "MSBUILD_VERSION=14 2015"
)

if "!MSBUILD_BIN!" == "" (
   echo Build tools for Visual Studio 2015 / 2017 / 2019 cannot be found. If you use Visual Studio 2017 / 2019, please download and install build tools from https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2017
   GOTO errorHandling
)

set "SOLUTION_DIR64=%BUILD_FOLDER%\inference_engine_demos_build"

echo Creating Visual Studio !MSBUILD_VERSION! %PLATFORM% files in %SOLUTION_DIR64%... && ^
if exist "%SOLUTION_DIR64%\CMakeCache.txt" del "%SOLUTION_DIR64%\CMakeCache.txt"
cd "%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\demos" && cmake -E make_directory "%SOLUTION_DIR64%" && cd "%SOLUTION_DIR64%" && cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM% "%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\demos"
if ERRORLEVEL 1 GOTO errorHandling

timeout 7
echo.
echo ###############^|^| Build Inference Engine demos using MS Visual Studio (MSBuild.exe) ^|^|###############
echo.
timeout 3
echo "!MSBUILD_BIN!" Demos.sln /p:Configuration=Release /t:pedestrian_tracker_demo /clp:ErrorsOnly /m
"!MSBUILD_BIN!" Demos.sln /p:Configuration=Release /t:pedestrian_tracker_demo /clp:ErrorsOnly /m
if ERRORLEVEL 1 GOTO errorHandling

timeout 7

:runSample
echo.
echo ###############^|^| Run Inference Engine pedestrian tracker demo ^|^|###############
echo.
timeout 3
cd "%SOLUTION_DIR64%\intel64\Release"
echo "%SOLUTION_DIR64%\intel64\Release\pedestrian_tracker_demo.exe" -i "%target_image_path%" -m_det "%person_detection_model_path%.xml" -m_reid "%person_reidentification_model_path%.xml" -d_det !TARGET! -d_reid !TARGET! !SAMPLE_OPTIONS!
pedestrian_tracker_demo.exe -i "%target_image_path%" ^
                                 -m_det "%person_detection_model_path%.xml" ^
                                 -m_reid "%person_reidentification_model_path%.xml" ^
                                 -d_det !TARGET! -d_reid !TARGET! !SAMPLE_OPTIONS!
if ERRORLEVEL 1 GOTO errorHandling

echo.
echo ###############^|^| Demo completed successfully ^|^|###############
cd "%ROOT_DIR%"

goto :eof

:errorHandling
echo Error
cd "%ROOT_DIR%"

あとは、下記コマンドで実行すると、結果が表示されます。

cd C:\Program Files (x86)\IntelSWTools\openvino\deployment_tools\demo
demo_human_detection.bat

・結果
キャプチャ10.PNG

終わりに

学習はできませんが推論のみであれば、
タブレットPCでもOpenVINO™ toolkitを利用すれば、
十分利用できることが分かりました。

人の検知枠もなかなかに綺麗で素晴らしいです。

今後、もう少し他のサンプルも試してみたいところです。

備考

・今回利用した人検知モデル 
https://docs.openvinotoolkit.org/2018_R5/_docs_Retail_object_detection_pedestrian_rmnet_ssd_0013_caffe_desc_person_detection_retail_0013.html

8
14
0

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
8
14