概要
こちらのサイトにRaspberry Pi と Neural Compute Stick を使ったOpenVINOでのPython APIコードのチュートリアルが書いてありますが、PCのみの環境で行う場合には少し変更や追加が必要なので、そのメモを書きます。
画像引用元:OpenVINO™ でゼロから学ぶディープラーニング推論
必要なのは以下3つの項目です
- ターゲットデバイスの変更
- FP16をFP32へ変更
- ライブラリ読込みの追加
ターゲットデバイスの変更
Neural Compute Stickを意味する MYRAID
から CPU
に変更するだけ。これは簡単。
# 変更前
plugin = IEPlugin(device="MYRIAD")
# 変更後
plugin = IEPlugin(device="CPU")
FP16をFP32へ変更
学習済みモデル(xmlファイルとbinファイル)をFP16からFP32に変更します
例えば、OpenVINO 2019_R3.1用のface-detection-retail-0004
であれば、以下のサイトのFP32からダウンロードすればOK
Intel Open Source Technology Center
ちなみに、FP16のままでも動作する場合がありますが、FP32が推奨なので変更した方が良いでしょう
画像引用元:Intel OpenVINO™ TOOLKIT公式サイト
ライブラリ読込み追加
使用する学習済みモデルにもよりますが、以下のようなエラーが発生する場合があります(顔認識など)
Traceback (most recent call last):
File "XXXXXXXX.py", line XXX, in <module>
exec_net = plugin.load(network=net)
File "ie_api.pyx", line 547, in openvino.inference_engine.ie_api.IEPlugin.load
File "ie_api.pyx", line 557, in openvino.inference_engine.ie_api.IEPlugin.load
RuntimeError: Unsupported primitive of type: PriorBoxClustered name: fc7_mbox_priorbox
対応としてCPU Extensionsライブラリ読込みの追加が必要です。
OSやCPUでパスやファイル名が異なるので、色々試してみて下さい。
Windows10(Intel Coreプロセッサ)の例
# ターゲットデバイス指定の下に追加
plugin.add_cpu_extension("C:/Program Files (x86)/IntelSWTools/openvino/deployment_tools/inference_engine/bin/intel64/Release/cpu_extension_avx2.dll")
※上記でダメな場合は cpu_extension.dll
を検索してフルパスで指定してみてください
Linux(Intel Atomプロセッサ)の例
# ターゲットデバイス指定の下に追加
plugin.add_cpu_extension('/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libcpu_extension_sse4.so')
※Intel Coreプロセッサの場合は libcpu_extension_avx2.so
に置き換えてみて下さい
Macの例
# ターゲットデバイス指定の下に追加
plugin.add_cpu_extension('/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64/libcpu_extension.dylib')
これでPCさえあれば、無料でディープラーニング推論が出来ますね! では、また。