将Keras多输入_形状转换为TensorFlow Lite
我们应该如何将多输入_形模型从Keras转换为Tensorflow Lite 我试图将其转换为:将Keras多输入_形状转换为TensorFlow Lite,keras,tensorflow-lite,Keras,Tensorflow Lite,我们应该如何将多输入_形模型从Keras转换为Tensorflow Lite 我试图将其转换为: { "class_name": "Model", "keras_version": "2.2.4", "config": { "layers": [ { "class_name
{
"class_name": "Model",
"keras_version": "2.2.4",
"config": {
"layers": [
{
"class_name": "InputLayer",
"config": {
"dtype": "float32",
"batch_input_shape": [
null,
null,
null,
3
],
"name": "input",
"sparse": false
},
"inbound_nodes": [],
"name": "input"
},
...
因此:
import sys, os
import tensorflow as tf
import traceback
from os.path import splitext, basename
print(tf.__version__)
mod_path = "wpod-net_update1.h5"
def load_model(path,custom_objects={},verbose=0):
#from tf.keras.models import model_from_json
path = splitext(path)[0]
with open('wpod-net.json','r') as json_file:
model_json = json_file.read()
model = tf.keras.models.model_from_json(model_json, custom_objects=custom_objects)
model.load_weights('%s.h5' % path)
if verbose: print('Loaded from %s' % path)
return model
keras_mod = load_model(mod_path)
converter = tf.lite.TFLiteConverter.from_keras_model(keras_mod)
tflite_model = converter.convert()
# Save the TF Lite model.
with tf.io.gfile.GFile('wpod-net-1.tflite', 'wb') as f:
f.write(tflite_model)
但我的输出如下所示:
因此,如果我理解正确,它说所需的输入是1像素的RGB图像
当我使用TensorFlow Lite时,是否可以保持此变量输入形状行为?
还是应该将3null
替换为某个常量
只是想让你知道,我没有创建模型,它来自于TFLite converter不能很好地处理动态输入形状。解决方案是将之前的转换设置为固定大小,并在推断之前对其进行更改,请参阅