FPGA上利用Vitis AI部署resnet50 TensorFlow神經(jīng)網(wǎng)絡(luò)模型
參考Xilinx官方教程快速入門 ? Vitis AI 用戶指南 (UG1414)
克隆 Vitis AI 存儲庫以獲取示例、參考代碼和腳本(連接github失敗可能需要科學(xué)上網(wǎng))。
[Host]$ git clone https://github.com/Xilinx/Vitis-AI
[Host]$ cd Vitis-AI
安裝Docker如何在 Ubuntu 20.04 上安裝和使用 Docker
安裝完docker后,下載最新Vitis AI Docker,
Host]$ docker pull xilinx/vitis-ai-<pytorch/tensorflow/tensorflow2>-cpu:latest
將官方的指令docker pull xilinx/vitis-ai-<pytorch/tensorflow/tensorflow2>-cpu:latest
改為docker pull xilinx/vitis-ai-tensorflow2-cpu:latest
,從tensorflow,pytorch,tensorflow2
中三選一。遇到問題permission denied
如下,
將當(dāng)前用戶添加到用戶組,解決docker權(quán)限問題,運行的命令如下:
sudo groupadd docker #添加用戶組
sudo gpasswd -a username docker #將當(dāng)前用戶添加至用戶組,username寫自己的用戶名
newgrp docker #更新用戶組
使用git checkout v3.0
切換到3.0
版本
運行以下命令安裝交叉編譯系統(tǒng)環(huán)境
[Host]$ ./host_cross_compiler_setup.sh
如果提示host_cross_compiler_setup.sh找不到命令
,需要使用chmod
命令修改文件權(quán)限,使文件可執(zhí)行
安裝完交叉編譯鏈后,有如下提示:
Please run the following command to enable Cross Compiler
source /root/petalinux_sdk_2022.2/environment-setup-cortexa72-cortexa53-xilinx-linux
If you run the above command failed, run the following commands to enable Cross Compiler
unset LD_LIBRARY_PATH
source /root/petalinux_sdk_2022.2/environment-setup-cortexa72-cortexa53-xilinx-linux
下載并設(shè)置開發(fā)板鏡像 Design License Agreement (XEF) (xilinx.com)
使用Etcher將鏡像文件燒寫到SD卡上,將含鏡像的SD卡插入目標(biāo)開發(fā)板,通電并使用串行端口啟動開發(fā)板以在系統(tǒng)上進行操作,使用串行端口來設(shè)置開發(fā)板的IP信息(ifconfig
)。
下載tensorflow resnet50 模型
[Host]$ cd Vitis-AI
[Host]$ wget https://www.xilinx.com/bin/public/openDownload?filename=tf_resnetv1_50_imagenet_224_224_6.97G_3.0.zip -O tf_resnetv1_50_imagenet_224_224_6.97G_.0.zip
[Host]$ unzip tf_resnetv1_50_imagenet_224_224_6.97G_3.0.zip
量化模型
量化模型時 ,從 Imagenet_calib.tar.gz下載數(shù)據(jù)集,并復(fù)制到 Vitis-AI 文件夾中
啟動 Docker 鏡像./docker_run.sh xilinx/vitis-ai-tensorflow-cpu:latest
在 tf_resnetv1_50_imagenet_224_224_6.97G_3.0/code/quantize/config.ini 中,將 CALIB_BATCH_SIZE 設(shè)置為 5。然后運行
[Docker]$ conda activate vitis-ai-tensorflow
[Docker]$ tar -xzvf Imagenet_calib.tar.gz -C tf_resnetv1_50_imagenet_224_224_6.97G_3.0/data
[Docker]$ cd tf_resnetv1_50_imagenet_224_224_6.97G_3.0/code/quantize
[Docker]$ bash quantize.sh
量化需要1個小時45分鐘, 運行 quantize.sh 后,已量化的模型包含在 tf_resnetv1_50_imagenet_224_224_6.97G_3.0/quantized 中
編譯模型
vai_c_tensorflow -f ./quantized/quantized_baseline_6.96B_919.pb -a /opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json -o ./compiled -n resnet50_tf
修改ipv4的網(wǎng)絡(luò)配置,輸入命令sudo vim /etc/network/interfaces
,編輯文件
重啟網(wǎng)絡(luò)服務(wù):
sudo /etc/init.d/networking force-reload
sudo /etc/init.d/networking restart
此時IPv4的地址已經(jīng)修改成功,可以和主機ping通。
將已經(jīng)編譯的模型復(fù)制到開發(fā)板上,要求輸入root的密碼,密碼為root
scp tf_resnetv1_50_imagenet_224_224_6.97G_3.0/compiled/resnet50_tf.xmodel root@[BOARD_IP]:~
下載 vitis_ai_runtime_r3.0.0_image_video.tar.gz 測試圖,通過MobaXterm
發(fā)送到開發(fā)板上,并在目標(biāo)邊緣平臺上解壓將下載好的測試圖片。
解壓圖片壓縮包tar -xzvf vitis_ai_runtime_r3.0.0_image_video.tar.gz -C Vitis-AI/examples/vai_runtime
文章來源:http://www.zghlxwxcb.cn/news/detail-755997.html
運行 resnet50 示例
cd ~/Vitis-AI/examples/vai_runtime/resnet50
./resnet50 ~/resnet50_tf.xmodel
運行結(jié)果:文章來源地址http://www.zghlxwxcb.cn/news/detail-755997.html
到了這里,關(guān)于FPGA上利用Vitis AI部署resnet50 TensorFlow神經(jīng)網(wǎng)絡(luò)模型的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!