进入到代码所在目录下
cd Vitis-Tutorials-master/Machine_Learning/Design_Tutorials/02-MNIST_classification_tf/files
启动GPU-docker
source ./start_gpu_docker.sh
启动成功
依次执行如下命令,设置环境变量,训练,冻结参数,评估,量化,量化评估,编译,生成目标平台可执行文件
source 0_setenv.sh
source 1_train.sh
source 2_freeze.sh
source 3_eval_frozen_graph.sh
source 4_quant.sh
source 5_eval_quant_graph.sh
source 6_compile_zcu102.sh
source 7_make_target_zcu102.sh
生成的文件在files/build/target_zcu102下,如图,model_dir目录下是dpu_customcnn.elf,images下是1万张手写图片
打开开发板,连接UART 线至主机,启动模式位SD-Boot mode (箭头指向on的方向看,四个开关分别为:上下下下)
通过UART设置开发板IP地址为192.168.0.110
ifconfig eth0 192.168.0.110 netmask 255.255.255.0
UART 内容如下,我的Ubuntu连接开发板突然uart模式连接不了,设置不了IP 了,去windows下一切正常,不知道是何原因
root@xilinx-zcu102-2020_1:~# ifconfig eth0 192.168.0.110 netmask 255.255.255.0
root@xilinx-zcu102-2020_1:~# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0A:35:00:22:01
inet addr:192.168.0.110 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:659 errors:0 dropped:0 overruns:0 frame:0
TX packets:338 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:52216 (50.9 KiB) TX bytes:116192 (113.4 KiB)
Interrupt:31
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:140 (140.0 B) TX bytes:140 (140.0 B)
root@xilinx-zcu102-2020_1:~#
IP 设置完成,通过scp命令将刚才生成的内容拷贝到开发板上
scp -r ./build/target_zcu102 root@192.168.0.110:~/
远程登录开发板(此时开发板通过网线和主机连接)
ssh root@192.168.0.110
登录之后执行如下命令
单线程
python3 app_mt.py -m model_dir/dpu_customcnn.elf
多线程
python3 app_mt.py -m model_dir/dpu_customcnn.elf -t 6
至此完成了mnist图像分类程序的zcu102部署运行~
下边是上面7个命令的正确运行输出结果,备忘
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 1_train.sh
-----------------------------------------
TRAINING STARTED..
-----------------------------------------
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz
11493376/11490434 [==============================] - 2s 0us/step
------------------------------------
Keras version : 2.2.4-tf
TensorFlow version : 1.15.2
Python version : 3.6.10 |Anaconda, Inc.| (default, Mar 25 2020, 23:51:54)
[GCC 7.3.0]
------------------------------------
Command line options:
--input_height : 28
--input_width : 28
--input_chan : 1
--epochs : 5
--batchsize : 100
--learnrate : 0.001
--output_ckpt_path: ./build/chkpts/float_model.ckpt
--infer_graph_path: ./build/chkpts/inference_graph.pb
--tboard_path : ./build/tb_logs
--gpu : 0
------------------------------------
Network input shape: (?, 28, 28, 1)
(?, 14, 14, 16)
(?, 7, 7, 32)
(?, 4, 4, 64)
(?, 1, 1, 10)
Network output shape: (?, 10)
----------------------------
TRAINING STARTED...
----------------------------
Epoch 1 / 5 - accuracy 97.20 %
Epoch 2 / 5 - accuracy 98.14 %
Epoch 3 / 5 - accuracy 98.46 %
Epoch 4 / 5 - accuracy 98.44 %
Epoch 5 / 5 - accuracy 98.46 %
----------------------------
SAVING CHECKPOINT & GRAPH...
----------------------------
Saved checkpoint to ./build/chkpts/float_model.ckpt
Network input shape: (?, 28, 28, 1)
(?, 14, 14, 16)
(?, 7, 7, 32)
(?, 4, 4, 64)
(?, 1, 1, 10)
Network output shape: (?, 10)
Saved binary inference graph to ./build/chkpts/inference_graph.pb
Run `tensorboard --logdir=./build/tb_logs --port 6006 --host localhost` to see the results.
-----------------------------------------
TRAINING COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 2_freeze.sh
-----------------------------------------
FREEZE STARTED..
-----------------------------------------
WARNING:tensorflow:From /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/tools/freeze_graph.py:127: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
W1214 00:26:40.466517 140039891904320 deprecation.py:323] From /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/tools/freeze_graph.py:127: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version.
Instructions for updating:
Use standard file APIs to check for files with this prefix.
2020-12-14 00:26:40.478010: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2020-12-14 00:26:40.497383: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 4200000000 Hz
2020-12-14 00:26:40.497751: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x56472e899760 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-12-14 00:26:40.497767: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
INFO:tensorflow:Restoring parameters from ./build/chkpts/float_model.ckpt
I1214 00:26:40.515603 140039891904320 saver.py:1284] Restoring parameters from ./build/chkpts/float_model.ckpt
WARNING:tensorflow:From /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/tools/freeze_graph.py:233: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.convert_variables_to_constants`
W1214 00:26:40.533195 140039891904320 deprecation.py:323] From /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/tools/freeze_graph.py:233: convert_variables_to_constants (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.convert_variables_to_constants`
WARNING:tensorflow:From /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/graph_util_impl.py:277: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.extract_sub_graph`
W1214 00:26:40.533316 140039891904320 deprecation.py:323] From /opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib/python3.6/site-packages/tensorflow_core/python/framework/graph_util_impl.py:277: extract_sub_graph (from tensorflow.python.framework.graph_util_impl) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.compat.v1.graph_util.extract_sub_graph`
INFO:tensorflow:Froze 20 variables.
I1214 00:26:40.541999 140039891904320 graph_util_impl.py:334] Froze 20 variables.
INFO:tensorflow:Converted 20 variables to const ops.
I1214 00:26:40.543889 140039891904320 graph_util_impl.py:394] Converted 20 variables to const ops.
-----------------------------------------
FREEZE COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 3_eval_frozen_graph.sh
-----------------------------------------
EVALUATING THE FROZEN GRAPH..
-----------------------------------------
------------------------------------
Keras version : 2.2.4-tf
TensorFlow version : 1.15.2
3.6.10 |Anaconda, Inc.| (default, Mar 25 2020, 23:51:54)
[GCC 7.3.0]
------------------------------------
Command line options:
--graph : ./build/freeze/frozen_graph.pb
--input_node : images_in
--output_node: conv2d_3/BiasAdd
--gpu : 0
------------------------------------
Graph accuracy: 98.00 %
-----------------------------------------
GRAPH EVAL COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 4_quant.sh
-----------------------------------------
QUANTIZE STARTED..
-----------------------------------------
Making list of calibration images..
Command line options:
--dataset : mnist
--subset : test
--image_dir : ./build/quantize/images
--image_list : calib_list.txt
--label_list :
--image_format : jpg
--max_images : 1000
Vai_q_tensorflow v1.2.0 build for Tensorflow 1.15.2
100% (100 of 100) |######################| Elapsed Time: 0:00:00 Time: 0:00:00
INFO: Checking Float Graph...
INFO: Float Graph Check Done.
INFO: Calibrating for 100 iterations...
INFO: Calibration Done.
INFO: Generating Deploy Model...
INFO: Deploy Model Generated.
********************* Quantization Summary *********************
INFO: Output:
quantize_eval_model: ./build/quantize/quantize_eval_model.pb
deploy_model: ./build/quantize/deploy_model.pb
-----------------------------------------
QUANTIZED COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 5_eval_quant_graph.sh
-----------------------------------------
EVALUATING THE QUANTIZED GRAPH..
-----------------------------------------
------------------------------------
Keras version : 2.2.4-tf
TensorFlow version : 1.15.2
3.6.10 |Anaconda, Inc.| (default, Mar 25 2020, 23:51:54)
[GCC 7.3.0]
------------------------------------
Command line options:
--graph : ./build/quantize/quantize_eval_model.pb
--input_node : images_in
--output_node: conv2d_3/BiasAdd
--gpu : 0
------------------------------------
Graph accuracy: 97.98 %
-----------------------------------------
GRAPH EVAL COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 6_compile_zcu102.sh
-----------------------------------------
COMPILE ZCU102 STARTED..
-----------------------------------------
Kernel topology "customcnn_kernel_graph.jpg" for network "customcnn"
kernel list info for network "customcnn"
Kernel ID : Name
0 : customcnn
Kernel Name : customcnn
--------------------------------------------------------------------------------
Kernel Type : DPUKernel
Code Size : 3.46KB
Param Size : 0.04MB
Workload MACs : 2.02MOPS
IO Memory Space : 5.61KB
Mean Value : 0, 0, 0,
Total Tensor Count : 5
Boundary Input Tensor(s) (H*W*C)
images_in:0(0) : 28*28*1
Boundary Output Tensor(s) (H*W*C)
conv2d_3_Conv2D:0(0) : 1*1*10
Total Node Count : 4
Input Node(s) (H*W*C)
conv2d_Conv2D(0) : 28*28*1
Output Node(s) (H*W*C)
conv2d_3_Conv2D(0) : 1*1*10
**************************************************
* VITIS_AI Compilation - Xilinx Inc.
**************************************************
-----------------------------------------
COMPILE ZCU102 COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$ source 7_make_target_zcu102.sh
-----------------------------------------
MAKE TARGET ZCU102 STARTED..
-----------------------------------------
Copied application to target folder
Copied elf file(s) to target folder
Command line options:
--dataset : mnist
--subset : test
--image_dir : ./build/target_zcu102/images
--image_list :
--label_list :
--image_format : jpg
--max_images : 10000
Copied images to target folder
-----------------------------------------
MAKE TARGET ZCU102 COMPLETED
-----------------------------------------
(vitis-ai-tensorflow) cao@cao-OMEN-by-HP-Desktop-PC-880-p0xx:/workspace$