2017-06-24 43 views
-2

我試圖通過TensorFlow的第一個教程的第二部分獲得: https://www.tensorflow.org/get_started/get_started有人可以解釋我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 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()

什麼是features變量用於?數據似乎永遠不會進入,因爲數據提供者是'input_fn'。 如何查看會話和圖形的實際計算圖形?

爲什麼有兩個地方我設定了時代的數量? (estimator.fitnumpy_input_fn

如果我有兩個不同的估計值estimator1.fit(..., steps=20)estimator2.fit(..., steps=50)怎麼辦? 我需要設置num_epochs=70嗎?或者num_epochs=max(20,50)? 如何從fit調用input_fn控制線程的數量,反之亦然?

回答

0
  1. tf.Graph()ot tf.Session()?

Tensorflow會爲您創建一個默認計算圖。因此,上面定義的所有 變量和操作都將使用默認的 圖表。會話是在估計器函數內部定義的。對於 示例estimator.fit()將創建一個受監視的培訓課程。

  1. 什麼是功能變量用於?

它用於給init LinearRegressor()模型。線性迴歸參數是基於特徵變量設置的。

  1. epochs set in input_fn and estimator?

的input_fn是隊列,所以在「input_fn」劃時代告訴需要每個輸入數據多少次 被彈出到隊列中。 「適合」的時期測量 每次輸入需要在訓練中使用多少次。所以如果你的適應期大於排隊時期,當隊列 停止時,訓練將停止。

  1. 兩個不同估計器的隊列大小。

在「input_fn」劃時代應大於或等於總結在估計的 曆元。

相關問題