qixingzhang / SummerSchool2022-Vitis-AI

Vitis AI Lab: MNIST classifier

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vitis AI Lab: MNIST Classifier

Install Vitis AI

  1. Install docker engine
  2. Pull Vitis AI 1.4 image
    sudo docker pull xilinx/vitis-ai:1.4.916
    
  3. Clone from GitHub
    $ git clone https://github.com/Xilinx/Vitis-AI.git
    $ cd Vitis-AI
    $ git checkout v1.4
  4. Clone this repository to Vitis-AI folder
    $ git clone https://github.com/qixingzhang/SummerSchool2022-Vitis-AI.git
  5. Launch Vitis AI
    sudo ./docker_run.sh xilinx/vitis-ai:1.4.916

Vitis AI Workflow

  1. Activate TensorFlow 2.x environment

    $ conda activate vitis-ai-tensorflow2
  2. Train the model if needed

    A pre-trained keras model (.h5 format) is provided, you can also train it by youself

    $ python train.py
  3. 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.
  4. Compile the model

    $ ./2_compile.sh

    This scripts uses the vai_c_tensorflow2 commmand to compile the quantized model. It has four required parameters:

    • --model quantized model with h5 format
    • --arch indicate DPU arch, it can be found in /opt/vitis_ai/compiler/arch/DPUCZDX8G for different Zynq boards.
    • --output_dir compile output path
    • --net_name your model name

    The output .xmodel file is saved in compile_output folder.

Deploy on edge board using DPU-PYNQ

  1. Boot the board with PYNQ v2.7 image
  2. Install python package
    $ sudo pip3 install pynq-dpu --no-build-isolation
  3. Get notebooks
    $ cd $PYNQ_JUPYTER_NOTEBOOKS
    $ pynq get-notebooks -p . pynq-dpu
  4. Run the dpu_mnist_classifier notebook in pynq-dpu folder. You can upload your own .xmodel file to this folder and replace the existing dpu_mnist_classifier.xmodel

About

Vitis AI Lab: MNIST classifier


Languages

Language:Python 78.9%Language:Shell 21.1%