Python 无法使用从keras保存的模型对图像输入使用联机预测服务

Python 无法使用从keras保存的模型对图像输入使用联机预测服务,python,tensorflow,keras,google-cloud-ml,Python,Tensorflow,Keras,Google Cloud Ml,请考虑以下代码以创建保存的_模型 import tensorflow as tf from tensorflow.keras.layers import Input, Lambda from tensorflow.keras.models import Model inp = Input((), dtype=tf.string, name="image_bytes") net = Lambda(lambda t: tf.map_fn(lambda x: tf.io.decode_jpeg(x)

请考虑以下代码以创建保存的_模型

import tensorflow as tf
from tensorflow.keras.layers import Input, Lambda
from tensorflow.keras.models import Model

inp = Input((), dtype=tf.string, name="image_bytes")
net = Lambda(lambda t: tf.map_fn(lambda x: tf.io.decode_jpeg(x), t, dtype=tf.uint8))(inp)
net = Lambda(lambda t: tf.map_fn(lambda x: tf.io.encode_jpeg(x), t, dtype=tf.string), name="output")(net)

model = Model(inp, net, name="test_network")

tf.keras.experimental.export_saved_model(model, "runs/cmle_test_model", serving_only=True)
现在,我正在尝试获取一个在线预测请求来处理有效负载

{"image_bytes":{"b64":"/9j/..."}}
全有效载荷

哪些错误与

{
  "error": "Prediction failed: Error during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"Expected input[1] == 'test_network/output/map/TensorArrayUnstack/TensorListFromTensor/element_shape:output:0' to be a control input.\n\tIn {{node test_network/lambda/map/TensorArrayV2Stack/TensorListStack}}\n\t [[{{node StatefulPartitionedCall}}]]\n\t [[{{node StatefulPartitionedCall}}]]\")"
}
然而,如果我只是这样做的话

out = model(data)
它很好用

更新:

我有工作要做

inp = Input((), dtype=tf.string, name="image_bytes")
net = Lambda(lambda t: tf.expand_dims(tf.io.decode_jpeg(t[0]), 0))(inp)
net = Lambda(lambda t: tf.expand_dims(tf.io.encode_base64(tf.io.encode_jpeg(t[0])), 0), name="output")(net)

但这将服务的可用批处理大小固定为1。理想情况下,我希望将
Lambda
层与
tf.map\u fn

一起使用。请通过添加代码片段或通过github url共享完整的代码。请尝试提供的第一个代码片段。它应该是完整的。请通过添加代码片段或通过github url共享完整的代码。请尝试提供的第一个代码片段。它应该是完整的。