2017-04-12 109 views
0

我想在同一個TensorFlow會話中訓練和測試我的模型。我使用兩個不同的tf.FIFOQueue來使用多線程加載訓練和測試數據(因爲feed_dict導致性能較差)。我試了兩件事:TensorFlow:在同一環節中進行培訓和測試

  1. 我試着用共享參數兩次創建我的模型(用於培訓和測試)。但我使用的是tf.contrib.layers.batch_norm,它不允許共享批量標準化的參數。

  2. 我試圖調節我的網絡的輸入tf.FIFOQueue使用tf.condis_training布爾佔位符,但顯然tf.cond執行兩個tf.FIFOQueue小號出列功能,無論什麼is_training成立。

我想知道傳統設置在同一會話中如何訓練和測試,而不使用feed_dict

回答

1

顯然tf.contrib.layers.batch_norm確實允許共享批處理標準化參數,如果在全局tf.variable_scope中定義的話。

舉例:編碼:來自here

def model(data, is_training=False, reuse=None, scope='my_model'): 
    # Define a variable scope to contain all the variables of your model 
    with tf.variable_scope(scope, 'model', data, reuse=reuse): 
    .... 
    net = tf.contrib.layers.batch_norm(net, is_training) 
    return net 

train_outputs = model(train_data, is_training=True) 
eval_outputs = model(eval_data, is_training=False, reuse=True)