如何构建具有独立推理和训练部分的 TF Graph? [英] How can I build a TF Graph that has separate inference and training parts?

查看:26
本文介绍了如何构建具有独立推理和训练部分的 TF Graph?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考 这篇文章 之前问过,因为建议创建一个具有独立推理和训练部分的图.

Referencing this post asked previously, as the suggestion was to create a graph that has separate inference and training parts.

非常感谢样板代码.

推荐答案

存储库中的MNIST卷积就是一个例子——tensorflow/tensorflow/models/image/mnist/convolutional.py

MNIST convolution in the repository is an example -- tensorflow/tensorflow/models/image/mnist/convolutional.py

当您将模型构建代码分解为一个函数(convolutional.py 中的model)时,它遵循一种模式,并为评估和训练部分分别调用它

It follows a pattern when you factor out model construction code into a function (model in convolutional.py), and call it separately for the eval and training parts

 logits = model(train_data_node, True)
 loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(
      logits, train_labels_node))
 eval_prediction = tf.nn.softmax(model(eval_data))

对于训练,您输入 train_data_node 并最小化 loss,对于 eval,您输入 eval_data 节点并在 处获得结果评估预测

For training you feed into train_data_node and minimize loss, for eval, you feed into eval_data node and get the results at eval_prediction

这篇关于如何构建具有独立推理和训练部分的 TF Graph?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆