1、矫正集的data.npy和label.npy
2、NN compiler的cfg文件
tflite_mobilenet_v2_build.cfg
tflite_mobilenet_v2_run.cfg
3、simulator执行的输入输出结果,比较运算量化误差
3.1 build
root@b4a83eb09b47:~/demos/tflite# ls config/
tflite_mobilenet_v2_build.cfg tflite_mobilenet_v2_run.cfg
root@b4a83eb09b47:~/demos/tflite# aipu
aipu_profiler aipu_simulator_z1 aipubuild aipugb aipurun
root@b4a83eb09b47:~/demos/tflite# aipubuild config/tflite_mobilenet_v2_build.cfg
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
[I] Parsing model....
[I] [Parser]: Begin to parse tflite model mobilenet_v2...
[W] [Parser]: Meets too high Onnx version! Please downgrade to 1.07!
2021-07-13 11:42:37.155406: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-07-13 11:42:37.186077: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2194800000 Hz
2021-07-13 11:42:37.186459: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0xb6bafd0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-07-13 11:42:37.186496: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
[I] [Parser]: Parser done!
[I] Parse model complete
[I] Quantizing model....
[I] AQT start: model_name:mobilenet_v2, calibration_method:MEAN, batch_size:1
[I] ==== read ir ================
[I] float32 ir txt: /tmp/AIPUBuilder_1626176556.499151/mobilenet_v2.txt
[I] float32 ir bin2: /tmp/AIPUBuilder_1626176556.499151/mobilenet_v2.bin
[I] ==== read ir DONE.===========
WARNING:tensorflow:From /usr/local/bin/aipubuild:8: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /usr/local/bin/aipubuild:8: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.
[I] ==== auto-quantization ======
[I] step1: get max/min statistic value DONE
[I] step2: quantization each op DONE
[I] step3: build quantization forward DONE
[I] step4: show output scale of end node:
[I] layer_id: 66, layer_top:MobilenetV2/Predictions/Softmax, output_scale:[255.99994]
[I] ==== auto-quantization DONE =
[I] Quantize model complete
[I] Building ...
[I] [common_options.h: 276] BuildTool version: 4.0.175. Build for target Z1_0701 at frequency 800MHz
[I] [IRChecker] Start to check IR: /tmp/AIPUBuilder_1626176556.499151/mobilenet_v2_int8.txt
[I] [IRChecker] model_name: mobilenet_v2
[I] [IRChecker] IRChecker: All IR pass
[I] [graph.cpp : 846] loading graph weight: /tmp/AIPUBuilder_1626176556.499151/mobilenet_v2_int8.bin size: 0x364ee8
[I] [builder.cpp:1059] Total memory for this graph: 0xa67f50 Bytes
[I] [builder.cpp:1060] Text section: 0x00012f50 Bytes
[I] [builder.cpp:1061] RO section: 0x00003900 Bytes
[I] [builder.cpp:1062] Desc section: 0x00022a00 Bytes
[I] [builder.cpp:1063] Data section: 0x0044a600 Bytes
[I] [builder.cpp:1064] BSS section: 0x005a4300 Bytes
[I] [builder.cpp:1065] Stack : 0x00040400 Bytes
[I] [builder.cpp:1066] Workspace(BSS): 0x0000f500 Bytes
Total errors: 0, warnings: 0
3.2 run
root@b4a83eb09b47:~/demos/tflite# aipubuild config/tflite_mobilenet_v2_run.cfg
WARNING:tensorflow:
The TensorFlow contrib module will not be included in TensorFlow 2.0.
For more information, please see:
* https://github.com/tensorflow/community/blob/master/rfcs/20180907-contrib-sunset.md
* https://github.com/tensorflow/addons
* https://github.com/tensorflow/io (for I/O related ops)
If you depend on functionality not listed there, please file an issue.
[I] Parsing model....
[I] [Parser]: Begin to parse tflite model mobilenet_v2...
[W] [Parser]: Meets too high Onnx version! Please downgrade to 1.07!
2021-07-13 11:44:02.115822: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2021-07-13 11:44:02.146010: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 2194800000 Hz
2021-07-13 11:44:02.146468: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0xb6a4b70 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2021-07-13 11:44:02.146503: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
[I] [Parser]: Parser done!
[I] Parse model complete
[I] Quantizing model....
[I] AQT start: model_name:mobilenet_v2, calibration_method:MEAN, batch_size:1
[I] ==== read ir ================
[I] float32 ir txt: /tmp/AIPUBuilder_1626176641.2187574/mobilenet_v2.txt
[I] float32 ir bin2: /tmp/AIPUBuilder_1626176641.2187574/mobilenet_v2.bin
[I] ==== read ir DONE.===========
WARNING:tensorflow:From /usr/local/bin/aipubuild:8: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /usr/local/bin/aipubuild:8: The name tf.nn.avg_pool is deprecated. Please use tf.nn.avg_pool2d instead.
[I] ==== auto-quantization ======
[I] step1: get max/min statistic value DONE
[I] step2: quantization each op DONE
[I] step3: build quantization forward DONE
[I] step4: show output scale of end node:
[I] layer_id: 66, layer_top:MobilenetV2/Predictions/Softmax, output_scale:[255.99994]
[I] ==== auto-quantization DONE =
[I] Quantize model complete
[I] Building ...
[I] [common_options.h: 276] BuildTool version: 4.0.175. Build for target Z1_0701 at frequency 800MHz
[I] [common_options.h: 297] using default profile events to profile AIFF
[I] [IRChecker] Start to check IR: /tmp/AIPUBuilder_1626176641.2187574/mobilenet_v2_int8.txt
[I] [IRChecker] model_name: mobilenet_v2
[I] [IRChecker] IRChecker: All IR pass
[I] [graph.cpp : 846] loading graph weight: /tmp/AIPUBuilder_1626176641.2187574/mobilenet_v2_int8.bin size: 0x364ee8
[I] [builder.cpp:1059] Total memory for this graph: 0xa7e930 Bytes
[I] [builder.cpp:1060] Text section: 0x00029130 Bytes
[I] [builder.cpp:1061] RO section: 0x00003900 Bytes
[I] [builder.cpp:1062] Desc section: 0x00022a00 Bytes
[I] [builder.cpp:1063] Data section: 0x0044a600 Bytes
[I] [builder.cpp:1064] BSS section: 0x005a4b00 Bytes
[I] [builder.cpp:1065] Stack : 0x00040400 Bytes
[I] [builder.cpp:1066] Workspace(BSS): 0x0000f500 Bytes
[I] [main.cpp : 467] # autogenrated by aipurun, do NOT modify!
LOG_FILE=log_default
FAST_FWD_INST=0
INPUT_INST_CNT=1
INPUT_DATA_CNT=2
CONFIG=Z1-0701
LOG_LEVEL=0
INPUT_INST_FILE0=/tmp/temp_3298ac0161b8220b5c6ffc1864346.text
INPUT_INST_BASE0=0x0
INPUT_INST_STARTPC0=0x0
INPUT_DATA_FILE0=/tmp/temp_3298ac0161b8220b5c6ffc1864346.ro
INPUT_DATA_BASE0=0x10000000
INPUT_DATA_FILE1=/tmp/temp_3298ac0161b8220b5c6ffc1864346.data
INPUT_DATA_BASE1=0x20000000
OUTPUT_DATA_CNT=2
OUTPUT_DATA_FILE0=output_mobilenet_v2.bin
OUTPUT_DATA_BASE0=0x20b6e400
OUTPUT_DATA_SIZE0=0x3e9
OUTPUT_DATA_FILE1=profile_data.bin
OUTPUT_DATA_BASE1=0x20599f00
OUTPUT_DATA_SIZE1=0x700
RUN_DESCRIPTOR=BIN[0]
[I] [main.cpp : 118] run simulator:
aipu_simulator_z1 /tmp/temp_3298ac0161b8220b5c6ffc1864346.cfg
[INFO]:SIMULATOR START!
[INFO]:========================================================================
[INFO]: STATIC CHECK
[INFO]:========================================================================
[INFO]: INST START ADDR : 0x0(0)
[INFO]: INST END ADDR : 0x2912f(168239)
[INFO]: INST SIZE : 0x29130(168240)
[INFO]: PACKET CNT : 0x2913(10515)
[INFO]: INST CNT : 0xa44c(42060)
[INFO]:------------------------------------------------------------------------
[WARN]:[0803] INST WR/RD REG CONFLICT! PACKET 0x44e: 0x472021b(POP R27,Rc7) vs 0x5f00000(MVI R0,0x0,Rc7), PACKET:0x44e(1102) SLOT:0 vs 3
[WARN]:[0803] INST WR/RD REG CONFLICT! PACKET 0x45b: 0x472021b(POP R27,Rc7) vs 0x5f00000(MVI R0,0x0,Rc7), PACKET:0x45b(1115) SLOT:0 vs 3
[WARN]:[0803] INST WR/RD REG CONFLICT! PACKET 0x5c0: 0x472021b(POP R27,Rc7) vs 0x9f80020(ADD.S R0,R0,0x1,Rc7), PACKET:0x5c0(1472) SLOT:0 vs 3
[WARN]:[0803] INST WR/RD REG CONFLICT! PACKET 0x7fd: 0x4520180(BRL R0) vs 0x47a03e4(ADD R4,R0,R31,Rc7), PACKET:0x7fd(2045) SLOT:0 vs 3
[WARN]:[0803] INST WR/RD REG CONFLICT! PACKET 0x996: 0x4720204(POP R4,Rc7) vs 0x9f80020(ADD.S R0,R0,0x1,Rc7), PACKET:0x996(2454) SLOT:0 vs 3
[WARN]:[0803] INST WR/RD REG CONFLICT! PACKET 0xe40: 0x4720204(POP R4,Rc7) vs 0x47a1be0(ADD R0,R6,R31,Rc7), PACKET:0xe40(3648) SLOT:0 vs 3
[INFO]:========================================================================
[INFO]: STATIC CHECK END
[INFO]:========================================================================
[INFO]:AIPU START RUNNING: BIN[0]
[INFO]:TOTAL TIME: 4.081745s.
[INFO]:SIMULATOR EXIT!
[I] [main.cpp : 135] Simulator finished.
Total errors: 0, warnings: 0
3.1 预测
root@b4a83eb09b47:~/demos/tflite# python3 quant_predict.py
predict first 5 label:
index 231, prob 180, name: Shetland sheepdog, Shetland sheep dog, Shetland
index 232, prob 67, name: collie
index 1000, prob 0, name: toilet tissue, toilet paper, bathroom tissue
index 342, prob 0, name: hog, pig, grunter, squealer, Sus scrofa
index 340, prob 0, name: sorrel
true first 5 label:
index 232, prob 83, name: collie
index 231, prob 83, name: Shetland sheepdog, Shetland sheep dog, Shetland
index 158, prob 41, name: papillon
index 170, prob 40, name: borzoi, Russian wolfhound
index 161, prob 39, name: Afghan hound, Afghan
Detect picture save to result.jpeg