开始使用Tensorflow

开始使用Tensorflow,tensorflow,tflearn,Tensorflow,Tflearn,我是Tensorflow的新手,尝试运行示例代码,但我无法理解该程序中发生了什么: 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

我是Tensorflow的新手,尝试运行示例代码,但我无法理解该程序中发生了什么:

    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 `numpy_input_fn`. We have to tell the function how many batches
# of data (num_epochs) we want and how big each batch should be.
x = np.array([1., 2., 3., 4.])
y = np.array([0., -1., -2., -3.])
input_fn = tf.contrib.learn.io.numpy_input_fn({"x":x}, y, batch_size=4,
                                              num_epochs=1000)

# We can invoke 1000 training steps by invoking the `fit` method and passing the
# training data set.
estimator.fit(input_fn=input_fn, steps=1000)

# Here we evaluate how well our model did. In a real example, we would want
# to use a separate validation and testing data set to avoid overfitting.
estimator.evaluate(input_fn=input_fn)
有人能解释一下从输入行开始发生了什么吗。 批处理大小是否为输入数据的大小?既然我告诉估计器它需要1000步,为什么我需要num_历元


提前谢谢

欢迎来到TensorFlow。下一行:input_fn=tf.contrib.learn.io.numpy_input_fn{x:x},y,batch_size=4, num_epochs=1000生成一个函数输入_fn,该函数输入随后传递给该方法。适合使用线性回归器估计器生成的估计器对象。输入\u fn将提供批量\u size=4功能和目标,最多1000倍于num\u epochs=1000。批次大小是指最小批次大小。“On Epoch”是一个完整的训练示例。在这种情况下,该输入提供的训练数据中只有4个示例。 这是一个很好的例子,因为随机梯度下降对于解决这个线性回归问题是不必要的,但它向您展示了解决更棘手问题所必需的机制