kendryte / nncase

Open deep learning compiler stack for Kendryte AI accelerators ✨
Apache License 2.0
748 stars 181 forks source link

tflite模型通过nncase转换为kmodel后输出结果变为随机数 #614

Closed Vbirdlook closed 2 years ago

Vbirdlook commented 2 years ago

Describe the bug A clear and concise description of what the bug is. tflite模型通过nncase转换为kmodel后输出结果变为随机数 To Reproduce Command line or scripts to reproduce the behavior: 十分类任务,模型训练后测试集准确率0.99 保存模型model.save('model.h5') 将h5文件转换为tflite import tensorflow as tf modelparh ='model.h5' model = tf.keras.models.load_model(modelparh) converter = tf.lite.TFLiteConverter.from_keras_model(model) tflite_model = converter.convert()

'model.tflite'是输出的文件名

savepath = r'model.tflite' open(savepath, "wb").write(tflite_model) tflite转kmodel python程序采用nncase使用说明中“”编译uint8量化tflite模型"示例 Expected behavior A clear and concise description of what you expected to happen.

Origin model and code If applicable, add orgin model and code to help explain your problem.

Environment (please complete the following information):

Additional context Add any other context about the problem here. 问题解决方法:不使用ptq PC端推理结果正确,准确率为0.99 可能原因:converter = tf.lite.TFLiteConverter.from_keras_model(model)这一步已经进行了量化,(源h5模型大小为5814kb,tflite模型大小为1922kb)nncase再次量化造成结果出错 但k210推理仍为随机数

curioyang commented 2 years ago

转tflite的时候别转定点的,直接用浮点模型来编译kmodel

curioyang commented 2 years ago

模型, 编译脚本, 测试图片 ,测试结果都上传一下