【问题标题】:`Table not initialized` when predicting with AI-platform使用 AI 平台进行预测时,“表未初始化”
【发布时间】:2020-11-05 00:09:27
【问题描述】:

我正在尝试保存更快的 R-CNN 集线器模型并将其与 AI 平台 gcloud ai-platform 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

saved_model_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

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

【问题讨论】:

  • 您可以在导出的模型上运行 saved_model_cli 并查看它的报告吗?问题可能是输入层中缺少形状维度
  • 感谢您的回复。输入层的形状是:dtype: DT_STRING shape: (-1) name: serving_default_image_bytes:0。预期的形状应该是什么?

标签: tensorflow keras google-cloud-ml


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2021-11-01
    • 2020-06-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 1970-01-01
    • 2021-07-19
    相关资源
    最近更新 更多