1.Open the docker environment of Vitis AI shell , and go to the path of this tutorial lab
---
```
./docker_run.sh xilinx/vitis-ai-cpu:latest
```

2.Active the conda environment of this lab , and download the package we need
---
```
conda activate vitis-ai-pytorch
pip install torchsummary
conda deactivate
```
3.Run the script
---
```
source ./run_all.sh
```
First it will start the training :


output the weight file to "cnn_float.pt"

After training finished , it will show the imformation of this CNN model .
And it will quantize the model

It put the following structure into your device before loading your weight



Then compile the model for hardware DPU


In this step I try to use another compile command to compile the model for device KV260
```
ARCH=/opt/vitis_ai/compiler/arch/DPUCZDX8G/KV260/arch.json
TARGET=kv260
echo "-----------------------------------------"
echo "COMPILING MODEL FOR KV260"
echo "Using ARCH: $ARCH"
echo "-----------------------------------------"
rm -rf ./build/compiled_model_kv260
mkdir -p ./build/compiled_model_kv260
compile() {
vai_c_xir \
--xmodel ./build/quantized_model/CNN_int.xmodel \
--arch $ARCH \
--net_name CNN_int_${TARGET} \
--output_dir ./build/compiled_model_kv260
}
compile 2>&1 | tee ./build/compile_${TARGET}.log
echo "-----------------------------------------"
echo "Compile completed! Output in ./build/compiled_model_kv260"
echo "-----------------------------------------"
```
4.Dataflow graph of this CNN
---
Tanh(x) and sigmoid operation can't run on DPU , these operation will run on PS side's ARM processor :

So it arrange the dataflow graph as following :

5.Host code
---
a. tanh 、 sigmoid function

b. Img pre-process (open grayscale img、resize)

c. Excution inference

In run_dpu() :


I run this lab by PYNQ's environment instead of the origin way (because the setting's issue),and the following are my host code's link :
6.generate the bitstream and xclbin、hwh to program PL side
---
In this lab ,I use the xilinx's offical github repo "DPU-PYNQ" to generate the bitstream and xclbin
```
git clone https://github.com/Xilinx/DPU-PYNQ.git
```
And then enter the folder to run makefile
```
cd boards
make BOARD=kv260_som
```
Then it will generate the file in the folder kv260_som .
You can modify the command to generate other board's bitstream .
ex : zcu104 zcu102...
7.Inference on KV260 board
---
1. Upload the requirement files tn jupyter lab


hostcode :

2. Excute the host code to get the result
