简体   繁体   English

keras 和 tensorflow lite model 之间的预测差异

[英]Prediction differences between keras and tensorflow lite model

I've created keras model to recognize human activity, based on data from mobile accelerometer:根据来自移动加速度计的数据,我创建了 keras model 来识别人类活动:

model = Sequential()
model.add(Reshape((const.PERIOD, const.N_FEATURES), input_shape=(240,)))
model.add(Conv1D(100, 10, activation='relu', input_shape=(const.PERIOD, const.N_FEATURES)))
model.add(Conv1D(100, 10, activation='relu'))
model.add(MaxPooling1D(const.N_FEATURES))
model.add(Conv1D(160, 10, activation='relu'))
model.add(Conv1D(160, 10, activation='relu'))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(7, activation='softmax'))
model.summary()
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

I've tested model, and the accuracy after ten epochs is like 85-90%.我已经测试过 model,十个 epoch 后的准确率大约是 85-90%。 I don't know, but when I converse my model to TF Lite and I run interpreter in my android app, there's horrible predictions.我不知道,但是当我将 model 转换为 TF Lite 并在我的 android 应用程序中运行解释器时,会有可怕的预测。 What can be reason of that bad results?结果不好的原因是什么? No compatibility on keras -> tensorflow -> tensorflow lite line? keras -> tensorflow -> tensorflow lite line 不兼容? Should I run it with another way, using something like servlet + keras model?我应该以另一种方式运行它,使用类似 servlet + keras model 之类的东西吗?

A few suggestions:几点建议:

  1. Try to visualize your tflite graph with https://lutzroeder.github.io/netron/ .尝试使用https://lutzroeder.github.io/netron/可视化您的 tflite 图。 See if there's anything unexpected.看看有没有什么意外。
  2. Try to debug with tensorflow lite's python API first.首先尝试使用 tensorflow lite 的 python API 进行调试。 Feed the same input to the keras model and tflite model and compare the output tensor.将相同的输入输入到 keras model 和 tflite model 并比较 Z78E6221F6393D1356D8681

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM