首页 文章

无法对google cloud ml进行预测,而同一型号正在本地计算机上运行

提问于
浏览
0

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

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

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

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

1 回答

  • 0

    错误消息表明并非所有变量都已初始化 . 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
    

相关问题