1、搭建模型
搭建一个分类网络,分类物体,模型结构如下:
输入: Placeholder
输出: output
1.1 训练
git clone https://gitee.com/Yang123321/simple-cnn.git
cd simple-cnn
python3 cnn.py
log:
step = 0 mean loss = 1.119428038597107
step = 10 mean loss = 1.0487422943115234
step = 20 mean loss = 0.9574651122093201
step = 30 mean loss = 0.8987987041473389
step = 40 mean loss = 0.8074296116828918
step = 50 mean loss = 0.7118208408355713
step = 60 mean loss = 0.5731518268585205
step = 70 mean loss = 0.42807847261428833
step = 80 mean loss = 0.25988009572029114
step = 90 mean loss = 0.5996816754341125
step = 100 mean loss = 0.20746763050556183
step = 110 mean loss = 0.08659818023443222
step = 120 mean loss = 0.027754301205277443
step = 130 mean loss = 0.009440970607101917
step = 140 mean loss = 0.005224811844527721
训练结束,保存模型到model/image_model
1.2 测试
修改cnn.py中的train = False
python3 cnn.py
log:
allImg: 150, trueImg: 150, percent: 100.0%
全部分类正确
2、模型量化
在1.2中会生成带有权重的pb文件
2.1 配置量化环境
git clone -b simpleCNN https://gitee.com/Yang123321/r329_aipu_simulator.git
cd r329_aipu_simulator
2.2 矫正文件
三类物体,每类物体使用两帧图像作为矫正图像
cd dataset
python3 preprocess_dataset.py
2.3 cfg
量化配置文件build.cfg
模拟推理配置文件:run.cfg
生成输入测试文件(图像数据的二进制文件)
cd model
python3 gen_inputbin.py
2.4 仿真测试
aipubuild config/build.cfg
aipubuild config/run.cfg
共3类, 每类测试了一张图像,
输入为model目录下的input0.bin、input1.bin、input2.bin
测试结果如下
output_simpleCNN0.bin
output_simpleCNN1.bin
output_simpleCNN2.bin
模型直接输出的是类别,结果正确