R329 开发板申请Sample
模型下载:
- Inception V3下载地址:
http://download.tensorflow.or...\_v3\_2016\_08\_28.tar.gz
- 参考文档:
https://github.com/tensorflow...
矫正集
将图片和label放到calibration目录下的img路径和label.txt下,
执行 preprocess\_for\_dataset.py 生成 dataset.npy和label.npy矫正集文件.
输入文件
放测试文件car.jpg到\~//demos/pb/model目录下,更改gen\_inputbin.py脚本执行的jpg文件名, 运行python脚本生成input.bin.
生成Inception V3冻结的pb文件
- 步骤1:导出前向传播图
进入export\_inference\_graph.py所在目录models/research/slim/执行
python3 export_inference_graph.py \
--alsologtostderr \
--model_name=inception_v3 \
--output_file=./inception_v3_inf_graph.pb
- 步骤2: 生成冻结PB文件
python3 /usr/local/lib/python3.6/dist-packages/tensorflow_core/python/tools/freeze_graph.py \
--input_graph=./inception_v3_inf_graph.pb \
--input_checkpoint=./inception_v3.ckpt \
--input_binary=true --output_graph=./inception_v3_frozen.pb \
--output_node_names=InceptionV3/Predictions/Reshape
注:此步骤的output node names由Netron获取得到.
编写AIPU仿真和执行的配置文件
如附件inception\_v3\_build\_run.cfg所示:
[Common]
mode=run
[Parser]
model_name = inception_v3
detection_postprocess =
model_domain = image_classification
output = InceptionV3/Predictions/Reshape
input_model = /home/data/aipu_build_inception_v3/inception_v3_frozen.pb
input = input
input_shape = [1,299,299,3] # 注意这里Inception V3是299x299
output_dir = ./
[AutoQuantizationTool]
model_name = inception_v3
quantize_method = SYMMETRIC
ops_per_channel = DepthwiseConv
calibration_data = /home/data/aipu_build_inception_v3/dataset.npy
calibration_label = /home/data/aipu_build_inception_v3/label.npy
preprocess_mode = normalize
quant_precision=int8
reverse_rgb = False
label_id_offset = 0
#[GBuilder]
#target=Z1_0701
#outputs=./inception_model_output/aipu_inception.bin
#profile= True
[GBuilder]
inputs=/home/data/aipu_build_inception_v3/model_input/input.bin
outputs=/home/data/aipu_build_inception_v3/output_inception.bin
simulator=/usr/bin/aipu_simulator_z1
profile= True
target=Z1_0701
simulator 执行结果
cd /home/data/aipu\_build\_inception\_v3
aipubuild ./inception\_v3\_build\_run.cfg
运行之后得到 output\_inception.bin,Python中运行如下脚本解析后:
import numpy as np
outputfile = './output_inception.bin'
npyoutput = np.fromfile(outputfile, dtype=np.int8)
outputclass = npyoutput.argmax()
print("Predict Class is %d"%outputclass)
获得结果为
Predict Class is 35
附件
本次实验所有数据存放在百度网盘
链接:https://pan.baidu.com/s/1EWvG...\_VTJO64gQg 提取码:quoz