zhen8838 / K210_Yolo_framework

Yolo v3 framework base on tensorflow, support multiple models, multiple datasets, any number of output layers, any number of anchors, model prune, and portable model to K210 !
MIT License
249 stars 73 forks source link

pre-train model & prune model 模型压缩与转换 #27

Open erickyunyi opened 4 years ago

erickyunyi commented 4 years ago

hello zheng: 当我用连接提供的voc训练集完成训练后,默认生成的.h5模型大小为15.8M,通过提剪枝命令:make train MODEL=xxxx MAXEP=1 ILR=0.0003 DATASET=voc CLSNUM=20 BATCH=16 PRUNE=True CKPT=log/xxxxxx/yolo_model.h5 END_EPOCH=1 进行剪枝后生成的模型大小没有变化 ,模型通过nncase转换提示失败(模型超出K210内存) 我的目的时想把模型移植到K210上面跑,该如何实现,需要修改pre-train model 还是可以通过剪枝实现模型压缩?

zhen8838 commented 4 years ago

目前是使用更小的模型,比如使用的mbnet-0.75。剪枝只是把某些权重设置为0,稀疏的模型对于k210没有加速和减少内存消耗。更好的缩小模型参数方法是使用模型蒸馏。

erickyunyi commented 4 years ago

非常感谢回复,我打算往k210移植目标检测模型,但是目前训练出来的模型偏大,无法转换成功,应该如和更换pre-train模型训练并成功转换成K模型呢? 链接提供的train命令如下,但是train之后模型较大15.8M make train MODEL=yolo_mobilev1 DEPTHMUL=0.75 MAXEP=10 ILR=0.001 DATASET=voc CLSNUM=20 IAA=False BATCH=16

zhen8838 commented 4 years ago

不用换,mbnetv1-0.75通过之前的nncase转换为kmodel是可以在k210运行的

yeeshanqiao commented 3 years ago

I follow the readme doc and I have the same problem too, the h5 model size is about 15.8M and the converted tflite model is about 15.4M, did you solve this problem? @erickyunyi

@zhen8838 Also, when I try to convert the tflite file to kmodel, the ncc command gives me the following error message:

Fatal: Not supported tflite opcode: SHAPE

zhen8838 commented 3 years ago

Please use nncase v0.1.0-rc5. The quantized mobilenet-v1 0.75 model can be used on k210.

yeeshanqiao commented 3 years ago

Fatal: Not supported tflite opcode: SHAPE

Solved, the reason for this issue is that I use TensorFlow 2.0 to convert the h5 model to tflite.