首页 > 解决方案 > 如何在 ML Engine 上调试预测,预测返回空数组

问题描述

我正在实现一个 tfx 管道,类似于芝加哥出租车示例 推送模型的预测返回{"predictions": []}。我该如何调试这个问题?

我可以看到正在做出的预测的日志。但是因为它返回一个空数组,所以状态码是 200,并且没有关于出错的有用信息。我希望预测请求数据没有正确传递给估计器。

芝加哥示例使用它作为他们的服务接收器并且有效。我认为它也应该适用于我的示例

def _example_serving_receiver_fn(transform_output, schema):
    """Build the serving in inputs.
    Args:
        transform_output: directory in which the tf-transform model was written
        during the preprocessing step.
        schema: the schema of the input data.
    Returns:
        Tensorflow graph which parses examples, applying tf-transform to them.
    """

    raw_feature_spec = _get_raw_feature_spec(schema)
    raw_feature_spec.pop(_LABEL_KEY)

    raw_input_fn = tf.estimator.export.build_parsing_serving_input_receiver_fn(
        raw_feature_spec, default_batch_size=None)

    serving_input_receiver = raw_input_fn()

    transformed_features = transform_output.transform_raw_features(
        serving_input_receiver.features)

    return tf.estimator.export.ServingInputReceiver(
        transformed_features, serving_input_receiver.receiver_tensors)

主要区别在于我只期望 1 个输入:一串由 . 分隔的编程语言'|': 'java|python'

然后,我在我的预处理函数中将该字符串拆分并使其成为形状为 500 的多一热编码数组(我正好有 500 个选项)

也可能是预测没有被 tf transform 正确转换的情况。(tf 转换是 tfx 管道的一部分并且运行正确)

要求:{"instances": ["javascript|python"]}

回复:{"predictions": []}

预期响应:({"predictions": [520]}它是一个回归模型)

标签: google-cloud-platformtensorflow-servinggoogle-cloud-mltfx

解决方案


推荐阅读