2017-04-12 111 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)