Vitis AIをやってみる(メモ)

次のURLを参考にVitis AIをやってみます。

https://github.com/Xilinx/Vitis-AI/tree/master/tools/Vitis-AI-Library

本試行はZCU104で実機検証を行っています。

ホストのセットアップ

次のSDKをダウンロードします。

https://www.xilinx.com/bin/public/openDownload?filename=sdk-2020.2.0.0.sh

ダウンロード後、実行しましょう。

$ sudo ./sdk-2020.2.0.0.sh 
PetaLinux SDK installer version 2020.2
======================================
Enter target directory for SDK (default: /opt/petalinux/2020.2): 
You are about to install the SDK to "/disk/opt/petalinux/2020.2". Proceed [Y/n]? 
Extracting SDK...................................................................................................................................................................................................................done
Setting it up...done
SDK has been successfully set up and is ready to be used.
Each time you wish to use the SDK in a new shell session, you need to source the environment setup script e.g.
 $ . /disk/opt/petalinux/2020.2/environment-setup-aarch64-xilinx-linux

環境のセットアップ

環境をセットアップします。

$ source /opt/petalinux/2020.2/environment-setup-aarch64-xilinx-linux

Vitis AIのインストール

次のURLをダウンロードして展開します。

https://www.xilinx.com/bin/public/openDownload?filename=vitis_ai_2020.2-r1.3.0.tar.gz

$ sudo tar xvf vitis_ai_2020.2-r1.3.0.tar.gz -C /opt/petalinux/2020.2/sysroots/aarch64-xilinx-linux

デモ

デモ環境を構築します。

まず、次のようにgithubからcloneします。

$ git clone https://github.com/Xilinx/Vitis-AI.git

ここではfacedetectをやってみます。

次のようにビルドします。

$ cd ./Vitis-AI/demo/Vitis-AI-Library/samples/facedetect
$ bash -x build.sh

ターゲット

次のURLからSDカードイメージをダウンロードします。

https://www.xilinx.com/bin/public/openDownload?filename=xilinx-zcu104-dpu-v2020.2-v1.3.0.img.gz

次のように展開します。

$ gzip -d xilinx-zcu104-dpu-v2020.2-v1.3.0.img.gz

SDカードにイメージを書き込みます。 ここで書き込み先の/dev/sdaの指定には注意してください。

$ sudo dd if=xilinx-zcu104-dpu-v2020.2-v1.3.0.img of=/dev/sda

起動

SDカードをZCU104に差し込んで起動します。

Release 2020.2   Dec 13 2020  -  12:50:15                                       
NOTICE:  ATF running on XCZU7EV/silicon v4/RTL5.1 at 0xfffea000                 
NOTICE:  BL31: v2.2(release):xilinx_rebase_v2.2_2020.1-10-ge6eea88b1            
NOTICE:  BL31: Built : 12:47:33, Dec 13 2020                                    


U-Boot 2020.01 (Dec 13 2020 - 12:48:42 +0000)                                   

Model: ZynqMP ZCU104 RevC                                                       
Board: Xilinx ZynqMP                                                            
DRAM:  2 GiB                                                                    
PMUFW:  v1.1                                                                    
EL Level:       EL2                                                             
Chip ID:        zu7ev                                                           
NAND:  0 MiB                                                                    
MMC:   mmc@ff170000: 0                                                          
Loading Environment from FAT... *** Warning - bad CRC, using default environment

In:    serial@ff000000                                                          
Out:   serial@ff000000                                                          
Err:   serial@ff000000                                                          
Bootmode: LVL_SHFT_SD_MODE1                                                     
Reset reason:   EXTERNAL                                                        
Net:                                                                            
ZYNQ GEM: ff0e0000, mdio bus ff0e0000, phyaddr 12, interface rgmii-id           

Warning: ethernet@ff0e0000 using MAC address from DT                            
eth0: ethernet@ff0e0000                                                         
Hit any key to stop autoboot:  0                                                
switch to partitions #0, OK                                                     
mmc0 is current device                                                          
Scanning mmc 0:1...                                                             
Found U-Boot script /boot.scr                                                   
2007 bytes read in 14 ms (139.6 KiB/s)                                          
## Executing script at 20000000                                                 
21492224 bytes read in 1601 ms (12.8 MiB/s)                                     
36487 bytes read in 21 ms (1.7 MiB/s)                                           
## Flattened Device Tree blob at 00100000                                       
   Booting using the fdt blob at 0x100000                                       
   Loading Device Tree to 000000000fff4000, end 000000000ffffe86 ... OK         

Starting kernel ...                                                             

INIT: version 2.88 booting                                                      
Starting udev                                                                   
Sun Dec 13 13:05:27 UTC 2020                                                    
chown: cannot access '/var/log/wtmp': No such file or directory                 
Failed to set owner -root- for -/var/log/wtmp-.                                 
Configuring packages on first boot....                                          
 (This may take several minutes. Please do not power off the machine.)          
Running postinst /etc/rpm-postinsts/100-libmali-xlnx...                         
Running postinst /etc/rpm-postinsts/101-xrt...                                  
Running postinst /etc/rpm-postinsts/102-sysvinit-inittab...                     
Running postinst /etc/rpm-postinsts/103-zocl...                                 
update-rc.d: /etc/init.d/run-postinsts exists during rc.d purge (continuing)    
 Removing any system startup links for run-postinsts ...                        
INIT: Entering runlevel: 5                                                      
Configuring network interfaces... udhcpc: started, v1.31.0                      
udhcpc: sending discover                                                        
udhcpc: sending select for 192.168.1.207                                        
udhcpc: lease of 192.168.1.207 obtained, lease time 86400                       
/etc/udhcpc.d/50default: Adding DNS 192.168.1.1                                 
done.                                                                           
Starting system message bus: dbus.                                              
Starting haveged: haveged: listening socket at 3                                
haveged: haveged starting up                                                    


Starting Xserver                                                                
Starting Dropbear SSH server: Generating 2048 bit rsa key, this may take a whil.


X.Org X Server 1.20.5                                                           
X Protocol Version 11, Revision 0                                               
Build Operating System: Linux 3.10.0-693.el7.x86_64 x86_64                      
Current Operating System: Linux xilinx-zcu104-2020_2 5.4.0-xilinx-v2020.2 #1 SM4
Kernel command line: earlycon console=ttyPS0,115200 clk_ignore_unused root=/devM
Build Date: 15 November 2020  12:58:03PM                                        

Current version of pixman: 0.38.4                                               
        Before reporting problems, check http://wiki.x.org                      
        to make sure that you have the latest version.                          
Markers: (--) probed, (**) from config file, (==) default setting,              
        (++) from command line, (!!) notice, (II) informational,                
        (WW) warning, (EE) error, (NI) not implemented, (??) unknown.           
(==) Log file: "/var/log/Xorg.0.log", Time: Sun Dec 13 13:05:34 2020            
(==) Using config file: "/etc/X11/xorg.conf"                                    
(==) Using system config directory "/usr/share/X11/xorg.conf.d"                 
haveged: haveged: ver: 1.9.5; arch: generic; vend: ; build: (gcc 9.2.0 CTV); coK

haveged: haveged: cpu: (VC); data: 16K (D); inst: 16K (D); idx: 11/40; sz: 15452

haveged: haveged: tot tests(BA8): A:1/1 B:1/1 continuous tests(B):  last entrop2

haveged: haveged: fills: 0, generated: 0                                        

The XKEYBOARD keymap compiler (xkbcomp) reports:                                
> Warning:          Unsupported high keycode 372 for name <I372> ignored        
>                   X11 cannot support keycodes above 255.                      
>                   This warning only shows for the first high keycode.         
Errors from xkbcomp are not fatal to the X server                               
D-BUS per-session daemon address is: unix:abstract=/tmp/dbus-jQcwpvu7Yo,guid=681
matchbox: Cant find a keycode for keysym 269025056                              
matchbox: ignoring key shortcut XF86Calendar=!$contacts                         

matchbox: Cant find a keycode for keysym 2809                                   
matchbox: ignoring key shortcut telephone=!$dates                               

matchbox: Cant find a keycode for keysym 269025050                              
matchbox: ignoring key shortcut XF86Start=!matchbox-remote -desktop             

dbus-daemon[1023]: Activating service name='org.a11y.atspi.Registry' requested )
dbus-daemon[1023]: Successfully activated service 'org.a11y.atspi.Registry'     
SpiRegistry daemon is running with well-known name - org.a11y.atspi.Registry    
[settings daemon] Forking. run with -n to prevent fork                          
Public key portion is:                                                          
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDnQSopmgu9B+bVY7OgI7W2cgHMgQTTYjQVTIAT1Gk2
Fingerprint: sha1!! 81:c2:d0:03:e3:de:2d:ae:6c:fe:06:70:a1:55:c7:35:73:34:46:75 
dropbear.                                                                       
Starting rpcbind daemon...done.                                                 
starting statd: done                                                            

** (matchbox-desktop:1015): WARNING **: 13:05:38.672: Error loading icon: Icon o

** (matchbox-desktop:1015): WARNING **: 13:05:38.699: Error loading icon: Icon o
Starting internet superserver: inetd.                                           
exportfs: can't open /etc/exports for reading                                   
NFS daemon support not enabled in kernel                                        
Starting syslogd/klogd: done                                                    
Starting internet superserver: xinetd.                                          
Starting watchdog daemon...done                                                 
Warning: Partition /dev/mmcblk0p2 is being used. Are you sure you want to       
continue?                                                                       
Information: You may need to update /etc/fstab.                                 

resize2fs 1.45.3 (14-Jul-2019)                                                  
Filesystem at /dev/mmcblk0p2 is mounted on /media/sd-mmcblk0p2; on-line resizind
old_desc_blocks = 2, new_desc_blocks = 2                                        
The filesystem on /dev/mmcblk0p2 is now 3639424 (4k) blocks long.               

Auto resize ext4 partition ...[�✔]                                              
Start QoS config ...[�✔]                                                        
Config PMIC irps5401 ...Successful                                              
[�✔]                                                                            
Starting tcf-agent: OK                                                          

PetaLinux 2020.2 xilinx-zcu104-2020_2 ttyPS0                                    


root@xilinx-zcu104-2020_2:~# 

BoardのOptimaizeの実行

次のようにOptimizeを実行します。

root@xilinx-zcu104-2020_2:~# cd ~/dpu_sw_optimize/zynqmp/                       
root@xilinx-zcu104-2020_2:~/dpu_sw_optimize/zynqmp# ./zynqmp_dpu_optimize.sh    
Auto resize ext4 partition ...[�✔]                                              
Start QoS config ...[�✔]                                                        
Config PMIC irps5401 ...[�✔]                                                    

Vitis AI Model のアップデート

次のようにModelをアップデートします。

root@xilinx-zcu104-2020_2:~# wget https://www.xilinx.com/bin/public/openDownload?filename=densebox_320_320-zcu102_zcu104-r1.3.0.tar.gz -O densebox_320_320-zcu102_zcu104-r1.3.0.tar.gz
root@xilinx-zcu104-2020_2:~# tar xvf densebox_320_320-zcu102_zcu104-r1.3.0.tar.gz
densebox_320_320/
densebox_320_320/densebox_320_320.prototxt
densebox_320_320/densebox_320_320.xmodel
densebox_320_320/md5sum.txt
root@xilinx-zcu104-2020_2:~# cp densebox_320_320 /usr/share/vitis_ai_library/models -r

Vitis AI Runtime のアップデート

次のようにRuntimeをアップデートします。

root@xilinx-zcu104-2020_2:~# wget https://www.xilinx.com/bin/public/openDownload?filename=vitis-ai-runtime-1.3.0.tar.gz
root@xilinx-zcu104-2020_2:~# mv openDownload?filename=vitis-ai-runtime-1.3.0.tar.gz vitis-ai-runtime-1.3.0.tar.gz
root@xilinx-zcu104-2020_2:~# tar xvf vitis-ai-runtime-1.3.0.tar.gz 
vitis-ai-runtime-1.3.0/
vitis-ai-runtime-1.3.0/aarch64/
vitis-ai-runtime-1.3.0/aarch64/centos/
vitis-ai-runtime-1.3.0/aarch64/centos/libtarget-factory-1.3.0-r422.aarch64.rpm
tar: vitis-ai-runtime-1.3.0/aarch64/centos/libtarget-factory-1.3.0-r422.aarch64.rpm: time stamp 2020-12-14 03:01:50 is 49565.16884806 s in the future
vitis-ai-runtime-1.3.0/aarch64/centos/libunilog-1.3.0-r422.aarch64.rpm
tar: vitis-ai-runtime-1.3.0/aarch64/centos/libunilog-1.3.0-r422.aarch64.rpm: time stamp 2020-12-14 03:01:50 is 49565.16228633 s in the future
vitis-ai-runtime-1.3.0/aarch64/centos/libvart-1.3.0-r422.aarch64.rpm
tar: vitis-ai-runtime-1.3.0/aarch64/centos/libvart-1.3.0-r422.aarch64.rpm: time stamp 2020-12-14 03:01:50 is 49564.69414223 s in the future
vitis-ai-runtime-1.3.0/aarch64/centos/libvitis_ai_library-1.3.0-r422.aarch64.rpm
tar: vitis-ai-runtime-1.3.0/aarch64/centos/libvitis_ai_library-1.3.0-r422.aarch64.rpm: time stamp 2020-12-14 03:01:50 is 49562.82382058 s in the future
vitis-ai-runtime-1.3.0/aarch64/centos/libxir-1.3.0-r422.aarch64.rpm
tar: vitis-ai-runtime-1.3.0/aarch64/centos/libxir-1.3.0-r422.aarch64.rpm: time stamp 2020-12-14 03:01:50 is 49562.45794085 s in the future
vitis-ai-runtime-1.3.0/aarch64/centos/setup.sh
vitis-ai-runtime-1.3.0/X86_64/
tar: vitis-ai-runtime-1.3.0/aarch64/centos: time stamp 2020-12-14 03:01:50 is 49562.45750268 s in the future
vitis-ai-runtime-1.3.0/X86_64/ubuntu/
vitis-ai-runtime-1.3.0/X86_64/ubuntu/libtarget-factory_1.3.0-r422_amd64.deb
tar: vitis-ai-runtime-1.3.0/X86_64/ubuntu/libtarget-factory_1.3.0-r422_amd64.deb: time stamp 2020-12-14 03:02:16 is 49588.45098774 s in the future
vitis-ai-runtime-1.3.0/X86_64/ubuntu/libunilog_1.3.0-r422_amd64.deb
tar: vitis-ai-runtime-1.3.0/X86_64/ubuntu/libunilog_1.3.0-r422_amd64.deb: time stamp 2020-12-14 03:02:16 is 49588.45068286 s in the future
vitis-ai-runtime-1.3.0/X86_64/ubuntu/libvart_1.3.0-r422_amd64.deb
tar: vitis-ai-runtime-1.3.0/X86_64/ubuntu/libvart_1.3.0-r422_amd64.deb: time stamp 2020-12-14 03:02:16 is 49588.39387753 s in the future
vitis-ai-runtime-1.3.0/X86_64/ubuntu/libvitis_ai_library_1.3.0-r422_amd64.deb
tar: vitis-ai-runtime-1.3.0/X86_64/ubuntu/libvitis_ai_library_1.3.0-r422_amd64.deb: time stamp 2020-12-14 03:02:16 is 49588.26720411 s in the future
vitis-ai-runtime-1.3.0/X86_64/ubuntu/libxir_1.3.0-r422_amd64.deb
tar: vitis-ai-runtime-1.3.0/X86_64/ubuntu/libxir_1.3.0-r422_amd64.deb: time stamp 2020-12-14 03:02:16 is 49588.21672086 s in the future
vitis-ai-runtime-1.3.0/X86_64/ubuntu/setup.sh
tar: vitis-ai-runtime-1.3.0/X86_64/ubuntu: time stamp 2020-12-14 03:02:16 is 49588.21627182 s in the future

root@xilinx-zcu104-2020_2:~# cd ~/vitis-ai-runtime-1.3.0/aarch64/centos
root@xilinx-zcu104-2020_2:~/vitis-ai-runtime-1.3.0/aarch64/centos# bash setup.sh

ここまでで環境が整いました。

AI Library Exmaple の実行

次のようにイメージをダウンロードします。

root@xilinx-zcu104-2020_2:~# wget https://www.xilinx.com/bin/public/openDownload?filename=vitis_ai_library_r1.3.0_images.tar.gz
root@xilinx-zcu104-2020_2:~# wget https://www.xilinx.com/bin/public/openDownload?filename=vitis_ai_library_r1.3.0_video.tar.gz

root@xilinx-zcu104-2020_2:~# mv openDownload?filename=vitis_ai_library_r1.3.0_images.tar.gz vitis_ai_library_r1.3.0_images.tar.gz
root@xilinx-zcu104-2020_2:~# mv openDownload?filename=vitis_ai_library_r1.3.0_video.tar.gz vitis_ai_library_r1.3.0_video.tar.gz

root@xilinx-zcu104-2020_2:~# tar xvf vitis_ai_library_r1.3.0_images.tar.gz -C ~/Vitis-AI/demo/Vitis-AI-Library
root@xilinx-zcu104-2020_2:~# tar xvf vitis_ai_library_r1.3.0_video.tar.gz -C ~/Vitis-AI/demo/Vitis-AI-Library

次のようにJPEG画像でfacedetectを行います。

root@xilinx-zcu104-2020_2:~# cd ~/Vitis-AI/demo/Vitis-AI-Library/samples/facedetect
root@xilinx-zcu104-2020_2:~# ./test_jpeg_facedetect densebox_320_320 sample_facedetect.jpg

他にも動画の認識などがあります。

root@xilinx-zcu104-2020_2:~# ./test_video_facedetect densebox_320_320 video_input.webm -t 0

こちらはUSBカメラでの認識です。

root@xilinx-zcu104-2020_2:~# ./test_video_facedetect densebox_320_320 0 -t 8

リストでの指定もできるようです。

root@xilinx-zcu104-2020_2:~# ./test_performance_facedetect densebox_320_320 test_performance_facedetect.list -t 8 -s 60
writed: 2021/01/06/ 00:00:00