我正在尝试完成TensorFlow第一个教程的第二部分: https://www.tensorflow.org/get_started/get_started
“基本用法”:
!=
有人可以解释一下,这段代码中隐藏的计算图在哪里?
我没有看到对import tensorflow as tf
# NumPy is often used to load, manipulate and preprocess data.
import numpy as np
# Declare list of features. We only have one real-valued feature. There are many
# other types of columns that are more complicated and useful.
features = [tf.contrib.layers.real_valued_column("x", dimension=1)]
# An estimator is the front end to invoke training (fitting) and evaluation
# (inference). There are many predefined types like linear regression,
# logistic regression, linear classification, logistic classification, and
# many neural network classifiers and regressors. The following code
# provides an estimator that does linear regression.
estimator = tf.contrib.learn.LinearRegressor(feature_columns=features)
# TensorFlow provides many helper methods to read and set up data sets.
# Here we use two data sets: one for training and one for evaluation
# We have to tell the function how many batches
# of data (num_epochs) we want and how big each batch should be.
x_train = np.array([1., 2., 3., 4.])
y_train = np.array([0., -1., -2., -3.])
x_eval = np.array([2., 5., 8., 1.])
y_eval = np.array([-1.01, -4.1, -7, 0.])
input_fn = tf.contrib.learn.io.numpy_input_fn({"x":x_train}, y_train,
batch_size=4,
num_epochs=1000)
eval_input_fn = tf.contrib.learn.io.numpy_input_fn(
{"x":x_eval}, y_eval, batch_size=4, num_epochs=1000)
# We can invoke 1000 training steps by invoking the method and passing the
# training data set.
estimator.fit(input_fn=input_fn, steps=1000)
# Here we evaluate how well our model did.
train_loss = estimator.evaluate(input_fn=input_fn)
eval_loss = estimator.evaluate(input_fn=eval_input_fn)
print("train loss: %r"% train_loss)
print("eval loss: %r"% eval_loss)
或tf.Graph()
的任何来电。
tf.Session()
变量用于什么?数据似乎永远不会进入,因为数据提供者是'input_fn'。
如何查看会话和图表的实际计算图?
为什么有两个地方我设定了时代数? (features
和estimator.fit
)
如果我有numpy_input_fn
和estimator1.fit(..., steps=20)
两个不同的估算器怎么办?
我需要设置estimator2.fit(..., steps=50)
吗?还是num_epochs=70
?
如果从num_epochs=max(20,50)
调用线程数,input_fn
如何控制线程数,反之亦然?
答案 0 :(得分:0)
Tensorflow为您创建默认计算图。所以所有的 您在上面定义的变量和操作将是默认值 图形。会话在估算函数内定义。对于 示例estimator.fit()创建一个受监控的培训会话。
它用于初始化LinearRegressor()模型。线性回归参数基于特征变量设置。
input_fn是一个队列,所以' input_fn'告诉了多少次 每个输入数据都需要弹出到队列中。适合的时代'措施 每次输入需要在训练中使用多少次。因此,如果您的拟合时期大于队列时期,则训练将在队列时停止 停止。
" input_fn'时期应该大于或等于 估计中的时代。