我试着写#34;清洁"码。我想做的是
if(var exists)
var = tf.get_variable(...)
else
var = init_var
我尝试使用try-except执行此操作,如下所示:
try:
with scope('my scope'):
var = tf.get_variable('v', reuse=True)
except ValueError:
with scope('my scope'):
var = tf.get_variable('v', reuse=False)
但这似乎不起作用。 我尝试过在线查找示例,但是我还没有发现任何与我试图解决的案件有关的事情,即干净地使用大型网络,几乎每个变量都在不同的范围内。
答案 0 :(得分:1)
tf.get_variable()没有重用参数。
这个问题已在这里得到解答: Tensorflow variable scope: reuse if variable exists