作者:黃明明 英特爾邊緣計(jì)算創(chuàng)新大使
英特爾 發(fā)行版 OpenVINO 工具套件基于 oneAPI 而開發(fā),可以加快高性能計(jì)算機(jī)視覺和深度學(xué)習(xí)視覺應(yīng)用開發(fā)速度工具套件,適用于從邊緣到云的各種英特爾平臺(tái)上,幫助用戶更快地將更準(zhǔn)確的真實(shí)世界結(jié)果部署到生產(chǎn)系統(tǒng)中。通過簡化的開發(fā)工作流程, OpenVINO 可賦能開發(fā)者在現(xiàn)實(shí)世界中部署高性能應(yīng)用程序和算法。
Java 是一門面向?qū)ο蟮?a target="_blank">編程語言,不僅吸收了 C++ 語言的各種優(yōu)點(diǎn),還摒棄了 C++ 里難以理解的多繼承、指針等概念,因此 Java 語言具有功能強(qiáng)大和簡單易用兩個(gè)特征。Java 語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實(shí)現(xiàn)了面向?qū)ο罄碚?,允許程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程。
雖然 OpenVINO 在 [OpenVINO Contrilb][1]提供了 Ubuntu 版本的 api,但由于使用 JNI 技術(shù),這對(duì)于沒有涉及 C/C++ 編程的開發(fā)者并不是特別的友好,且后期的維護(hù)更新也帶來了不小的麻煩。
在之前的工作中,我們推出了 OpenVINO Java API ,旨在推動(dòng) OpenVINO 在 Java 領(lǐng)域的應(yīng)用,目前已經(jīng)成功在 Mac、Windows、Linux 平臺(tái)實(shí)現(xiàn)使用。在本文中,我們將介紹如何在英特爾開發(fā)套件 AIxBoard 上基于 Linux 系統(tǒng)實(shí)現(xiàn) OpenVINO Java API。
項(xiàng)目中所使用的代碼已上傳至 OpenVINO Java API 倉庫中,GitHub 網(wǎng)址為:
https://github.com/Hmm466/OpenVINO-Java-API
(復(fù)制鏈接到瀏覽器打開)
1. 英特爾開發(fā)套件 AIxBoard 介紹
1.1產(chǎn)品定位
英特爾開發(fā)套件 AIxBoard 是英特爾開發(fā)套件官方序列中的一員,專為入門級(jí)人工智能應(yīng)用和邊緣智能設(shè)備而設(shè)計(jì)。英特爾開發(fā)套件 AIxBoard 能完美勝人工智能學(xué)習(xí)、開發(fā)、實(shí)訓(xùn)、應(yīng)用等不同應(yīng)用場景。該套件預(yù)裝了英特爾 OpenVINO 工具套件、模型倉庫和演示。
套件主要接口與 Jetson Nano 載板兼容,GPIO 與樹莓派兼容,能夠最大限度地復(fù)用成熟的生態(tài)資源。這使得套件能夠作為邊緣計(jì)算引擎,為人工智能產(chǎn)品驗(yàn)證和開發(fā)提供強(qiáng)大支持;同時(shí),也可以作為域控核心,為機(jī)器人產(chǎn)品開發(fā)提供技術(shù)支撐。
使用英特爾開發(fā)套件 AIxBoard,您將能夠在短時(shí)間內(nèi)構(gòu)建出一個(gè)出色的人工智能應(yīng)用應(yīng)用程序。無論是用于科研、教育還是商業(yè)領(lǐng)域,英特爾開發(fā)套件 AIxBoard 都能為您提供良好的支持。借助 OpenVINO 工具套件,CPU、iGPU 都具備強(qiáng)勁的 AI 推理能力,支持在圖像分類、目標(biāo)檢測、分割和語音處理等應(yīng)用中并行運(yùn)行多個(gè)神經(jīng)網(wǎng)絡(luò)。
1.2產(chǎn)品參數(shù)
1.3AI 推理單元
借助 OpenVINO 工具,能夠?qū)崿F(xiàn) CPU+iGPU 異構(gòu)計(jì)算推理,IGPU 算力約為 0.6TOPS。
2準(zhǔn)備工作
2.1
配置 java 環(huán)境
下載并配置 JDK:
JDK(Java Development Kit)稱為 Java 開發(fā)包或 Java 開發(fā)工具,是一個(gè)編寫 Java 的 Applet 小程序和應(yīng)用程序的程序開發(fā)環(huán)境。JDK 是整個(gè) Java 的核心,包括了 Java 運(yùn)行環(huán)境(Java Runtime Environment),一些 Java 工具和 Java 的核心類庫(Java API)。不論什么 Java 應(yīng)用服務(wù)器實(shí)質(zhì)都是內(nèi)置了某個(gè)版本的 JDK。主流的 JDK 是 Sun 公司發(fā)布的 JDK,除了 Sun 之外,還有很多公司和組織都開發(fā)了自己的 JDK。
2.1.1添加 api 到本地 maven
添加 OpenVINO Java API 至 Maven(目前沒有在 maven 中央倉庫發(fā)布,所以需要手動(dòng)安裝)
2.1.2clone OpenVINO Java API 項(xiàng)目到本地
java git clone https://github.com/Hmm466/OpenVINO-Java-API
左滑查看更多
2.1.3通過 IDEA 或 Eclipse 打開
通過 maven install 到本地 maven 庫中
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 14.647 s [INFO] Finished at: 2023-11-02T21:34:49+08:00 [INFO] ------------------------------------------------------------------------
左滑查看更多
jar 包會(huì)放置在:
/{userHome}/.m2/repository/org/openvino/java-api/1.0-SNAPSHOT/java-api-1.0-SNAPSHOT.pom
2.2安裝 OpenVINO Runtime
OpenVINO 有兩種安裝方式: OpenVINO Runtime 和 OpenVINO Development Tools。
OpenVINO Runtime 包含用于在處理器設(shè)備上運(yùn)行模型部署推理的核心庫。OpenVINO Development Tools 是一組用于處理 OpenVINO 和 OpenVINO 模型的工具,包括模型優(yōu)化器、OpenVINO Runtime、模型下載器等。在此處我們只需要安裝 OpenVINO Runtime 即可。
2.2.1下載 OpenVINO Runtime
訪問 Download the Intel Distribution of OpenVINO Toolkit 頁面,按照下面流程選擇相應(yīng)的安裝選項(xiàng),在下載頁面,由于 AIxBoard 使用的是 Ubuntu20.04,因此下載時(shí)按照指定的編譯版本下載即可。
2.2.2解壓縮安裝包
我們所下載的 OpenVINO Runtime 本質(zhì)是一個(gè) C++ 依賴包,因此我們把它放到我們的系統(tǒng)目錄下,這樣在編譯時(shí)會(huì)根據(jù)設(shè)置的系統(tǒng)變量獲取依賴項(xiàng)。
shell cd ~/Downloads/ tar -xvzf l_openvino_toolkit_ubuntu20_2022.3.1.9227.cf2c7da5689_x86_64.tgz sudo mv l_openvino_toolkit_ubuntu20_2022.3.1.9227.cf2c7da5689_x86_64/runtime/lib/intel64/* /usr/lib/
左滑查看更多
2.3編譯 OpenCV java 庫
2.3.1下載 ANT
由于 OpenCV 編譯出 libopencv_java{version}.[so|dll|dylib] 需要 apache ant 的支持,所以需要手動(dòng)下載ant[2]并加入環(huán)境變量
shell export ANT_HOME={ant_home} export PATH=$ANT_HOME/bin:$PATH
左滑查看更多
2.3.2OpenCV[3] 下載源代碼
解壓縮之后進(jìn)入文件夾:
shell mkdir build cd build cmake -DBUILD_SHARED_LIBS=OFF -DWITH_IPP=OFF -DBUILD_ZLIB=OFF -DCMAKE_INSTALL_PREFIX=你的opencv目錄 -DJAVA_INCLUDE_PATH={jdk 所在位置}/include -DJAVA_AWT_INCLUDE_PATH={jdk 所在位置}/include -DJAVA_INCLUDE_PATH2={jdk 所在位置}/include -DBUILD_JAVA=ON ..
左滑查看更多
注意看輸出有沒有:
-- Java: -- ant: -- JNI: -- Java wrappers: -- Java tests:
左滑查看更多
需要不為 NO 或者有目錄,然后編譯安裝:
shell make -j 8 make install
左滑查看更多
3在 AIxBoard 上進(jìn)行測試
3.1源代碼直接測試
shell git clone https://github.com/Hmm466/OpenVINO-Java-API
左滑查看更多
-使用IDEA / Eclipse 打開項(xiàng)目
- 運(yùn)行
src/test/java/org.openvino.java.test.YoloV8Test
3.2創(chuàng)建其他項(xiàng)目進(jìn)行測試
創(chuàng)建一個(gè) AlxBoardDeployYolov8 Maven 項(xiàng)目
創(chuàng)建完成之后引用我們剛剛 install 的 OpenVINO-Java-API,或者直接 clone 項(xiàng)目直接修改體驗(yàn)
maven 引用:
mavenorg.openvino java-api 1.0-SNAPSHOT
【注意】如果才用 maven 依賴需要注意 opencv 的庫引用問題.可以將 OpenVINO-Java-API/libs 的 opencv 庫引用到你的項(xiàng)目下
編寫測試代碼:
java OpenVINO vino = OpenVINO.load(); OvVersion version = vino.getVersion(); Console.println("---- OpenVINO INFO----"); Console.println("Description : %s", version.description); Console.println("Build number: %s", version.buildNumber);
左滑查看更多
結(jié)果將輸出:
text ---- OpenVINO INFO---- Description : OpenVINO Runtime Build number: 2023.2.0-12538-e7c1344d3c3 det text Description : OpenVINO Runtime Build number: 2023.2.0-12538-e7c1344d3c3 [INFO] Loading model files: model/yolov8/yolov8s.xml [INFO] model name: torch_jit [INFO] inputs: [INFO] input name: images [INFO] input type: Node [INFO] input shape: Shape{, rank=4, dims=1,3,640,640} [INFO] outputs: [INFO] output name: output0 [INFO] output type: Node [INFO] output shape: Shape{, rank=3, dims=1,84,8400} [INFO] Read image files: dataset/image/demo_2.jpg Detection result : 1: 0 0.92775315 {0, 304, 268x519} 2: 0 0.90614283 {632, 97, 615x725} 3: 0 0.9032028 {286, 198, 190x591} 4: 62 0.902739 {258, 164, 446x284} 5: 0 0.80478114 {739, 262, 123x229} 6: 0 0.7890141 {891, 314, 231x226} 7: 63 0.7383257 {532, 518, 260x275} 8: 63 0.7148062 {861, 448, 90x86} 9: 56 0.5889373 {102, 614, 185x216} 10: 0 0.4642688 {1006, 315, 116x159} 11: 63 0.43404874 {987, 483, 104x126} 12: 63 0.38955435 {892, 480, 202x196} 13: 62 0.30369592 {961, 384, 87x81}
左滑查看更多
seg text ---- OpenVINO INFO---- Description : OpenVINO Runtime Build number: 2023.2.0-12538-e7c1344d3c3 [INFO] Loading model files: model/yolov8/yolov8s-seg.xml [INFO] model name: torch_jit [INFO] inputs: [INFO] input name: images [INFO] input type: Node [INFO] input shape: Shape{, rank=4, dims=1,3,640,640} [INFO] outputs: [INFO] output name: output0 [INFO] output type: Node [INFO] output shape: Shape{, rank=3, dims=1,116,8400} [INFO] Read image files: dataset/image/demo_2.jpg Segmentation result : 1: 0 0.9207011 {0, 66, 439x801} 2: 0 0.91634876 {403, 151, 339x721} 3: 63 0.9086068 {37, 460, 388x231} 4: 56 0.74821126 {878, 517, 146x265} 5: 0 0.37459317 {679, 331, 91x263} 6: 0 0.31526685 {641, 345, 45x39}
左滑查看更多
pose text ---- OpenVINO INFO---- Description : OpenVINO Runtime Build number: 2023.2.0-12538-e7c1344d3c3 [INFO] Loading model files: model/yolov8/yolov8s.xml [INFO] model name: torch_jit [INFO] inputs: [INFO] input name: images [INFO] input type: Node [INFO] input shape: Shape{, rank=4, dims=1,3,640,640} [INFO] outputs: [INFO] output name: output0 [INFO] output type: Node [INFO] output shape: Shape{, rank=3, dims=1,84,8400} [INFO] Read image files: dataset/image/demo_2.jpg Classification result : 1: 1 0.9001118 {407, 151, 334x722} Nose: (0.0 ,0.0 ,3.4155396E-6) Left Eye: (0.0 ,0.0 ,6.0583807E-6) Right Eye: (0.0 ,0.0 ,3.7476743E-6) Left Ear: (0.0 ,0.0 ,3.2295986E-6) Right Ear: (0.0 ,0.0 ,1.7464492E-6) Left Shoulder: (0.0 ,0.0 ,2.5992335E-6) Right Shoulder: (0.0 ,0.0 ,3.937065E-6) Left Elbow: (0.0 ,0.0 ,7.936895E-6) Right Elbow: (0.0 ,0.0 ,2.3217426E-6) Left Wrist: (0.0 ,0.0 ,3.6387396E-6) Right Wrist: (0.0 ,0.0 ,4.40427E-6) Left Hip: (0.0 ,0.0 ,1.940609E-6) Right Hip: (0.0 ,0.0 ,3.770945E-6) Left Knee: (0.0 ,0.0 ,2.4128974E-6) Right Knee: (0.0 ,0.0 ,3.424496E-6) Left Ankle: (0.0 ,0.0 ,7.5513196E-7) Right Ankle: (0.0 ,0.0 ,4.3359764E-6) 2: 1 0.8558029 {0, 65, 441x802} Nose: (0.0 ,0.0 ,5.9377476E-7) Left Eye: (0.0 ,0.0 ,7.104497E-6) Right Eye: (0.0 ,0.0 ,1.319968E-6) Left Ear: (0.0 ,0.0 ,6.459948E-7) Right Ear: (0.0 ,0.0 ,4.0330252E-7) Left Shoulder: (0.0 ,0.0 ,1.5084498E-7) Right Shoulder: (0.0 ,0.0 ,6.642805E-7) Left Elbow: (0.0 ,0.0 ,2.447048E-6) Right Elbow: (0.0 ,0.0 ,2.463981E-7) Left Wrist: (0.0 ,0.0 ,3.8335997E-7) Right Wrist: (0.0 ,0.0 ,3.6232507E-7) Left Hip: (0.0 ,0.0 ,3.2433576E-7) Right Hip: (0.0 ,0.0 ,7.913691E-7) Left Knee: (0.0 ,0.0 ,4.720929E-7) Right Knee: (0.0 ,0.0 ,4.3835226E-7) Left Ankle: (0.0 ,0.0 ,1.2476052E-7) Right Ankle: (0.0 ,0.0 ,4.4775015E-7) 3: 1 0.60723305 {678, 333, 95x259} Nose: (0.0 ,0.0 ,8.775595E-7) Left Eye: (0.0 ,0.0 ,7.137654E-7) Right Eye: (0.0 ,0.0 ,1.2003383E-6) Left Ear: (0.0 ,0.0 ,8.495165E-7) Right Ear: (0.0 ,0.0 ,5.2003993E-6) Left Shoulder: (0.0 ,0.0 ,3.1942466E-7) Right Shoulder: (0.0 ,0.0 ,1.1035459E-6) Left Elbow: (0.0 ,0.0 ,5.3546346E-6) Right Elbow: (0.0 ,0.0 ,1.7979652E-6) Left Wrist: (0.0 ,0.0 ,8.755582E-7) Right Wrist: (0.0 ,0.0 ,6.6855574E-7) Left Hip: (0.0 ,0.0 ,4.0984042E-7) Right Hip: (0.0 ,0.0 ,7.5307044E-6) Left Knee: (0.0 ,0.0 ,9.537544E-7) Right Knee: (0.0 ,0.0 ,7.810681E-8) Left Ankle: (0.0 ,0.0 ,3.2538756E-7) Right Ankle: (0.0 ,0.0 ,1.2676019E-6) 4: 1 0.38707685 {1277, 740, 44x138} Nose: (0.0 ,0.0 ,1.074906E-4) Left Eye: (0.0 ,0.0 ,3.1907311E-6) Right Eye: (0.0 ,0.0 ,9.670388E-6) Left Ear: (0.0 ,0.0 ,4.4663593E-6) Right Ear: (0.0 ,0.0 ,0.0025005206) Left Shoulder: (0.0 ,0.0 ,4.032511E-5) Right Shoulder: (0.0 ,0.0 ,2.5534397E-5) Left Elbow: (0.0 ,0.0 ,0.0043662274) Right Elbow: (0.0 ,0.0 ,4.32287E-5) Left Wrist: (0.0 ,0.0 ,8.4830776E-7) Right Wrist: (0.0 ,0.0 ,5.0576923E-6) Left Hip: (0.0 ,0.0 ,1.1178828E-5) Right Hip: (0.0 ,0.0 ,2.2293802E-5) Left Knee: (0.0 ,0.0 ,3.1517664E-6) Right Knee: (0.0 ,0.0 ,8.923516E-5) Left Ankle: (0.0 ,0.0 ,5.5582723E-6) Right Ankle: (0.0 ,0.0 ,2.206743E-6)
左滑查看更多
cls text ---- OpenVINO INFO---- Description : OpenVINO Runtime Build number: 2023.2.0-12538-e7c1344d3c3 [INFO] Loading model files: model/yolov8/yolov8s.xml [INFO] model name: torch_jit [INFO] inputs: [INFO] input name: images [INFO] input type: Node [INFO] input shape: Shape{, rank=4, dims=1,3,640,640} [INFO] outputs: [INFO] output name: output0 [INFO] output type: Node [INFO] output shape: Shape{, rank=3, dims=1,84,8400} [INFO] Read image files: dataset/image/demo_2.jpg Classification Top 10 result : classid probability ------- ----------- {14789} {635.549438} {3679} {635.543701} {14788} {635.522583} {14731} {635.518616} {14730} {635.513428} {3839} {635.502441} {14790} {635.497314} {14732} {635.489258} {14781} {635.486694} {14739} {635.484985}
左滑查看更多
4總結(jié)
在該項(xiàng)目中,我們基于 AIxBoard 為硬件基礎(chǔ)實(shí)現(xiàn)了 Java 在 Ubuntu 22.04 系統(tǒng)上成功使用 OpenVINO Java API,并且成功允許了 Yolov8 模型,驗(yàn)證了 Java 運(yùn)行的可行性,并簡化了 Java 開發(fā)者對(duì)于 AI 類項(xiàng)目的上手難度。
同時(shí) OpenVINO Java API 已完成了 Mac、Linux、Windows 的測試,Windows 平臺(tái)的文檔也正在輸出。后續(xù)我還會(huì)將繼續(xù)使用 OpenVINO Java API 在 英特爾開發(fā)套件 AIxBoard 部署更多的深度學(xué)習(xí)模型。
審核編輯:湯梓紅
-
英特爾
+關(guān)注
關(guān)注
61文章
9967瀏覽量
171796 -
JAVA
+關(guān)注
關(guān)注
19文章
2967瀏覽量
104763 -
邊緣計(jì)算
+關(guān)注
關(guān)注
22文章
3092瀏覽量
48972 -
OpenVINO
+關(guān)注
關(guān)注
0文章
93瀏覽量
203
原文標(biāo)題:OpenVINO? Java API 詳解與演示|開發(fā)者實(shí)戰(zhàn)
文章出處:【微信號(hào):英特爾物聯(lián)網(wǎng),微信公眾號(hào):英特爾物聯(lián)網(wǎng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論