我正在尝试使用谷歌云中的张量流库训练机器学习模型。创建存储桶后,我可以在云中训练模型。当我尝试使用现有模型进行预测时,我遇到了这个问题。代码和数据可以在以下 Github 目录中找到。https://github.com/terminator172/game-price-predictions
云上的tensorflow版本是1.8,我系统上的tensorflow版本也是1.8
我尝试通过给出以下输入来进行预测
“gcloud ml-engine 预测 --model=earnings --version=v8 --json-instances=sample_input_prescaled.json”
它因以下错误而出错
“{
“错误”:“预测失败:模型执行期间出错:AbortionError(code=StatusCode.FAILED_PRECONDITION,详细信息=\“尝试使用未初始化的值output/biases4\n\t [[节点:output/biases4/read = IdentityT=DT_FLOAT , _output_shapes=[[1]], _device=\"/job:localhost/replica:0/task:0/device:CPU:0\"]]\")"
}”
错误消息表明并非所有变量都已初始化。 CloudML 示例中有一些示例代码演示了如何处理初始化(link)另外,我建议使用tf.saved_model.simple_save在较新版本的 TF 上。尝试对您的代码进行以下更改:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)