通过mobileNet冻结预训练权重值,自定义训练猫,狗分类,转换模型kmodel在k210运行
代码下载地址:
https://codeload.github.com/AIWintermuteAI/transfer_learning_sipeed/zip/master
测试代码:(用来下载mobileNet模型并测试,检查本地环境)
1 |
|
训练代码:(images文件中放入要训练分类图片,比如新建cat,dog文件夹并放入相关图片用于训练)
1 |
|
测试代码:(测试生成的模型效果)
1 |
|
h5转tflite
1 | tflite_convert --output_file=my_model.tflite --keras_model_file=my_model.h5 |
放一些测试图片放到images文件夹里
tflite转kmodel
1 | bash tflite2kmodel.sh workspace/my_model.tflite |
生成my_model.kmodel
用kflash烧录到一个地址,比如:0x200000
制作一个lables.txt标签文件放到SD卡中:
格式为:
cat
dog
micropython代码如下:
1 |
|
问题:Converting Keras model, Conv2d error
原话:
Perhaps you used wrong parameters? https://github.com/kendryte/nncase#supported-layers
When using TensorFlow Conv2d/DepthwiseConv2d kernel=3x3 stride=2 padding=same, you must first use tf.pad([[0,0],[1,1],[1,1],[0,0]]) to pad the input and then use Conv2d/DepthwiseConv2d with valid padding.
大概意思:
或许你使用了错误的参数,参考:
https://github.com/kendryte/nncase#supported-layers
在使用 TensorFlow Conv2d/DepthwiseConv2d kernel=3x3 stride=2 padding=same 的时候,你必须先使用 tf.pad([[0,0],[1,1],[1,1],[0,0]]) 去填充输入 并且使用 Conv2d/DepthwiseConv2d 的padding=valid参数
支持的layer:
https://github.com/dotnetGame/nncase#supported-layers
i managed to get it to work by making sure that every conv2d layer have the ‘same’ padding. Do you have any tip so that the conversion from h5 to kmodel will result in a small memory footprint ? When i convert for now, i have a kmodel that is as large as the .pb graph.
参考:
https://www.instructables.com/id/Transfer-Learning-With-Sipeed-MaiX-and-Arduino-IDE/
https://bbs.sipeed.com/t/topic/986