2017-04-21 64 views
0

我做了一個TensorFlow估計具有一定的借鑑作用:TensorFlow:是否適合以相當於擬合1大增量的小步增量?

estimator = tf.contrib.learn.Estimator(
    model_fn=_model_fn_for_penguin_model, 
    model_dir=/tmp/penguin_classification, 
    config=tf.contrib.learn.RunConfig(
     save_summary_steps=5)) 

然後叫estimator.fit訓練模型。我注意到,如果我在小步增量(不批量大小)像10列車上,OptimizeLoss指標收斂:

step_increment = 10 
for step in xrange(0, 1e6, step_increment): 
    # Train for certain increment of steps. 
    estimator.fit(
     input_fn=_input_fn_for_train, steps=step_increment) 

我可以告訴基於TensorBoard(奇怪的是,損失我的評價數據集實際上增加...但可能是不相關的問題)

enter image description here

但是,如果我用一個更大的一步增量大小如200,損失上下波動:

step_increment = 200 
for step in xrange(0, 1e6, step_increment): 
    # Train for certain increment of steps. 
    estimator.fit(
     input_fn=_input_fn_for_train, steps=step_increment) 

這讓我困惑,因爲在我看來,上面的2個代碼片段應該在一天結束時做同樣的事情:訓練一百萬步的模型。情況並非如此嗎?

我不相信這是源於隨機播種 - 我可以一貫地重現這種行爲。

這裏是輸入功能。

def make_input_fn(mode): 
    def internal_input_fn(): 
    include_target = mode != tf.contrib.learn.ModeKeys.INFER 
    feature_spec = tf.contrib.layers.create_feature_spec_for_parsing(
     feature_columns=_get_feature_columns(
      include_target_column=include_target)) 
    feature_map = tf.contrib.learn.read_batch_features(
     batch_size=100, 
     features=feature_spec, 
     file_pattern=os.path.join("/tmp", mode + ".tfrecord"), 
     queue_capacity=250, 
     randomize_input=True, 
     reader=tf.TFRecordReader) 
    target = feature_map.pop() if include_target else None 
    return feature_map, target 
    return internal_input_fn 

回答

1

這些調用應該是等價的,但有一點需要記住的是input_fn的行爲。例如,如果它沒有隨機化,第一個案例可以循環多達1M個訓練樣例,而第二個案例將多次重複訪問相同的200個例子。

+0

我認爲我的輸入函數(發佈)確實做了隨機化。也許隨機化不適用於'tf.TFRecordReader'? – dangerChihuahua007

+0

隨機化適用於記錄閱讀器,但也許你沒有足夠的隨機性。 –