Tensorflow如何在tf.variable_scope中重置重用

时间:2018-11-24 08:30:53

标签: tensorflow

我想在设置了复用=真的范围内将复用重设为False。我只是用tf.variable_scope(name,复用= False)重置了它,但似乎不起作用。像这样的代码

def scope_test(ema, name,reuse):
    with tf.variable_scope(name, reuse=reuse):
        v = tf.get_variable("v")
    with tf.variable_scope(name, reuse=False)
        ema_apply_op = ema.apply([batch_mean, batch_var])

ema = tf.train.ExponentialMovingAverage()    
with tf.variable_scope("layer1", reuse=False):
    g = tf.get_variable("g")
    scope_test(ema, name="bn1", reuse=False)
with tf.variable_scope("layer1",reuse=True):
    g = tf.get_variable("g")
    scope_test(ema, name="bn1",reuse=True)

然后此代码将显示错误,layer1 / bn1 / moments / Squeeze / ExponentialMovingAverage /不存在,或者不是使用tf.get_variable()创建的。您是说要在VarScope中设置“ reuse = None”? 如何解决这个问题?

0 个答案:

没有答案
相关问题