繁体   English   中英

使用 AI 平台进行预测时,“表未初始化”

[英]`Table not initialized` when predicting with AI-platform

我正在尝试保存更快的 R-CNN 集线器 model 并将其与 AI-platform 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的代码:

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")加载并使用它进行预测时,model 可以工作,但不能使用 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 的 Output:

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)

暂无
暂无

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

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