ML引擎服务似乎未按预期工作

时间:2019-01-21 10:30:37

标签: tensorflow tensorflow-serving google-cloud-ml

使用以下代码并进行gcloud ml-engine local本地预测时,我得到了:

  

InvalidArgumentError(请参阅上面的回溯):您必须提供一个值   用于具有dtype字符串和形状[?]的占位符张量“占位符”            [[节点:占位符= Placeholderdtype = DT_STRING,形状= [?],_ device =“ / job:localhost /副本:0 /任务:0 /设备:CPU:0”]](错误代码:2)

tf_files_path = './tf'
# os.makedirs(tf_files_path)  # temp dir
estimator =\
    tf.keras.estimator.model_to_estimator(keras_model_path="model_data/yolo.h5",
                                            model_dir=tf_files_path)

#up_one_dir(os.path.join(tf_files_path, 'keras'))

def serving_input_receiver_fn():
    def prepare_image(image_str_tensor):
        image = tf.image.decode_jpeg(image_str_tensor,
                                    channels=3)
        image = tf.divide(image, 255)
        image = tf.image.convert_image_dtype(image, tf.float32)
        return image

    # Ensure model is batchable
    # https://stackoverflow.com/questions/52303403/
    input_ph = tf.placeholder(tf.string, shape=[None])
    images_tensor = tf.map_fn(
                prepare_image, input_ph, back_prop=False, dtype=tf.float32)

    return tf.estimator.export.ServingInputReceiver(
        {model.input_names[0]: images_tensor},
        {'image_bytes': input_ph})

export_path = './export'
estimator.export_savedmodel(
    export_path,
    serving_input_receiver_fn=serving_input_receiver_fn)

我要发送给ml引擎的json如下:

{"image_bytes": {"b64": "/9j/4AAQSkZJRgABAQAAAQABAAD/2w..."}}

当不进行局部预测,而是将其发送到ML引擎本身时,我得到:

ERROR: (gcloud.ml-engine.predict) HTTP request failed. Response: {
"error": {
"code": 500,
"message": "Internal error encountered.",
"status": "INTERNAL"
}
}

Saved_model_cli给出:

saved_model_cli show --all --dir export/1547848897/

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

signature_def['serving_default']:
The given SavedModel SignatureDef contains the following input(s):
inputs['image_bytes'] tensor_info:
dtype: DT_STRING
shape: (-1)
name: Placeholder:0
The given SavedModel SignatureDef contains the following output(s):
outputs['conv2d_59'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, 255)
name: conv2d_59/BiasAdd:0
outputs['conv2d_67'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, 255)
name: conv2d_67/BiasAdd:0
outputs['conv2d_75'] tensor_info:
dtype: DT_FLOAT
shape: (-1, -1, -1, 255)
name: conv2d_75/BiasAdd:0
Method name is: tensorflow/serving/predict

有人看到这里出了什么问题吗?

1 个答案:

答案 0 :(得分:0)

问题已解决。该模型的输出似乎太大,以至于ml-engine无法将其发送回去,并且它没有捕获比500内部错误更相关的异常。我们在模型中添加了一些后处​​理步骤,现在可以正常使用了。

对于返回错误的gcloud ml-engine本地本地预测命令,这似乎是一个错误。由于该模型现在可以在ml-engine上运行,但仍会通过局部预测返回此错误。