OpenVINO入門筆記

一、簡介

官方原文:https://software.intel.com/zh-cn/openvino-toolkit/

使用英特爾®分佈式OpenVINO™工具包開發模擬人類視覺的應用程序和解決方案。該工具包基於卷積神經網絡(CNN),可擴展英特爾®硬件(包括加速器)的工作負載,並最大限度地提高性能。

  • 在邊緣啓用基於CNN的深度學習推理
  • 支持跨計算機視覺加速器的異構執行 - CPU,GPU,英特爾®Movidius™神經計算棒和FPGA - 使用通用API
  • 通過功能庫和預優化內核加快產品上市速度
  • 包括針對計算機視覺標準的優化調用,包括OpenCV *,OpenCL™和OpenVX *
    在這裏插入圖片描述

OpenVINO™工具包是一個開源產品。它包含用於英特爾®處理器(用於CPU),英特爾®處理器顯卡(用於GPU)和異構支持的深度學習部署工具包(DLDT)。它包括一個帶有預訓練模型,樣本和演示的開放模型庫。

  • OpenVINO™工具包:https://01.org/openvinotoolkit

二、開始(基於Ubuntu 16.04LTS,64位)

官方原文:https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_linux.html#introduction
我的電腦系統:

下載(Linux):https://software.intel.com/en-us/openvino-toolkit/choose-download/free-download-linux
解壓並進入目錄:

$ tar -xvzf l_openvino_toolkit_p_<version>.tgz
$ cd l_openvino_toolkit_p_2019.1.144/
# 如果您安裝了以前版本的Intel Distribution of OpenVINO工具包,請重命名或刪除這兩個目錄:
# /home/<user>/inference_engine_samples
# /home/<user>/openvino_models
$ sudo ./install_GUI.sh
# 安裝很簡單,一直下一步就行。

1.安裝外部軟件依賴項

這些依賴關係是必需的:

  • 英特爾優化的OpenCV
  • 深度學習推理引擎
  • 深度學習模型優化工具
# 切換到install_dependencies目錄:
$ cd /opt/intel/openvino/install_dependencies/
# 運行腳本以下載並安裝外部軟件依賴項:
$ sudo -E ./install_openvino_dependencies.sh

2.設置環境變量

# 在編譯和運行OpenVINO™應用程序之前,必須更新多個環境變量。運行以下腳本以臨時設置環境變量:
$ source /opt/intel/openvino/bin/setupvars.sh
# 通過以下方式來永久生效:
$ gedit ~/.bashrc
# 在文件最後一行添加:
source /opt/intel/openvino/bin/setupvars.sh
# 保存並關閉文件

3.配置模型優化工具

Model Optimizer是一個基於Python *的命令行工具,用於從流行的深度學習框架(如Caffe *,TensorFlow *,Apache MXNet *,ONNX *和Kaldi *)導入經過訓練的模型。

Model Optimizer是OpenLinkO工具包的Intel Distribution的關鍵組件。如果不通過模型優化器運行模型,則無法對訓練的模型進行推理。當您通過模型優化器運行預先訓練的模型時,您的輸出是網絡的中間表示(IR)。Intermediate Representation是一對描述整個模型的文件:

  • .xml:描述網絡拓撲
  • .bin:包含權重和偏差二進制數據

有關模型優化程序的更多信息,請參閱模型優化程序開發人員指南:https://docs.openvinotoolkit.org/latest/_docs_MO_DG_Deep_Learning_Model_Optimizer_DevGuide.html

同時配置所有支持的框架
$ cd /opt/intel/openvino/deployment_tools/model_optimizer/install_prerequisites
$ sudo ./install_prerequisites.sh
[WARNING] All Model Optimizer dependencies are installed globally.
[WARNING] If you want to keep Model Optimizer in separate sandbox
[WARNING] run install_prerequisites.sh venv {caffe|tf|mxnet|kaldi|onnx}

也可以單獨配置每個框架

#For Caffe:
#sudo ./install_prerequisites_caffe.sh
#For TensorFlow:
#sudo ./install_prerequisites_tf.sh
#For MXNet:
#sudo ./install_prerequisites_mxnet.sh
#For ONNX:
#sudo ./install_prerequisites_onnx.sh
#For Kaldi:
#sudo ./install_prerequisites_kaldi.sh

4.運行驗證腳本以驗證安裝

$ cd /opt/intel/openvino/deployment_tools/demo

# 運行圖像分類驗證腳本:
$ sudo ./demo_squeezenet_download_convert_run.sh
# 遇到一些問題:
[ ERROR ]  
Detected not satisfied dependencies:
	protobuf: installed: 3.7.1, required: 3.6.1
	test-generator: not installed, required: 0.1.1
	defusedxml: not installed, required: 0.5.0
# 解決:
$ cd /opt/intel/openvino_2019.1.144/deployment_tools/model_optimizer/install_prerequisites/
$ sudo ./install_prerequisites_caffe.sh

# 運行 Inference Pipeline 驗證腳本:
$ sudo ./demo_security_barrier_camera.sh

5.英特爾®處理器顯卡(GPU)的步驟

$ cd /opt/intel/openvino/install_dependencies/
$ sudo -E su
# 安裝使用GPU插件所需的OpenCL™驅動程序組件的英特爾®圖形計算運行時,併爲英特爾®集成顯卡編寫自定義圖層:
$ ./install_NEO_OCL_driver.sh
# 有以下輸出,我暫時沒管它,至少是成功了。
Installation completed successfully.
Next steps:
Add OpenCL users to the video group: 'sudo usermod -a -G video USERNAME'
   e.g. if the user running OpenCL host applications is foo, run: sudo usermod -a -G video foo
   Current user has been already added to the video group

If you use 8th Generation Intel® Core™ processor, you will need to add:
   i915.alpha_support=1
   to the 4.14 kernel command line, in order to enable OpenCL functionality for this platform.

6.openVINO卸載

$ cd /opt/intel/openvino/openvino_toolkit_uninstaller/
$ sudo ./uninstall_GUI.sh

7.其他

轉換你的Caffe *模型:https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_Caffe.html
轉換你的TensorFlow *模型:https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_TensorFlow.html
轉換您的MXNet *模型:https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_MxNet.html
轉換你的ONNX *模型:https://docs.openvinotoolkit.org/latest/_docs_MO_DG_prepare_model_convert_model_Convert_Model_From_ONNX.html

三、Hello World人臉檢測教程

GitHub:https://github.com/intel-iot-devkit/inference-tutorials-generic

本教程將從一個基本應用程序開始,該應用程序可以讀入圖像數據並將圖像輸出到窗口。從那裏開始,每個步驟都會添加深度學習模型,用於處理圖像數據並進行推理。在最後一步中,完整的應用程序將能夠檢測到面部,報告面部的年齡和性別,並繪製表示每個面部的頭部姿勢的3D軸。

因爲我安裝的是l_openvino_toolkit_p_2019.1.144版本,所以選擇分支版本2019 R1.0

# 源碼
$ git clone https://github.com/intel-iot-devkit/inference-tutorials-generic.git
$ cd inference-tutorials-generic
$ git checkout openvino_toolkit_2019_r1_0
# 切換到面部檢測教程文件夾:
$ cd face_detection_tutorial
# 下載模型
$ source ./scripts/get_models.sh

我先編譯並運行了step1,保證openCV沒有問題:

$ cd ~/projects/inference-tutorials-generic/face_detection_tutorial/step_1/cmake-build-debug
$ cmake ..
$ make -j12
$ ./intel64/Debug/face_detection_tutorial
# 注:源文件內需要修改 FLAGS_i 參數,修改爲自己的攝像頭網絡地址。

然後又嘗試編譯運行step2,但運行起來有問題沒能處理:

$ cd ~/projects/inference-tutorials-generic/face_detection_tutorial/step_2/cmake-build-debug
$ cmake ..
$ make -j12
$ ./intel64/Debug/face_detection_tutorial
# 注:源文件內需要修改 FLAGS_i 參數,修改爲自己的攝像頭網絡地址。
#     源文件內需要修改 FLAGS_m 參數,修改爲模型文件目錄。
#報錯:
[ ERROR ] Cannot make shared blob! The blob type cannot be used to store objects of current precision
/opt/intel/openvino_2019.1.144/deployment_tools/inference_engine/include/details/ie_exception_conversion.hpp:71
#思考:可能和依賴的某個程序有關,可能是openCV,在CMake的時候注意openCV的依賴路徑。

後來使用的是Github上找的一個openVINO的demo來試的。

發佈了26 篇原創文章 · 獲贊 13 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章