- Install docker engine
- Official site: https://docs.docker.com/engine/install/
- For Ubuntu: https://docs.docker.com/engine/install/ubuntu/
- Pull Vitis AI 1.4 image
sudo docker pull xilinx/vitis-ai:1.4.916 - Clone from GitHub
$ git clone https://github.com/Xilinx/Vitis-AI.git
$ cd Vitis-AI$ git checkout v1.4
- Clone this repository to
Vitis-AIfolder$ git clone https://github.com/qixingzhang/SummerSchool2022-Vitis-AI.git
- Launch Vitis AI
sudo ./docker_run.sh xilinx/vitis-ai:1.4.916
-
Activate TensorFlow 2.x environment
$ conda activate vitis-ai-tensorflow2
-
Train the model if needed
A pre-trained keras model (.h5 format) is provided, you can also train it by youself
$ python train.py
-
Quantize the model
$ chmod +x *.sh$ ./1_quantize.sh
This script invokes the python script
vitis_ai_tf2_quantize.py. It uses the python API of Vitis AI Quantizer:quantizer = vitis_quantize.VitisQuantizer(model)- model: keras floating point model
quantized_model = quantizer.quantize_model(calib_dataset=dataset)- calib_dataset: dataset for calibration, 100 ~ 1000 training or testing images is enough.
-
Compile the model
$ ./2_compile.sh
This scripts uses the
vai_c_tensorflow2commmand to compile the quantized model. It has four required parameters:--modelquantized model with h5 format--archindicate DPU arch, it can be found in/opt/vitis_ai/compiler/arch/DPUCZDX8Gfor different Zynq boards.--output_dircompile output path--net_nameyour model name
The output
.xmodelfile is saved incompile_outputfolder.
- Boot the board with PYNQ v2.7 image
- Image download link: http://www.pynq.io/board.html
- Install python package
$ sudo pip3 install pynq-dpu --no-build-isolation
- Get notebooks
$ cd $PYNQ_JUPYTER_NOTEBOOKS
$ pynq get-notebooks -p . pynq-dpu - Run the
dpu_mnist_classifiernotebook inpynq-dpufolder. You can upload your own.xmodelfile to this folder and replace the existingdpu_mnist_classifier.xmodel