Tensorflow `使用AI平台进行预测时未初始化表

Tensorflow `使用AI平台进行预测时未初始化表,tensorflow,keras,google-cloud-ml,Tensorflow,Keras,Google Cloud Ml,我试图保存更快的R-CNN中心模型,并将其与AI平台一起使用gcloud AI平台local predict。我得到的错误是: Failed to run the provided model: Exception during running the graph: [_Derived_] Table not initialized.\n\t [[{{node hub_input/index_to_string_1_Lookup}}]]\n\t [[StatefulPartitionedCal

我试图保存更快的R-CNN中心模型,并将其与AI平台一起使用
gcloud AI平台local predict
。我得到的错误是:

Failed to run the provided model: Exception during running the graph: [_Derived_]  Table not initialized.\n\t [[{{node hub_input/index_to_string_1_Lookup}}]]\n\t [[StatefulPartitionedCall_1/StatefulPartitionedCall/model/keras_layer/StatefulPartitionedCall]] (Error code: 2)\n'
保存模型的代码:

model_url = "https://tfhub.dev/google/faster_rcnn/openimages_v4/inception_resnet_v2/1"

input = tf.keras.Input(shape=(), dtype=tf.string)
decoded = tf.keras.layers.Lambda(
    lambda y: tf.map_fn(
        lambda x: tf.image.resize(
            tf.image.convert_image_dtype(
                tf.image.decode_jpeg(x, channels=3), tf.float32), (416, 416)
        ),
        tf.io.decode_base64(y), dtype=tf.float32)
)(input)

results = hub.KerasLayer(model_url, signature_outputs_as_dict=True)(decoded)

model = tf.keras.Model(inputs=input, outputs=results)
model.save("./saved_model", save_format="tf")
当我加载tf.keras.models.load_model(“./saved_model”)并使用它进行预测时,该模型工作,但不使用ai平台本地预测

ai平台本地预测命令:

gcloud ai-platform local predict --model-dir ./saved_model --json-instances data.json --framework TENSORFLOW
版本:

python 3.7.0
tensorflow==2.2.0
tensorflow-hub==0.7.0
保存的\u模型\u cli的输出:

MetaGraphDef with tag-set: 'serve' contains the following SignatureDefs:

signature_def['__saved_model_init_op']:
  The given SavedModel SignatureDef contains the following input(s):
  The given SavedModel SignatureDef contains the following output(s):
    outputs['__saved_model_init_op'] tensor_info:
        dtype: DT_INVALID
        shape: unknown_rank
        name: NoOp
  Method name is: 

signature_def['serving_default']:
  The given SavedModel SignatureDef contains the following input(s):
    inputs['image_bytes'] tensor_info:
        dtype: DT_STRING
        shape: (-1)
        name: serving_default_image_bytes:0
  The given SavedModel SignatureDef contains the following output(s):
    outputs['keras_layer'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 4)
        name: StatefulPartitionedCall_1:0
    outputs['keras_layer_1'] tensor_info:
        dtype: DT_STRING
        shape: (-1, 1)
        name: StatefulPartitionedCall_1:1
    outputs['keras_layer_2'] tensor_info:
        dtype: DT_INT64
        shape: (-1, 1)
        name: StatefulPartitionedCall_1:2
    outputs['keras_layer_3'] tensor_info:
        dtype: DT_STRING
        shape: (-1, 1)
        name: StatefulPartitionedCall_1:3
    outputs['keras_layer_4'] tensor_info:
        dtype: DT_FLOAT
        shape: (-1, 1)
        name: StatefulPartitionedCall_1:4
  Method name is: tensorflow/serving/predict

有没有关于如何修复错误的想法?

问题是您的输入被解释为标量。做:

input = tf.keras.Input(shape=(1,), dtype=tf.string)

您是否可以在导出的模型上运行saved_model_cli并查看其报告的内容?问题可能是输入层中缺少shape维度,无法获得回复。输入层的形状为:dtype:DT_字符串形状:(-1)名称:SERVICED_default_image_字节:0。预期的形状应该是什么?