OpenVino 的 Inference Engine Samples 放在
<INSTALL_DIR>/deployment_tools/inference_engine/samples 底下
以我的為例子
我的Inference Engine Samples 在
C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\
deployment_tools\inference_engine\samples 底下
samples資料夾底下有三種型別
●Samples & tools是簡單的應用程式,用來闡述Inference Engine API怎麼用的
●Demos較複雜,內容是用IE API解決特定的use-cases
Sample / Demo 我各挑一個來玩
■Hello Shape Infer C++ Sample
這個Sample會去偵測input圖片裡面的object
並用矩形框起來
這個例子是在教怎麼使用 Shape Inference
所吃的圖片input要是BGR channel
若是RBG圖片 要使用 --reverse_input_channels來轉成RBG channel
詳情請見Converting a Model Using General Conversion Parameters
以下步驟我是根據官方demo batch的邏輯建立的
(demo_squeezenet_download_convert_run.bat)
步驟1: 先搞到一個public 或pre-trained的model
可以用OpenVINO Model Downloader 或
https://download.01.org/opencv/ 去下載pre-trained model
我用Model Downloader 來下一個ssd300好了 ,cmd指令如下
★python "%INTEL_OPENVINO_DIR%\deployment_tools\tools\
model_downloader\downloader.py"
--name ssd300
--output_dir
C:\Users\$(username)\Documents\Intel\OpenVINO\openvino_models\models\FP32
output_dir我選擇放在FP32是因為我設的TARGET是CPU
若TARGET我設MYRIAD就會放在FP16
執行後出現Error
###############|| Downloading topologies ||###############
========= Downloading C:\Users\xxxxx\Documents\Intel\OpenVINO\
openvino_models\models\FP32\object_detection\common\ssd\300\caffe\ssd300.tar.gz
Error Connecting: HTTPSConnectionPool(host='docs.google.com', port=443):
Max retries exceeded with url: /uc?export=download&id=0BzKzrI_SkD1_TkFPTEQ1Z091SUE (
Caused by ProxyError('Cannot connect to proxy.',
NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x000001EE51A88080>:
Failed to establish a new connection: [Errno 11001] getaddrinfo failed',)))
這是因為我連公司網路的緣故
後來連手機熱點+把Lan設定改成auto就解決了
步驟2: 安裝Model Optimizer prerequisites
cmd指令如下
★cd C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\deployment_tools\model_optimizer\install_prerequisites
★call install_prerequisites_caffe.bat
註: 在install_prerequisites底下有這些batch,視你所要轉換的model是從哪個framework產出的來做使用
步驟3: 把model轉成IR
●我在C:\Users\xxxx\Documents\Intel\OpenVINO\openvino_models\ir\FP32
新增 object_detection\ssd\300\caffe 路徑放IR
●將 C:\Users\xxx\Documents\Intel\OpenVINO\openvino_models\models\FP32\
object_detection\ssd\300\caffe\models\VGGNet\VOC0712Plus\SSD_300x300_ft\deploy.prototxt
rename成 VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.prototxt
cmd指令如下
★ cd C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\
deployment_tools\model_optimizer
★python mo.py --input_model C:\Users\xxx\Documents\Intel\OpenVINO\openvino_models\models\FP32\
object_detection\ssd\300\caffe\models\VGGNet\VOC0712Plus\SSD_300x300_ft\
VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.caffemodel
--output_dir
C:\Users\xxx\Documents\Intel\OpenVINO\openvino_models\ir\
FP32\object_detection\ssd\300\caffe
--data_type FP32
註: IR路徑名意義
%BUILD_FOLDER%\openvino_models\ir\%target_precision%\
%model_type%\%model_name%\%model_version%\%model_framework%
步驟4: Generate VS solution for Inference Engine samples using cmake
demo_squeezenet_download_convert_run.bat裡面的指令是
cd "%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\samples"
&& cmake -E make_directory "%SOLUTION_DIR64%"
&& cd "%SOLUTION_DIR64%"
&& cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM%
"%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\samples"
因為我之前跑過demo_squeezenet_download_convert_run.bat
%SOLUTION_DIR64%資料夾已經建立了
所以將上面的指令改寫成
cd "%SOLUTION_DIR64%"
&& cmake -G "Visual Studio !MSBUILD_VERSION!" -A %PLATFORM%
"%INTEL_OPENVINO_DIR%\deployment_tools\inference_engine\samples"
cmd指令如下
★cd "C:\Users\xxxx\Documents\Intel\OpenVINO\inference_engine_samples_build"
&& cmake -G "Visual Studio 15 2017" -A x64 "C:\Program Files (x86)\
IntelSWTools\openvino\deployment_tools\inference_engine\samples"
步驟5: Build Inference Engine
cmd指令如下
★"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\
MSBuild\15.0\Bin\MSBuild.exe"
Samples.sln
/p:Configuration=Release /t:hello_shape_infer_ssd /clp:ErrorsOnly /m
步驟6: Do inference on CPU on an image using a trained SSD network
★cd C:\Users\xxxx\Documents\Intel\OpenVINO\
inference_engine_samples_build\intel64\Release
★hello_shape_infer_ssd
"C:\Users\xxx\Documents\Intel\OpenVINO\openvino_models\ir
\FP32\object_detection\ssd\300\caffe\
VGG_VOC0712Plus_SSD_300x300_ft_iter_160000.xml"
"C:\test.bmp" CPU 3
ps:請自己找一個bmp檔rename成test.bmp 有些圖片可能無法判斷出object
找街道有行人的照片應該比較沒問題
上面的指令執行後出現找不到opencv_world410.dll / inference_engine.dll/tbb.dll的error
google一下發現是少執行了下面的設定環境變數的cmd指令
★ call "C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\bin\setupvars.bat"
步驟7:產出結果
指令執行完畢會看到如下msg
The resulting image was saved in the file: hello_shape_infer_ssd_output.jpg
我網路上隨便抓一張圖的執行結果
可以看出行人這個object被detect到並框出
--------------------------------------------------
■其它參考連結
- ImageNet
22k categories and 14M images