google-cloud-ml-engine - 占位符张量需要 ml-engine 预测中的值但不是本地预测

标签 google-cloud-ml-engine

我一直在开发一个与云 ML 引擎的在线预测服务一起使用的模型。我的模型包含一个 placeholder_with_default 张量,我用它来保持预测重要性的阈值。

threshold = tf.placeholder_with_default(0.01, shape=(), name="threshold")

我注意到在使用本地预测时:

gcloud ml-engine local predict --json-instances=data.json --model-dir=/my/model/dir

我不需要为这个张量提供值。例如这是一个有效的输入:

{"features": ["a", "b"], "values": [10, 5]}

但是当使用在线预测时:

gcloud ml-engine predict --model my_model --version v1 --json-instances data.json

如果我使用上面的 JSON,我会得到一个错误:

{
    "error": "Prediction failed: Exception during model execution: AbortionError(code=StatusCode.INVALID_ARGUMENT, details=\"input size does not match signature\")"
}

但是,如果我包括阈值,那么我就不会。例如:

{"features": ["a", "b"], "values": [10, 5], "threshold": 0.01}

有没有办法让“阈值”成为可选输入?

谢谢

马修

最佳答案

目前看来在 CloudML 中是不可能的。如果您从 JSON 文件中获取预测,则需要显式添加默认值(就像您对 "threshold": 0.01 所做的那样)。

在 Python 中,我只是在执行 API 请求之前动态添加所需的属性:

def add_empty_fields(instance):
    placeholder_defaults = {"str_placeholder": "", "float_placeholder": -1.0}
    for ph, default_val in placeholder_defaults.items():
        if ph not in instance:
            instance[ph] = default_val

这会改变将占位符名称映射到占位符值的 instance 字典。对于具有许多可选占位符的模型,这比手动为每个实例设置缺失的占位符值要好一些。

关于google-cloud-ml-engine - 占位符张量需要 ml-engine 预测中的值但不是本地预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43976664/

相关文章:

python - Google ML 引擎和 Python 数据存储 API, 'Forbidden: 403 Request had insufficient authentication scopes.'

google-cloud-ml - 将重新训练的 inception SavedModel 部署到 google cloud ml 引擎

machine-learning - Google Cloud 上使用 GPU 的 Tensorflow

google-cloud-ml - cloud ml 预测 FAILED_PRECONDITION 和字段 [projectsId] 的值

gcloud - Google Cloud ML 上的 "Attempted relative import in non-package"

google-cloud-ml - 在谷歌云机器学习中读取文件

tensorflow - 由于 "A job with this id already exists"无法将作业重新提交到 ml-engine

machine-learning - GPU 在参数服务器上进行数据并行训练是否高效?

numpy - 使用 gcloud ml 为大图像服务