英特尔OpenVINO工具套件高级课程实验操作记录与学习总结
英特爾OpenVINO工具套件高級課程&實驗操作記錄與學(xué)習(xí)總結(jié)
實驗機器環(huán)境部分信息:
dc2-user@10-0-255-63:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 18.04.3 LTS Release: 18.04 Codename: bionic dc2-user@10-0-255-63:~$ date Wed Feb 23 19:10:31 CST 2022 dc2-user@10-0-255-63:~$ uname -a Linux 10-0-255-63 4.15.0-167-generic #175-Ubuntu SMP Wed Jan 5 01:56:07 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux dc2-user@10-0-255-63:~$Intel? Distribution of OpenVINO? Toolkit Download:
下載地址
文章目錄
- 第一課動手實驗:如何充分使用OpenVINO?工具套件?-在線測試
- 1.人體動作姿勢識別示例
- 2.圖像著色示例
- 3.音頻檢測示例
- 4.公式識別
- 5.環(huán)境深度識別
- 6.目標(biāo)識別示例
- 7.自然語言處理示例(NLP)——自動回答問題
- 第二課動手實驗:如何構(gòu)建一個異構(gòu)系統(tǒng)——動手實驗-在線測試
- 1.上傳性能評估腳本到DevCloud
- 2.利用多硬件協(xié)同推理
- 第三課動手實驗:AI應(yīng)用中的視頻處理-在線測試
- 1.測試當(dāng)前設(shè)備的解碼密度
- 第四課動手實驗:如何進(jìn)行AI推理的性能對比-在線測試
- 1.數(shù)據(jù)精度對推理性能的影響
- 第六課動手實驗:AI應(yīng)用中的音頻處理-在線測試
- 1.聲音檢測實驗
- 2.聲音識別實驗
- 第七課動手實驗:如何實現(xiàn)DL-streamer包含的高級功能?-在線測試
- 1.使用DL-streamer進(jìn)行表情識別
- 第八課動手實驗:整合實現(xiàn)AI應(yīng)用中的音視頻處理-在線測試
- 1.視頻+音頻處理實驗
- OpenVINO高級課程結(jié)業(yè)證書
第一課動手實驗:如何充分使用OpenVINO?工具套件?-在線測試
1.人體動作姿勢識別示例
設(shè)定實驗路徑
設(shè)定OpenVINO的路徑:
export OV=/opt/intel/openvino_2021/
設(shè)定當(dāng)前實驗的路徑:
export WD=~/OV-300/01/3D_Human_pose/
注:實驗文件夾名為OV-300,位于主目錄下。本環(huán)境下,文件的上傳與下載方法,參考右上角幫助手冊。
運行初始化OpenVINO的腳本
source $OV/bin/setupvars.sh
當(dāng)你看到:[setupvars.sh] OpenVINO environment initialized 表示OpenVINO環(huán)境已經(jīng)成功初始化。
運行OpenVINO依賴腳本的安裝
進(jìn)入腳本目錄:
cd $OV/deployment_tools/model_optimizer/install_prerequisites/
安裝OpenVINO需要的依賴:
sudo ./install_prerequisites.sh
PS:此步驟為模擬開發(fā)機本地進(jìn)行OpenVINO使用的步驟,所以 之后你在本地使用OpenVINO之前需要遵循此步驟。
安裝OpenVINO模型下載器的依賴文件
進(jìn)入到模型下載器的文件夾:
cd $OV/deployment_tools/tools/model_downloader/
安裝模型下載器的依賴:
python3 -mpip install --user -r ./requirements.in
安裝下載轉(zhuǎn)換pytorch模型的依賴:
sudo python3 -mpip install --user -r ./requirements-pytorch.in
安裝下載轉(zhuǎn)換caffe2模型的依賴:
sudo python3 -mpip install --user -r ./requirements-caffe2.in
PS:此步驟為模擬開發(fā)機本地進(jìn)行OpenVINO使用的步驟,所以 之后你在本地使用OpenVINO之前需要遵循此步驟。
通過模型下載器下載人體姿勢識別模型
正式進(jìn)入實驗?zāi)夸?#xff1a;
cd $WD
查看human_pose_estimation_3d_demo需要的模型列表:
cat /opt/intel/openvino_2021//deployment_tools/inference_engine/demos/human_pose_estimation_3d_demo/python/models.lst
通過模型下載器下載模型:
python3 $OV/deployment_tools/tools/model_downloader/downloader.py --list $OV/deployment_tools/inference_engine/demos/human_pose_estimation_3d_demo/python/models.lst -o $WD
使用模型轉(zhuǎn)換器把模型轉(zhuǎn)換成IR格式
OpenVINO支持把市面上主流的框架比如TensorFlow/Pytorch->ONNX/CAFFE等框架構(gòu)建好的模型轉(zhuǎn)換為IR格式:
python3 $OV/deployment_tools/tools/model_downloader/converter.py --list $OV/deployment_tools/inference_engine/demos/human_pose_estimation_3d_demo/python/models.lst
PS:目前OpenVINO的推理引擎只能夠推理經(jīng)過轉(zhuǎn)換完成的IR文件,無法直接推理.pb/.caffemode/.pt等文件。
編譯OpenVINO的Python API
只需要編譯一次:
source $OV/inference_engine/demos/build_demos.sh -DENABLE_PYTHON=ON
若你需要使用OpenVINO的PythonAPI,請加入如下編譯出來的庫地址(否則會找不到庫):
export PYTHONPATH="$PYTHONPATH:/home/dc2-user/omz_demos_build/intel64/Release/lib/"
播放待識別的實驗視頻
由于網(wǎng)頁播放器限制,請手動輸入如下命令來播放視頻:
show 3d_dancing.mp4
PS:請務(wù)必使用鍵盤逐字母進(jìn)行輸入
運行人體姿勢識別Demo
運行人體姿勢識別Demo:
python3 $OV/inference_engine/demos/human_pose_estimation_3d_demo/python/human_pose_estimation_3d_demo.py -m $WD/public/human-pose-estimation-3d-0001/FP16/human-pose-estimation-3d-0001.xml -i 3d_dancing.mp4 --no_show -o output.avi
請耐心等待程序運行完成,若屏幕出現(xiàn)Inference Completed!! 則表示推理完成,請輸入“l(fā)s”羅列當(dāng)前文件夾的所有文件
轉(zhuǎn)換并播放識別結(jié)果視頻
由于平臺限制,我們必須先將輸出結(jié)果視頻轉(zhuǎn)換為MP4格式,使用如下命令:
ffmpeg -i output.avi output.mp4
手動輸入如下命令進(jìn)行推理結(jié)果視頻播放:
show output.mp4
2.圖像著色示例
設(shè)置實驗路徑
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/01/Colorization/
初始化OpenVINO
source $OV/bin/setupvars.sh
開始實驗
正式進(jìn)入工作目錄:
cd $WD
查看該demo的所需模型:
cat $OV/deployment_tools/inference_engine/demos/colorization_demo/python/models.lst
由于該實驗?zāi)P洼^大,模型已經(jīng)提前下載好了,請繼續(xù)下一步。
查看原始視頻
所有show命令都請手動輸入:
show butterfly.mp4
運行著色Demo
python3 $OV/inference_engine/demos/colorization_demo/python/colorization_demo.py -m $WD/public/colorization-siggraph/colorization-siggraph.onnx -i butterfly.mp4 --no_show -o output.avi
PS:細(xì)心的同學(xué)會發(fā)現(xiàn),這個實驗中可以直接使用onnx格式進(jìn)行實驗,這說明推理引擎是支持簡單的onnx進(jìn)行推理(當(dāng)然你轉(zhuǎn)換為IR也可以)。請耐心等待程序運行完成,你將會看到“Inference Completed”的字樣。輸出avi將保存于當(dāng)前文件夾,使用小寫“LL”命令查看當(dāng)前文件夾。
查看著色實驗的輸出結(jié)果視頻
請先使用ffmpeg將.avi轉(zhuǎn)換為.mp4格式:
ffmpeg -i output.avi output.mp4
手動輸入播放視頻的指令:
show output.mp4
PS:若轉(zhuǎn)換完成使用show命令無法顯示,請稍后30s再試。
3.音頻檢測示例
初始化環(huán)境
#初始化工作目錄
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/01/Audio-Detection/
#初始OpenVINO
source $OV/bin/setupvars.sh
進(jìn)入音頻檢測目錄
#進(jìn)入OpenVINO中自帶的音頻檢測示例:
cd $OV/data_processing/dl_streamer/samples/gst_launch/audio_detect
#你可以查看檢測的標(biāo)簽文件
vi ./model_proc/aclnet.json
#你也可以播放待會待檢測的音頻文件
show how_are_you_doing.mp3
運行音頻檢測
#運行示例
bash audio_event_detection.sh
分析音頻檢測結(jié)果
#結(jié)果并不是很適合觀察,你可以運行如下命令
bash audio_event_detection.sh | grep “l(fā)abel”:" |sed ‘s/.*label"//’ | sed ‘s/"label_id.start_timestamp"😕/’ | sed 's/}].//’
#現(xiàn)在你可以看到在時間戳600000000的時候,我們檢測到語音了,但并不知道內(nèi)容是什么,因為它知識一個檢測示例,并不是一個識別示例:“Speech”,600000000
4.公式識別
初始化環(huán)境
#初始化環(huán)境
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/01/Formula_recognition/
#初始化OpenVINO
source $OV/bin/setupvars.sh
查看可識別的字符
cd $WD
#手寫字符:
vi hand.json
#打印字符:
vi latex.json
查看待識別的公式
#進(jìn)入材料目錄
cd $WD/…/Materials/
#查看打印公式
show Latex-formula.png
#查看手寫公式
show Hand-formula.png
運行公式識別
cd $WD
#識別打印公式
python3 $OV/inference_engine/demos/formula_recognition_demo/python/formula_recognition_demo.py -m_encoder $WD/intel/formula-recognition-medium-scan-0001/formula-recognition-medium-scan-0001-im2latex-encoder/FP16/formula-recognition-medium-scan-0001-im2latex-encoder.xml -m_decoder $WD/intel/formula-recognition-medium-scan-0001/formula-recognition-medium-scan-0001-im2latex-decoder/FP16/formula-recognition-medium-scan-0001-im2latex-decoder.xml --vocab_path latex.json -i $WD/…/Materials/Latex-formula.png -no_show
識別手寫公式
#識別手寫公式
python3 $OV/inference_engine/demos/formula_recognition_demo/python/formula_recognition_demo.py -m_encoder $WD/intel/formula-recognition-polynomials-handwritten-0001/formula-recognition-polynomials-handwritten-0001-encoder/FP16/formula-recognition-polynomials-handwritten-0001-encoder.xml -m_decoder $WD/intel/formula-recognition-polynomials-handwritten-0001/formula-recognition-polynomials-handwritten-0001-decoder/FP16/formula-recognition-polynomials-handwritten-0001-decoder.xml --vocab_path hand.json -i $WD/…/Materials/Hand-formula.png -no_show
挑戰(zhàn)任務(wù)
#可上傳自己的手寫公式,保存為PNG格式來示例進(jìn)行識別
#上傳文件的方法位于網(wǎng)頁右上角幫助手冊中
#若想跳過該任務(wù)直接點擊確認(rèn)即可
5.環(huán)境深度識別
初始化環(huán)境
#環(huán)境目錄
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/01/MonoDepth_Python/
#初始化OpenVINO
source $OV/bin/setupvars.sh
轉(zhuǎn)換原始模型文件為IR文件
進(jìn)入工作目錄
cd $WD
#下載好的模型為TensorFlow格式,使用converter準(zhǔn)換為IR格式:
python3 $OV/deployment_tools/tools/model_downloader/converter.py --list $OV/deployment_tools/inference_engine/demos/monodepth_demo/python/models.lst
查看需要被識別的原始圖片
#查看原始文件
show tree.jpeg
運行深度識別示例
#進(jìn)入工作目錄
cd $WD
運行示例,該示例的作用是自動分離圖片中景深不同的地方:
python3 $OV/inference_engine/demos/monodepth_demo/python/monodepth_demo.py -m $WD/public/midasnet/FP32/midasnet.xml -i tree.jpeg
#查看顯示結(jié)果
show disp.png
6.目標(biāo)識別示例
初始化環(huán)境
#定義OpenVINO 目錄
export OV=/opt/intel/openvino_2021/
#定義工作目錄
export WD=~/OV-300/01/Object_Detection/
#初始化OpenVINO
source $OV/bin/setupvars.sh
#進(jìn)入工作目錄
cd $WD
選擇適合你的模型
#由于支持目標(biāo)檢測的模型較多,你可以在不同拓?fù)渚W(wǎng)絡(luò)下選擇適合模型:
vi $OV/inference_engine/demos/object_detection_demo/python/models.lst
注:關(guān)于SSD, Yolo, centernet, faceboxes or Retina拓?fù)渚W(wǎng)絡(luò)的區(qū)別,本課程不會繼續(xù)深入,有興趣的同學(xué)可以自行上網(wǎng)了解。在OpenVINO中的deployment_tools/inference_engine/demos/的各個demo文件夾中都有model.lst列出了該demo支持的可直接通過downloader下載使用的模型
轉(zhuǎn)換模型至IR格式
#本實驗已經(jīng)事先下完成:pedestrian-and-vehicle-detector-adas 與 yolo-v3-tf
#使用Converter進(jìn)行IR轉(zhuǎn)換,由于pedestrian-and-vehicle-detector-adas 為英特爾預(yù)訓(xùn)練模型,已經(jīng)轉(zhuǎn)換IR完成,只需要對yolo-v3進(jìn)行轉(zhuǎn)換:
python3 $OV/deployment_tools/tools/model_downloader/converter.py --name yolo-v3-tf
查看待檢測的視頻
cd $WD/…/Materials/Road.mp4
#播放視頻:
show Road.mp4
使用SSD模型運行目標(biāo)檢測示例
cd $WD
#運行 OMZ (ssd) model
python3 $OV/inference_engine/demos/object_detection_demo/python/object_detection_demo.py -m $WD/intel/pedestrian-and-vehicle-detector-adas-0001/FP16/pedestrian-and-vehicle-detector-adas-0001.xml --architecture_type ssd -i $WD/…/Materials/Road.mp4 --no_show -o $WD/output_ssd.avi
#轉(zhuǎn)換為mp4格式進(jìn)行播放
ffmpeg -i output_ssd.avi output_ssd.mp4
show output_ssd.mp4
運行Yolo-V3下的目標(biāo)檢測示例
#運行 the Yolo V3 model
python3 $OV/inference_engine/demos/object_detection_demo/python/object_detection_demo.py -m $WD/public/yolo-v3-tf/FP16/yolo-v3-tf.xml -i $WD/…/Materials/Road.mp4 --architecture_type yolo --no_show -o $WD/output_yolo.avi
#轉(zhuǎn)換為mp4格式進(jìn)行播放
ffmpeg -i output_yolo.avi output_yolo.mp4
show output_yolo.mp4
!請對比兩個模型在相同代碼下的檢測性能
7.自然語言處理示例(NLP)——自動回答問題
初始化環(huán)境
#定義工作目錄
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/01/NLP-Bert/
#初始化OpenVINO
source $OV/bin/setupvars.sh
#進(jìn)入目錄
cd $WD
查看支持的模型列表
#可用列表:
cat $OV/deployment_tools/inference_engine/demos/bert_question_answering_demo/python/models.lst
注:在OpenVINO中的deployment_tools/inference_engine/demos/的各個demo文件夾中都有model.lst列出了該demo支持的可直接通過downloader下載使用的模型,且我們已經(jīng)事先下載好全部模型為IR格式。
打開待識別的網(wǎng)址
#使用瀏覽器打開一個英文網(wǎng)址進(jìn)行瀏覽,例如Intel官網(wǎng):https://www.intel.com/content/www/us/en/homepage.html
運行NLP示例
python3 $OV/inference_engine/demos/bert_question_answering_demo/python/bert_question_answering_demo.py -m $WD/intel/bert-small-uncased-whole-word-masking-squad-0001/FP16/bert-small-uncased-whole-word-masking-squad-0001.xml -v $OV/deployment_tools/open_model_zoo/models/intel/bert-small-uncased-whole-word-masking-squad-0001/vocab.txt --input=https://www.intel.com/content/www/us/en/homepage.html --input_names=input_ids,attention_mask,token_type_ids --output_names=output_s,output_e
#在Type question (empty string to exit): 輸入core。即可查看當(dāng)前對于core(酷睿)的可知信息,例如: Intel? Core? processors provide a range of performance from entry-level to the highest level 。當(dāng)然你也可以輸入別的問題。對比網(wǎng)站上的相關(guān)描述
注:–input=https://www.intel.com/content/www/us/en/homepage.html 為我們需要訪問的英文網(wǎng)站
挑戰(zhàn)任務(wù)
#在上一個步驟的實驗基礎(chǔ)上,嘗試使用不同的網(wǎng)址作為–input 的輸入,并嘗試提出一些別的關(guān)鍵詞問題。并思考如何能夠提升這個示例的準(zhǔn)確性。
#在上一個步驟的實驗基礎(chǔ)上,嘗試使用不同的模型作為-m/-v 的輸入(模型位于$WD/INTEL/目錄下),并嘗試提出一些別的關(guān)鍵詞問題。并思考如何能夠提升這個示例的準(zhǔn)確性。
注:該示例只支持英文網(wǎng)站,且該網(wǎng)站可正常訪問。
第二課動手實驗:如何構(gòu)建一個異構(gòu)系統(tǒng)——動手實驗-在線測試
1.上傳性能評估腳本到DevCloud
初始實驗路徑
#定義OpenVINO 文件夾
export OV=/opt/intel/openvino_2021/
#定義工作目錄
export WD=~/OV-300/02/LAB1/
#初始化OpenVINO
source $OV/bin/setupvars.sh
#進(jìn)入實驗?zāi)夸?/p>
cd $WD
查看當(dāng)前設(shè)備信息
通過OpenVINO自帶腳本可以查詢當(dāng)前環(huán)境的設(shè)備信息:
python3 $OV/inference_engine/samples/python/hello_query_device/hello_query_device.py
DevCloud 介紹
英特爾? DevCloud 提供對各種英特爾? 架構(gòu)CPU/GPU/NCS2/智能硬件等設(shè)備的免費訪問,幫助您獲得英特爾? 軟件的即時動手體驗,并執(zhí)行您的邊緣、人工智能、高性能計算 (HPC) 和渲染工作負(fù)載。借助預(yù)裝的英特爾? 優(yōu)化框架、工具(OpenVINO Toolkit, OneAPI)和庫,您擁有快速跟蹤學(xué)習(xí)和項目原型制作所需的一切。
本次實驗提供了4個可用節(jié)點:
idc004nc2: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
idc007xv5: Intel - xeon e3-1268l-v5, intel-hd-p530
idc008u2g: Intel - atom e3950, intel-hd-505,myriad-1-VPU
idc014:Intel - i7 8665ue, intel-uhd-620
注:NCS2中文名為第二代神經(jīng)計算棒,是英特爾公司推出的邊緣計算設(shè)備,體積和U盤相似,接口為USB3.0,內(nèi)置Myriad X計算芯片,功耗僅為2W,理論算力可達(dá)1TOPS。OpenVINO可以通過“MYRIAD”的插件將深度學(xué)習(xí)模型部署在上面。
上傳Benchmark_App.py至DevCloud中運行
我們將需要運行的代碼提交至idc004nc2節(jié)點中執(zhí)行:
python3 submit_job_to_DevCloud.pyc idc004nc2
PS:因為有一定的網(wǎng)絡(luò)延遲,若命令無反應(yīng),可重復(fù)嘗試幾次該命令。
請耐心等待實驗狀態(tài)成為“C”,腳本執(zhí)行完成,上傳的腳本位于當(dāng)前文件目錄下,名為userscript.py, 其功能是將OpenVINO的人臉識別模型運行在NCS2上以得到性能參數(shù)。
比較不同CPU下NCS2的性能
根據(jù)剛才上傳的指令,將同樣的代碼上傳至idc008u2g節(jié)點。
上傳指令為:
python3 submit_job_to_DevCloud.pyc “目標(biāo)節(jié)點名稱”
PS:該指令默認(rèn)上傳當(dāng)前目錄下的userscript.py腳本。
請對比不同CPU(Atom和 Core)的條件下,NCS2的性能是否有差異?
比較結(jié)果如下:
idc004nc2: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc004nc2
[Step 11/11] Dumping statistics report
Count: 260 iterations
Duration: 10297.15 ms
Latency: 158.08 ms
Throughput: 25.25 FPS
idc008u2g: Intel - atom e3950, intel-hd-505,myriad-1-VPU
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc008u2g
[Step 11/11] Dumping statistics report
Count: 260 iterations
Duration: 10294.75 ms
Latency: 157.99 ms
Throughput: 25.26 FPS
挑戰(zhàn)任務(wù)1:將推理任務(wù)部署在節(jié)點的不同推理設(shè)備上
修改userscript.py:
vi userscript.py
在第43行: target_device= “MYRIAD”
注:可使用“:wq”指令保存更改并退出該界面。
你可以在這里選擇你想要運行的設(shè)備:"CPU/GPU/MYRIAD”
CPU:對應(yīng) 英特爾中央處理器
GPU:對應(yīng) 英特爾集成顯卡
MYRIAD:這個名稱對應(yīng)的設(shè)備是剛才提到的NCS2
這里你可以自行發(fā)揮,嘗試使用不同的設(shè)備 或者Devcloud節(jié)點運行這個性能測試腳本
嘗試使用不同的設(shè)備 或者Devcloud節(jié)點運行這個性能測試執(zhí)行結(jié)果如下:
設(shè)備:GPU
Devcloud節(jié)點:idc007xv5: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc007xv5
[Step 11/11] Dumping statistics report
Count: 724 iterations
Duration: 10031.90 ms
Latency: 27.45 ms
Throughput: 72.17 FPS
設(shè)備:CPU
Devcloud節(jié)點:idc007xv5: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc007xv5
[Step 11/11] Dumping statistics report
Count: 920 iterations
Duration: 10015.39 ms
Latency: 10.82 ms
Throughput: 91.86 FPS
target_device= “MYRIAD”
設(shè)備:MYRIAD
Devcloud節(jié)點:idc007xv5: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc007xv5
2022年 02月 21日 星期一 06:17:38 CST,設(shè)備:MYRIAD,運行腳本報錯 RuntimeError: Can not init Myriad device: NC_ERROR。
2022年 02月 21日 星期一 03:56:50 CST,網(wǎng)頁shell卡死失效,無法保存退出(:wq),無執(zhí)行結(jié)果。2022年 02月 21日 星期一 05:55:18 CST,ok處理好了,不是卡死是命令在web shell上無效,改用 ctrl+[ 退出INSERT模式就ok了。
挑戰(zhàn)任務(wù)2:打印出NCS2的工作溫度
請根據(jù):hello_query_device.py 代碼中的關(guān)于溫度顯示的片段,更改userscript.py,使之可以顯示當(dāng)前NCS2的工作溫度。
請在userscript.py的 line:136 后 添加適當(dāng)?shù)拇a,來顯示當(dāng)前NCS2的溫度。
提示:請在確保target_device為“MYRIAD”的前提下,使用函數(shù):self.ie.get_metric(metric_name=“DEVICE_THERMAL”,device_name=‘MYRIAD’ ) 獲取溫度。
答案userscript…py 位于上一級目錄的Solution文件夾中,你可以復(fù)制到當(dāng)前文件夾進(jìn)行使用。
2022年 02月 21日 星期一 04:03:53 CST,這個有難度,先跳過。
2.利用多硬件協(xié)同推理
初始化實驗?zāi)夸?/p>
#定義OV目錄
export OV=/opt/intel/openvino_2021/
#定義工作目錄
export WD=~/OV-300/02/LAB2/
#初始化OpenVINO
source $OV/bin/setupvars.sh
#進(jìn)入工作目錄
cd $WD
不同模型的性能測試
我們?yōu)槟銣?zhǔn)備了三個模型:
face-detection-adas-0001.xml
head-pose-estimation-adas-0001.xml
text-spotting-0003-recognizer-encoder.xml
請對userscript.py進(jìn)行編輯:
在line 44: path_to_model="/app/face-detection-adas-0001.xml" 中對 face-detection-adas-0001.xml 進(jìn)行替換,即可測試不同的模型
不同模型的性能測試執(zhí)行結(jié)果如下:
設(shè)備:CPU
Devcloud節(jié)點:idc007xv5: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
模型:head-pose-estimation-adas-0001.xml
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc007xv5
[Step 11/11] Dumping statistics report
Count: 720 iterations
Duration: 10055.01 ms
Latency: 27.66 ms
Throughput: 71.61 FPS
設(shè)備:CPU
Devcloud節(jié)點:idc007xv5: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
模型:face-detection-adas-0001.xml
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc007xv5
[Step 11/11] Dumping statistics report
Count: 923 iterations
Duration: 10018.43 ms
Latency: 10.79 ms
Throughput: 92.13 FPS
2022年 02月 21日 星期一 05:27:26 CST,vi編輯userscript.py文件的時候,發(fā)現(xiàn)文件中的內(nèi)容少了(可能是前面的實驗操作,操作失誤錯刪除了?),少了line 44: path_to_model="/app/face-detection-adas-0001.xml"配置這段,這咋整…。
2022年 02月 21日 星期一 05:50:11 CST,系統(tǒng)又默認(rèn)恢復(fù)了???。
使用多硬件協(xié)同推理
OpenVINO提供了多硬件協(xié)同推理的“MULTI”插件,你只需要編譯Target_device的對象,不需要改動原先代碼,便可以實現(xiàn)協(xié)同推理。
例如:target_device=“MULTI:CPU,GPU” , 即可使用CPU+GPU協(xié)同推理 ,其中CPU(1st priority) and GPU (2nd priority)。
注:本實驗所有的GPU均為英特爾集成顯卡,在進(jìn)行實驗之前,請務(wù)必確認(rèn)運行的節(jié)點包含GPU設(shè)備(某些型號的至強處理器不包含GPU設(shè)備)。MYRIAD也是同理,請在實驗前確保實驗節(jié)點擁有該硬件!
使用多硬件協(xié)同推理測試執(zhí)行結(jié)果如下:
target_device=“MULTI:CPU,GPU”
設(shè)備:MULTI:CPU,GPU
Devcloud節(jié)點:idc007xv5: Intel - core i5-6500te, intel-hd-530,myriad-1-VPU
執(zhí)行命令:python3 submit_job_to_DevCloud.pyc idc007xv5
[Step 11/11] Dumping statistics report
Count: 1065 iterations
Duration: 10037.20 ms
Throughput: 106.11 FPS
進(jìn)行性能對比實驗
請在idc004nc2節(jié)點下,完成如下表格并分析性能數(shù)據(jù):
逐個參數(shù)修:vi userscript.py
target_device=“MULTI:CPU,GPU” //設(shè)備,line43
path_to_model="/app/head-pose-estimation-adas-0001.xml" //模型,line44
運行任務(wù):python3 submit_job_to_DevCloud.pyc idc004nc2
2022年 02月 21日 星期一 06:33:15 CST,該睡覺了,睡醒再整了。
Intel DevCloud引導(dǎo)
由于實驗內(nèi)容有限,暫時不列舉其他DevCloud平臺上有趣的動手實驗,以及超過30種邊緣設(shè)備,Atom,Xeon,Core應(yīng)有盡有,更有11代TigerLake CPU設(shè)備等你來試,感興趣的同學(xué)請自行移至英特爾DevCloud官網(wǎng)進(jìn)行體驗。
2022年 02月 21日 星期一 21:14:54 CST,更多設(shè)備的性能測試,自己到DevCloud官網(wǎng)體驗了。
第三課動手實驗:AI應(yīng)用中的視頻處理-在線測試
1.測試當(dāng)前設(shè)備的解碼密度
初始化環(huán)境
#定義OV目錄
export OV=/opt/intel/openvino_2021/
#定義工作目錄
export WD=~/OV-300/03/
#初始化OpenVINO
source $OV/bin/setupvars.sh
進(jìn)行解碼密度測試
進(jìn)入工作目錄
cd $WD
由于當(dāng)前環(huán)境只有 CPU,且DevCloud只接受.py腳本。
所以需要你通過如下指令獲取及結(jié)果為25 FPS per channel的通道數(shù):
bash decode.sh video1.mp4 CPU CPU 1
bash decode.sh video1.mp4 CPU CPU 10
bash decode.sh video1.mp4 CPU CPU 100
你也可以自行調(diào)整通道數(shù),使之最后接近per-stream= 25FPS/channel。
請記錄下你的答案!
bash decode.sh video1.mp4 CPU CPU 1
Redistribute latency…
FpsCounter(1sec): total=740.71 fps, number-streams=1, per-stream=740.71 fps
FpsCounter(1sec): total=742.76 fps, number-streams=1, per-stream=742.76 fps
FpsCounter(1sec): total=732.41 fps, number-streams=1, per-stream=732.41 fps
FpsCounter(1sec): total=722.62 fps, number-streams=1, per-stream=722.62 fps
FPSCounter(average): total=732.91 fps, number-streams=1, per-stream=732.91 fps
bash decode.sh video1.mp4 CPU CPU 10
Redistribute latency…
FpsCounter(1sec): total=621.85 fps, number-streams=10, per-stream=62.19 fps (56.99, 63.98, 59.99, 57.99, 65.98, 61.99, 64.98, 61.99, 63.98, 63.98)
FpsCounter(1sec): total=621.26 fps, number-streams=10, per-stream=62.13 fps (68.59, 59.64, 59.64, 59.64, 59.64, 59.64, 64.61, 62.62, 63.62, 63.62)
FpsCounter(1sec): total=699.73 fps, number-streams=10, per-stream=69.97 fps (69.77, 69.77, 69.77, 67.78, 70.77, 69.77, 69.77, 68.78, 71.77, 71.77)
FpsCounter(1sec): total=713.92 fps, number-streams=10, per-stream=71.39 fps (71.99, 70.99, 71.99, 69.99, 70.99, 69.99, 71.99, 71.99, 71.99, 71.99)
FpsCounter(1sec): total=651.90 fps, number-streams=10, per-stream=65.19 fps (61.99, 62.99, 67.99, 64.99, 61.99, 63.99, 65.99, 65.99, 67.99, 67.99)
bash decode.sh video1.mp4 CPU CPU 100
Redistribute latency…
New clock: GstSystemClock0 %)
FpsCounter(1sec): total=134.83 fps, number-streams=100, per-stream=1.35 fps (1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 2.00, 1.00, 1.00, 2.00, 2.00, 1.00, 2.00, 2.00, 1.00, 1.00, 1.00, 1.00, 2.00, 1.00, 1.00, 1.00, 2.00, 1.00, 1.00, 2.00, 1.00, 2.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 2.00, 2.00, 2.00, 2.00, 2.00, 1.00, 1.00, 1.00, 2.00, 1.00, 2.00, 3.00, 2.00, 1.00, 2.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 2.00, 1.00, 2.00, 1.00, 1.00, 2.00, 2.00, 1.00, 1.00, 2.00, 1.00, 2.00, 1.00, 2.00, 1.00, 1.00, 1.00, 1.00, 1.00, 2.00, 1.00, 1.00, 1.00, 2.00, 2.00, 2.00, 2.00, 1.00, 1.00, 1.00, 2.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 2.00, 1.00, 2.00, 1.00, 1.00)
FpsCounter(1sec): total=367.22 fps, number-streams=100, per-stream=3.67 fps (2.00, 2.99, 2.99, 2.99, 5.99, 2.99, 1.00, 2.00, 2.00, 2.99, 2.00, 2.99, 1.00, 2.00, 8.98, 2.99, 1.00, 2.00, 2.00, 2.99, 1.00, 2.99, 5.99, 2.00, 1.00, 3.99, 5.99, 1.00, 8.98, 2.99, 2.99, 2.00, 2.99, 2.00, 2.00, 2.00, 14.97, 2.00, 4.99, 1.00, 2.99, 2.00, 2.99, 10.98, 2.00, 8.98, 7.98, 2.00, 2.99, 2.00, 2.99, 2.99, 2.00, 2.99, 1.00, 2.00, 2.99, 1.00, 2.99, 2.99, 2.99, 10.98, 2.99, 2.00, 9.98, 2.00, 2.99, 2.99, 1.00, 2.99, 2.00, 2.00, 7.98, 10.98, 2.99, 2.99, 3.99, 2.99, 2.99, 5.99, 16.96, 6.99, 2.99, 1.00, 2.99, 2.99, 2.00, 14.97, 2.99, 2.00, 1.00, 4.99, 2.99, 2.99, 2.99, 2.00, 2.99, 2.99, 2.99, 2.00)
FpsCounter(1sec): total=659.83 fps, number-streams=100, per-stream=6.60 fps (5.00, 6.00, 6.00, 6.00, 7.00, 4.00, 7.00, 8.00, 9.00, 8.00, 5.00, 9.00, 7.00, 4.00, 7.00, 6.00, 6.00, 3.00, 7.00, 6.00, 6.00, 7.00, 7.00, 8.00, 7.00, 9.00, 6.00, 7.00, 6.00, 9.00, 8.00, 5.00, 5.00, 6.00, 7.00, 6.00, 4.00, 6.00, 9.00, 6.00, 5.00, 8.00, 8.00, 9.00, 8.00, 4.00, 6.00, 9.00, 5.00, 7.00, 9.00, 8.00, 6.00, 6.00, 6.00, 9.00, 9.00, 5.00, 8.00, 7.00, 6.00, 5.00, 10.00, 7.00, 2.00, 6.00, 4.00, 6.00, 5.00, 8.00, 7.00, 9.00, 4.00, 5.00, 6.00, 5.00, 8.00, 7.00, 5.00, 7.00, 3.00, 9.00, 9.00, 5.00, 7.00, 7.00, 10.00, 3.00, 9.00, 7.00, 7.00, 8.00, 6.00, 7.00, 6.00, 6.00, 9.00, 7.00, 6.00, 5.00)
FpsCounter(1sec): total=702.32 fps, number-streams=100, per-stream=7.02 fps (5.99, 8.98, 5.99, 6.98, 6.98, 5.99, 5.99, 7.98, 7.98, 7.98, 8.98, 4.99, 8.98, 7.98, 6.98, 8.98, 5.99, 7.98, 7.98, 5.99, 5.99, 4.99, 7.98, 8.98, 6.98, 6.98, 6.98, 5.99, 6.98, 5.99, 5.99, 5.99, 6.98, 8.98, 6.98, 7.98, 7.98, 5.99, 6.98, 7.98, 6.98, 7.98, 6.98, 6.98, 5.99, 7.98, 7.98, 6.98, 6.98, 3.99, 4.99, 7.98, 6.98, 5.99, 6.98, 7.98, 7.98, 7.98, 5.99, 6.98, 5.99, 6.98, 5.99, 5.99, 8.98, 6.98, 5.99, 8.98, 5.99, 7.98, 4.99, 7.98, 6.98, 7.98, 6.98, 6.98, 6.98, 6.98, 6.98, 6.98, 6.98, 5.99, 6.98, 5.99, 7.98, 6.98, 6.98, 7.98, 7.98, 6.98, 4.99, 7.98, 5.99, 7.98, 5.99, 7.98, 7.98, 6.98, 5.99, 5.99)
bash decode.sh video1.mp4 CPU CPU 50( 通道數(shù)接近per-stream= 25FPS/channel)
Redistribute latency…
New clock: GstSystemClock
FpsCounter(1sec): total=531.74 fps, number-streams=25, per-stream=21.27 fps (24.94, 23.94, 20.95, 19.95, 20.95, 21.95, 18.95, 20.95, 19.95, 23.94, 20.95, 12.97, 23.94, 20.95, 17.96, 23.94, 13.97, 19.95, 23.94, 26.94, 24.94, 22.95, 20.95, 19.95, 20.95)
FpsCounter(1sec): total=750.60 fps, number-streams=25, per-stream=30.02 fps (31.94, 30.94, 29.94, 27.95, 28.95, 31.94, 31.94, 28.95, 29.94, 30.94, 30.94, 28.95, 30.94, 30.94, 30.94, 29.94, 27.95, 30.94, 29.94, 28.95, 31.94, 29.94, 27.95, 27.95, 28.95)
FpsCounter(1sec): total=683.31 fps, number-streams=25, per-stream=27.33 fps (26.97, 26.97, 28.97, 25.97, 29.97, 27.97, 26.97, 29.97, 27.97, 24.97, 25.97, 25.97, 26.97, 30.97, 26.97, 29.97, 25.97, 28.97, 27.97, 25.97, 24.97, 28.97, 26.97, 25.97, 23.98)
FpsCounter(1sec): total=732.91 fps, number-streams=25, per-stream=29.32 fps (27.96, 29.96, 27.96, 29.96, 25.96, 30.95, 27.96, 27.96, 27.96, 31.95, 29.96, 29.96, 31.95, 29.96, 29.96, 27.96, 31.95, 28.96, 27.96, 29.96, 29.96, 27.96, 27.96, 29.96, 29.96)
FpsCounter(1sec): total=734.54 fps, number-streams=25, per-stream=29.38 fps (27.98, 30.98, 25.98, 29.98, 27.98, 32.98, 27.98, 27.98, 28.98, 29.98, 29.98, 31.98, 29.98, 28.98, 27.98, 27.98, 29.98, 24.98, 29.98, 29.98, 31.98, 27.98, 27.98, 31.98, 31.98)
第四課動手實驗:如何進(jìn)行AI推理的性能對比-在線測試
1.數(shù)據(jù)精度對推理性能的影響
初始化環(huán)境
#定義OV目錄
export OV=/opt/intel/openvino_2021/
#定義工作目錄
export WD=~/OV-300/04/
#初始化OpenVINO
source $OV/bin/setupvars.sh
編譯示例
#一鍵編譯OpenVINO中的C++ sample
source $OV/inference_engine/samples/cpp/build_samples.sh
開始實驗
開始實驗:
cd $WD
將剛才編譯完成的benchmark_app 復(fù)制到當(dāng)前文件夾:
cp /home/dc2-user/inference_engine_04_samples_build/intel64/Release/benchmark_app $WD
獲取模型
下載模型:
python3 $OV/deployment_tools/tools/model_downloader/downloader.py --name face-detection-adas-0001 -o $WD
進(jìn)行不同精度的模型性能測試
./benchmark_app -m intel/face-detection-adas-0001/FP32/face-detection-adas-0001.xml
./benchmark_app -m intel/face-detection-adas-0001/FP16/face-detection-adas-0001.xml
./benchmark_app -m intel/face-detection-adas-0001/FP16-INT8/face-detection-adas-0001.xml
比較不同精度的模型性能,以及模型的推理延遲或者是讀取網(wǎng)絡(luò)的時間…看看有什么不一樣。
不同精度的模型性能如下:
挑戰(zhàn)任務(wù)
請輸入:
./benchmark_app -help
以獲得更多benchmark_app 的可評估參數(shù)。
請嘗試設(shè)置不同的參數(shù):
number of streams (-nstreams)
batch size (-b)
number of inderence request (-nireq)
number of threads (-nthreads)
例如:./benchmark_app -m intel/face-detection-adas-0001/FP32/face-detection-adas-0001.xml -b 2 -nireq 2 -nthreads 4
來獲取當(dāng)前設(shè)備的最佳性能
第六課動手實驗:AI應(yīng)用中的音頻處理-在線測試
1.聲音檢測實驗
初始化環(huán)境
#定義工作目錄
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/06/Lab1/
export MODELS_PATH=~/OV-300/06/Lab1/
#初始化OpenVINO
source $OV/bin/setupvars.sh
開始實驗
#進(jìn)入實驗?zāi)夸?/p>
cd $WD
#下載并使用MO轉(zhuǎn)換聲音識別模型
bash download_audio_models.sh
#通過vi查看模型拓?fù)浣Y(jié)構(gòu)
vi $MODELS_PATH/audio_models/aclnet/FP32/aclnet.xml
注:可以看到該xml的版本以及 數(shù)據(jù)精度為:FP32,input shape=“1, 1, 1, 16000”。使用“:q”指令退出該界面。
播放需要檢測的聲音文件
#使用show命令,播放mp3
show how_are_you_doing.mp3
注:由于功能限制,必須手動逐字輸入該命令。并且由于限制,平臺只能夠播放MP3格式文件,實驗運行的聲音材料為WAV格式,本平臺事先已經(jīng)將WAV轉(zhuǎn)換成MP3格式可供使用。
運行Demo
#運行指令:
bash audio_event_detection.sh
注:屏幕上將會打印DL-Streamer的pipeline指令和該指令的全部輸出結(jié)果
#運行篩選結(jié)果的指令,來查看探測到的聲音種類:
bash audio_event_detection.sh | grep “l(fā)abel”:" | sed ‘s/label_id.*//’ |sed ‘s/.*label"/==>/’
探測到的聲音種類:
挑戰(zhàn)任務(wù):提高程序的識別準(zhǔn)確度
#你可以從音頻文件聽到?jīng)]有昆蟲的聲音,但是程序檢測到了昆蟲的聲音。請你思考一下,如何改善這個問題?
注:檢測每個種類的聲音是否村子都會存在一個臨界值,也就是檢測閾值
#修改aclnet.json 腳本來實現(xiàn)你的猜想:
vi $WD/model_proc/aclnet.json
解決方案:嘗試 “Insects (flying)” 在 0.5 至0.9 之間更改,更改后保存完再次運行audio_event_detection.sh進(jìn)行測試,直至檢測不到昆蟲噪音。
{
“index”: 7,
“l(fā)abel”: “Insects (flying)”,
“threshold”: 0.5 //修改為上臨界值0.9
},
檢測結(jié)果(無昆蟲噪音了):
==>:“Rain”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
==>:“Speech”,"
思考任務(wù)
你可以上傳你的WAV文件進(jìn)行測試,不過若是想使用平臺進(jìn)行播放mp3,記得使用:
ffmpeg -i xxx.wav output.mp3
轉(zhuǎn)換成MP3進(jìn)行播放哦,并且需要修改audio_event_detection.sh里面的輸入wav名稱。
注:上傳與下載文件的教程在頁面上角幫助手冊中可以得到。該實驗可按確認(rèn)鍵跳過。
2022年 02月 21日 星期一 22:47:34 CST,后面還有任務(wù),先跳過。
2.聲音識別實驗
初始化環(huán)境
#定義工作目錄
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/06/Lab2/
#添加OpenVINO Python API路徑
export PYTHONPATH="$PYTHONPATH:/home/dc2-user/omz_demos_build/intel64/Release/lib/"
#初始化OpenVINO
source $OV/bin/setupvars.sh
#進(jìn)入工作目錄
cd $WD
將原生模型轉(zhuǎn)換為IR格式
#使用converter.py將事先準(zhǔn)備好的mozilla-deepspeech-0.6.1進(jìn)行IR轉(zhuǎn)換 :
python3 $OV/deployment_tools/tools/model_downloader/converter.py --name mozilla-deepspeech-0.6.1 -o $WD
運行聲音識別Demo
#播放待識別的聲音文件:
show how_are_you_doing.mp3
#運行聲音識別示例:
python3 $OV/deployment_tools/inference_engine/demos/speech_recognition_deepspeech_demo/python/speech_recognition_deepspeech_demo.py -m ./public/mozilla-deepspeech-0.6.1/FP32/mozilla-deepspeech-0.6.1.xml -i how_are_you_doing.wav -p mds06x_en
注:音頻輸入為wav格式, 你可以在屏幕上看到剛才的音頻的識別結(jié)果。
思考任務(wù)
#使用你自帶的wav文件進(jìn)行聲音識別示例,看看能否正確識別到文件中的聲音。
#可以嘗試使用中文或者英文作為聲音輸入,并且實驗探究一下它們識別的準(zhǔn)確性。
2022年 02月 21日 星期一 22:59:47 CST,后面還有任務(wù),先跳過。
第七課動手實驗:如何實現(xiàn)DL-streamer包含的高級功能?-在線測試
1.使用DL-streamer進(jìn)行表情識別
初始化環(huán)境
#定義工作目錄
export OV=/opt/intel/openvino_2021/
export WD=~/OV-300/07/
#初始化OpenVINO
source $OV/bin/setupvars.sh
開始實驗
#進(jìn)入實驗?zāi)夸?/p>
cd $WD
#播放原始視頻示例:
show video1.mp4
運行識別示例
#運行人臉識別和分類示例:
bash face_detection_and_classification.sh video1.mp4
#獲得output.mp4,獲得可播放的標(biāo)準(zhǔn)MP4格式,使用:
ffmpeg -i output.mp4 output_1.mp4
#播放結(jié)果視頻:
show output_1.mp4
挑戰(zhàn)任務(wù):增加情緒識別功能
#請你思考如何在年齡/性別識別的基礎(chǔ)上,怎么情緒識別的功能:
修改 postproc_callbacks/age_gender_classification.py 腳本,我們往里添加的代碼是:
if 'prob_emotion' == layer_name:emotions = ["neutral", "happy", "sad", "surprise", "anger"]tensor.set_label(emotions[numpy.argmax(data)])continue修改 face_detection_and_classification.sh 腳本。需要和 age-gender-recognition模型一樣,同理增加emotion-recognition的部分,所用 模型為emotions-recognition-retail-003.xml
注:答案可以在Solution中獲取
cd Solution
#查看age_gender_classification.py/face_detection_and_classification.sh腳本的改動
bash face_detection_and_classification.sh video1.mp4
ffmpeg -i output.mp4 output_1.mp4
#播放結(jié)果視頻:
show output_1.mp4
實驗工作目錄文件列表如下: dc2-user@10-0-13-46:~/OV-300/07$ ll total 36760 drwxrwxr-x 4 dc2-user dc2-user 4096 Feb 22 00:08 ./ drwxrwxr-x 9 dc2-user dc2-user 4096 Nov 29 22:04 ../ -rw-rw-r-- 1 dc2-user dc2-user 1926 Nov 30 16:10 face_detection_and_classification.sh -rw-rw-r-- 1 dc2-user dc2-user 5760389 Feb 21 23:25 output_1.mp4 -rw-rw-r-- 1 dc2-user dc2-user 15066315 Feb 22 00:17 output.mp4 drwxrwxr-x 3 dc2-user dc2-user 4096 Feb 22 00:05 postproc_callbacks/ drwxrwxr-x 3 dc2-user dc2-user 4096 Feb 22 00:16 Solution/ -rw-rw-r-- 1 dc2-user dc2-user 16788193 Oct 25 03:22 video1.mp4 dc2-user@10-0-13-46:~/OV-300/07$
postproc_callbacks/目錄:
dc2-user@10-0-13-46:~/OV-300/07/postproc_callbacks$ ll total 20 drwxrwxr-x 3 dc2-user dc2-user 4096 Feb 22 00:05 ./ drwxrwxr-x 4 dc2-user dc2-user 4096 Feb 22 00:08 ../ -rw-rw-r-- 1 dc2-user dc2-user 1067 Feb 22 00:05 age_gender_classification.py drwxrwxr-x 2 dc2-user dc2-user 4096 Feb 22 00:16 __pycache__/ -rw-rw-r-- 1 dc2-user dc2-user 1382 Oct 25 03:22 ssd_object_detection.py dc2-user@10-0-13-46:~/OV-300/07/postproc_callbacks$Solution目錄:
dc2-user@10-0-13-46:~/OV-300/07/Solution$ ll total 24 drwxrwxr-x 3 dc2-user dc2-user 4096 Feb 22 00:16 ./ drwxrwxr-x 4 dc2-user dc2-user 4096 Feb 22 00:08 ../ -rw-rw-r-- 1 dc2-user dc2-user 1087 Oct 25 03:22 age_gender_classification.py -rw-rw-r-- 1 dc2-user dc2-user 2103 Nov 30 16:44 face_detection_and_classification.sh drwxrwxr-x 2 dc2-user dc2-user 4096 Nov 30 16:45 __pycache__/ -rw-rw-r-- 1 dc2-user dc2-user 1397 Oct 25 03:22 ssd_object_detection.py dc2-user@10-0-13-46:~/OV-300/07/Solution$~/OV-300/07/Solution/age_gender_classification.py
# ============================================================================== # Copyright (C) 2018-2020 Intel Corporation # # SPDX-License-Identifier: MIT # ==============================================================================from gstgva import VideoFrame import numpydef process_frame(frame: VideoFrame) -> bool:for roi in frame.regions():for tensor in roi.tensors():if tensor.name() == 'detection':continuelayer_name = tensor.layer_name()data = tensor.data()if 'age_conv3' == layer_name:tensor.set_label(str(int(data[0] * 100)))continueif 'prob' == layer_name:tensor.set_label(" M " if data[1] > 0.5 else " F ")continueif 'prob_emotion' == layer_name:emotions = ["neutral", "happy", "sad", "surprise", "anger"]#print(data, emotions[numpy.argmax(data)])tensor.set_label(emotions[numpy.argmax(data)])continuereturn True2022年 02月 22日 星期二 00:40:30 CST,添加line23-27行代碼。
if 'prob_emotion' == layer_name:emotions = ["neutral", "happy", "sad", "surprise", "anger"]#print(data, emotions[numpy.argmax(data)])tensor.set_label(emotions[numpy.argmax(data)])continue~/OV-300/07/Solution/face_detection_and_classification.sh
#!/bin/bash # ============================================================================== # Copyright (C) 2018-2021 Intel Corporation # # SPDX-License-Identifier: MIT # ==============================================================================set -eINPUT=${1:-https://github.com/intel-iot-devkit/sample-videos/raw/master/head-pose-face-detection-female-and-male.mp4}DEVICE=${2:-CPU}if [[ $3 == "display" ]] || [[ -z $3 ]]; thenSINK_ELEMENT="gvawatermark ! videoconvert !avenc_mpeg4 ! mp4mux! filesink location=output.mp4" elif [[ $3 == "fps" ]]; thenSINK_ELEMENT="gvafpscounter ! fakesink async=false " elseecho Error wrong value for SINK_ELEMENT parameterecho Possible values: display - render, fps - show FPS onlyexit fiMODEL1=face-detection-adas-0001 MODEL2=age-gender-recognition-retail-0013SCRIPTDIR="$(dirname "$(realpath "$0")")" PYTHON_SCRIPT1=$SCRIPTDIR/postproc_callbacks/ssd_object_detection.py PYTHON_SCRIPT2=$SCRIPTDIR/postproc_callbacks/age_gender_classification.pyif [[ $INPUT == "/dev/video"* ]]; thenSOURCE_ELEMENT="v4l2src device=${INPUT}" elif [[ $INPUT == *"://"* ]]; thenSOURCE_ELEMENT="urisourcebin buffer-size=4096 uri=${INPUT}" elseSOURCE_ELEMENT="filesrc location=${INPUT}" fiDETECT_MODEL_PATH=${MODELS_PATH}/intel/face-detection-adas-0001/FP32/face-detection-adas-0001.xml CLASS_MODEL_PATH=${MODELS_PATH}/intel/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013.xml EMOTION_MODEL_PATH=${MODELS_PATH}/intel/emotions-recognition-retail-0003/FP32/emotions-recognition-retail-0003.xmlecho Running sample with the following parameters: echo GST_PLUGIN_PATH=${GST_PLUGIN_PATH}PIPELINE="gst-launch-1.0 \ $SOURCE_ELEMENT ! decodebin ! \ gvainference model=$DETECT_MODEL_PATH device=$DEVICE ! queue ! \ gvapython module=$PYTHON_SCRIPT1 ! \ gvaclassify model=$CLASS_MODEL_PATH device=$DEVICE ! queue ! \ gvaclassify model=$EMOTION_MODEL_PATH device=$DEVICE ! queue ! \ gvapython module=$PYTHON_SCRIPT2 ! \ $SINK_ELEMENT"echo ${PIPELINE} PYTHONPATH=$PYTHONPATH:$(dirname "$0")/../../../../python \ ${PIPELINE}2022年 02月 22日 星期二 00:40:30 CST,添加line41行代碼。
EMOTION_MODEL_PATH=${MODELS_PATH}/intel/emotions-recognition-retail-0003/FP32/emotions-recognition-retail-0003.xml 2022年 02月 22日 星期二 00:56:06 CST,這相應(yīng)配置都修改了,運行怎么無效果呀???沒有情緒識別信息輸出。第八課動手實驗:整合實現(xiàn)AI應(yīng)用中的音視頻處理-在線測試
1.視頻+音頻處理實驗
實驗?zāi)繕?biāo)
你的任務(wù):
構(gòu)建一個包含視頻處理與音頻處理的pipeline流水線程序
在OV-300/08/目錄下,這些是你擁有的資源:
在/Models/目錄下
音頻檢測模型
/Models/audio_detection/FP16/aclnet.xml
目標(biāo)檢測模型
/Models/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.xml
object.list.yml
A list of objects to detect:目標(biāo)列表
sound.list.yml
A list of sounds to detect:聲音種類列表
Road.mp4
輸入MP4(包含了音頻+視頻)
audio_video_detect.py
用于音頻檢測的可用代碼
進(jìn)行實驗準(zhǔn)備
#初始化環(huán)境
export OV= (填寫你的答案)
export OV=/opt/intel/openvino_2021/
export WD=(填寫你的答案)
export WD=/home/dc2-user/OV-300/08
#初始化 OpenVINO
(填寫你的答案)
source $OV/bin/setupvars.sh
進(jìn)行實驗
#進(jìn)入實驗?zāi)夸?/p>
(填寫你的答案)cd $WD
#播放待檢測的視頻road.mp4
(填寫你的答案)show road.mp4
#編輯run.sh 來完成實驗?zāi)繕?biāo)
(填寫你的答案)vi run.sh
注:audio pipeline參考 /opt/intel/openvino_2021/data_processing/dl_streamer/samples/gst_launch/audio_detect/audio_event_detection.sh中截取你需要的音頻處理command line部分(注意模型和Json的名稱相對應(yīng)),來添加aclnet.xml的音頻檢測功能,粘貼至run.sh中。
video-decode-pipelide參考/opt/intel/openvino_2021/data_processing/dl_streamer/samples/gst_launch/vehicle_pedestrian_tracking/vehicle_pedestrian_tracking.sh來添加 person-vehicle-bike-detection-crossroad-0078模型的車輛行人識別功能。
/home/dc2-user/OV-300/08 tree羅列一下所有目錄、文件: dc2-user@10-0-255-63:~/OV-300/08$ pwd /home/dc2-user/OV-300/08 dc2-user@10-0-255-63:~/OV-300/08$ ll total 48780 drwxrwxr-x 5 dc2-user dc2-user 4096 Feb 22 02:08 ./ drwxrwxr-x 9 dc2-user dc2-user 4096 Nov 29 22:04 ../ -rw-rw-r-- 1 dc2-user dc2-user 3146 Nov 30 19:39 audio_video_detect.py drwxrwxr-x 4 dc2-user dc2-user 4096 Oct 25 11:32 Models/ -rw-rw-r-- 1 dc2-user dc2-user 64 Nov 30 18:41 object.list.yml -rw-rw-r-- 1 dc2-user dc2-user 1340 Oct 25 03:22 OV-300.08.How drwxrwxr-x 2 dc2-user dc2-user 4096 Feb 22 02:05 __pycache__/ -rw-rw-r-- 1 dc2-user dc2-user 49906354 Oct 25 03:22 road.mp4 -rw-rw-r-- 1 dc2-user dc2-user 1822 Feb 22 02:05 run.sh drwxrwxr-x 3 dc2-user dc2-user 4096 Nov 30 19:39 Solution/ -rw-rw-r-- 1 dc2-user dc2-user 72 Nov 30 18:40 sound.list.yml dc2-user@10-0-255-63:~/OV-300/08$ dc2-user@10-0-255-63:~/OV-300/08$ pwd /home/dc2-user/OV-300/08 dc2-user@10-0-255-63:~/OV-300/08$ tree -L 5 . ├── audio_video_detect.py ├── Models │ ├── audio_detection │ │ ├── aclnet.json │ │ └── FP16 │ │ ├── aclnet.bin │ │ ├── aclnet.mapping │ │ └── aclnet.xml │ └── person-vehicle-bike-detection-crossroad-0078 │ ├── FP16 │ │ ├── person-vehicle-bike-detection-crossroad-0078.bin │ │ └── person-vehicle-bike-detection-crossroad-0078.xml │ └── person-vehicle-bike-detection-crossroad-0078.json ├── object.list.yml ├── OV-300.08.How ├── __pycache__ │ └── audio_video_detect.cpython-36.pyc ├── road.mp4 ├── run.sh ├── Solution │ ├── audio_event_detection.sh │ ├── audio_video_detect.py │ ├── object.list.yml │ ├── __pycache__ │ │ └── audio_video_detect.cpython-36.pyc │ ├── run.sh │ ├── sound.list.yml │ └── starting-point-run.sh └── sound.list.yml8 directories, 21 files dc2-user@10-0-255-63:~/OV-300/08$
完成實驗
#請在完成run.sh后運行腳本,請把輸出結(jié)果保存到本地,名稱為“road.watermarked.mp4”:
(填寫你的答案)
bash run.sh road.mp4
#通過ffmpeg轉(zhuǎn)換成可播放的格式:
ffmpeg -i road.watermarked.mp4 output.mp4
#查看結(jié)果 你能看到視頻左上角會顯示偵測到聲音類型:
show output.mp4
注:請將output.mp4生成在~/OV-300/08/目錄下,以免影響實驗結(jié)果判定。實驗操作手冊的答案位于當(dāng)前文件夾下,名為OV-300.08.How文件。run.sh的代碼參考答案位于$WD/Solution/run.sh
/home/dc2-user/OV-300/08/OV-300.08.How
OpenVINO 300Lesson 08Lab 1 ============================================================================= Your task: Build a pipeline that will process both video and audioIn the directory you can find:under /Models/The audio detection model/Models/audio_detection/FP16/aclnet.xmlThe object detection model/Models/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.xmlobject.list.ymlA list of objects to detectsound.list.ymlA list of sounds to detectRoad.mp4Input (audio + Video)audio_video_detect.pypython script to add the audio detection to the GST-buffer =============================================================================1) Get startedexport OV=/opt/intel/openvino_2021/ export WD=~/OV-300/08/Initialize OpenVINO source $OV/bin/setupvars.shThis is the file to edit ---->>> your baseline is run.sh2) Copy the audio detection pipeline from the DL-streamer samples..vi /opt/intel/openvino_2021/data_processing/dl_streamer/samples/gst_launch/audio_detect/audio_event_detection.sh 3) Results could be found under Solutions directory ./Solution/run.sh Just copy to your directory and run You can see the result video in Road.watermarked.mp4 or displayed to screen (need to edit run.sh to change that selection)/home/dc2-user/OV-300/08/Solution/run.sh
#Copyright (C) 2018-2021 Intel Corporation#Licensed under the Apache License, Version 2.0 (the "License");INPUT=${WD}/road.mp4 AUDIO_MODEL=${WD}/Models/audio_detection/FP16/aclnet.xml AUDIO_MODEL_PROC=${WD}/Models/audio_detection/aclnet.jsonDETECTION_MODEL=${WD}/Models/person-vehicle-bike-detection-crossroad-0078/FP16/person-vehicle-bike-detection-crossroad-0078.xml DETECTION_MODEL_PROC=${WD}/Models/person-vehicle-bike-detection-crossroad-0078/person-vehicle-bike-detection-crossroad-0078.jsongst-launch-1.0 uridecodebin uri=file:${INPUT} name=front_end \ front_end. ! queue ! \ audioresample ! audioconvert ! audio/x-raw, channels=1,format=S16LE,rate=16000 ! audiomixer output-buffer-duration=100000000 ! \ gvaaudiodetect model=$AUDIO_MODEL model-proc=$AUDIO_MODEL_PROC sliding-window=0.2 !\ gvametaconvert ! gvametapublish file-format=json-lines file-path=/tmp/audio_event_stream ! audioconvert !\ fakesink \ front_end. ! queue ! \ gvadetect model=$DETECTION_MODEL model-proc=$DETECTION_MODEL_PROC ! \ gvapython module=${WD}/audio_video_detect.py class=AudioEventWatermark ! \ videoconvert ! gvawatermark ! videoconvert ! avenc_mpeg4!\ mpegtsmux ! filesink location=road.watermarked.mp4#===> for saving the output to a file #gvawatermark ! videoconvert ! x264enc key-int-max=30 speed-preset=fast tune=zerolatency !\ #mpegtsmux ! filesink location=Road.watermarked.mp4#Replace the last 2 lines with this line to present the video to screen. #videoconvert ! gvawatermark ! ximagesink
2022年 02月 22日 星期二 02:31:27 CST,OK,實驗完成!全部實驗完成!
BEGIN:2022-02-20 23:53:49
END:2022年 02月 22日 星期二 02:31:27 CST
OpenVINO高級課程結(jié)業(yè)證書
您已完成 “英特爾? OpenVINO?工具套件高級課程” 學(xué)習(xí)
恭喜您獲得“英特爾? OpenVINO?工具套件高級課程 ”專屬證書!證書編號:L0102022022201041003,您可以在CSDN官網(wǎng)查詢,查詢地址:https://edu.csdn.net/cert?username=u014132947 。
Ok完成
總結(jié)
以上是生活随笔為你收集整理的英特尔OpenVINO工具套件高级课程实验操作记录与学习总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 视频教程-MVC+EF+LayUI框架的
- 下一篇: Tomcat之Directory Lis