【问题标题】:Unable to make predictions on google cloud ml, whereas same model is working on the local machine无法在 google cloud ml 上进行预测,而相同的模型正在本地机器上运行
【发布时间】:2018-11-21 10:31:35
【问题描述】:

我正在尝试在谷歌云中训练机器学习模型 usinf tensorflow 库。创建存储桶后,我可以在云中训练模型。当我尝试使用现有模型进行预测时,我遇到了这个问题。代码和数据可在以下 Github 目录中找到。 https://github.com/terminator172/game-price-predictions

云上的tensorflow版本是1.8,我系统上的tensorflow版本也是1.8

我尝试通过提供以下输入来进行预测 "gcloud ml-engine predict --model=earnings --version=v8 --json-instances=sample_input_prescaled.json"

出现以下错误 "{ "error": "预测失败:模型执行期间出错:AbortionError(code=StatusCode.FAILED_PRECONDITION, details=\"尝试使用未初始化的值 output/biases4\n\t [[Node: output/biases4/read = IdentityT=DT_FLOAT , _output_shapes=[[1]], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]]\")" }"

【问题讨论】:

    标签: python tensorflow machine-learning google-cloud-ml


    【解决方案1】:

    错误消息表明并非所有变量都已初始化。 CloudML 示例中有一些示例代码演示了如何处理初始化 (link) 另外,我建议在较新版本的 TF 上使用tf.saved_model.simple_save。尝试对您的代码进行以下更改:

    def main_op():
      init_local = variables.local_variables_initializer()
      init_tables = lookup_ops.tables_initializer()
      return control_flow_ops.group(init_local, init_tables)
    
    [...snip...]    
    
    # This replaces everything from your SavedModelBuilder on
    tf.saved_model.simple_save(
        session,
        export_dir='exported_model',
        inputs={'input': X},
        outputs={'earnings': prediction},
        legacy_init_op=main_op)  # This line is important
    

    【讨论】:

      【解决方案2】:

      您在 gcloud 中的模型目录(您提供的带有 --model 标志的目录)应该包含 2 个内容:

      1. saved_model.pb 文件,包含实际的 TensorFlow 程序或模型,以及一组命名签名,每个签名都标识一个接受张量输入并产生张量输出的函数。

      2. variables 目录,包含标准训练检查点。

      如果您的variables 目录丢失并且您只有saved_model.pb 文件,您可能会收到此Attempting to use uninitialized value 错误。为了修复它,您只需将 variables 目录添加到 gcloud 中的模型目录即可。

      参考:Tensorflow SavedModel format

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-15
        • 1970-01-01
        • 2018-07-20
        • 2018-06-06
        • 2022-01-12
        • 1970-01-01
        • 2019-03-20
        相关资源
        最近更新 更多