我正在建立一个神经网络,它并行处理两组图像。我希望这两列共享参数。我就是这么做的。
with tf.variable_scope(layer_name) as s: h1 = tf.contrib.layers.convolution2d(inputs = x1, num_outputs = 10, kernel_size = [3, 3], stride = [1, 1], padding = 'VALID', scope = s) h2 = tf.contrib.layers.convolution2d(inputs = x2, num_outputs = 10, kernel_size = [3, 3], stride = [1, 1], padding = 'VALID', reuse = True, scope = s)
这样做对吗?在使用tf.contrib.layers.convolution2d类时,我找不到如何正确地这样做的例子。
发布于 2016-11-15 20:48:32
这是不正确的,把它变成这样的函数:
def function(x, reuse):
with tf.variable_scope(layer_name) as s:
output = tf.contrib.layers.convolution2d(inputs = x, num_outputs = 10, kernel_size = [3, 3],
stride = [1, 1], padding = 'VALID', reuse = reuse, scope = s)
return output
output1 = function(image1, False)
output2 = function(image2, True)现在,当使用不同的输入调用时,同样的权重将被重用。
https://stackoverflow.com/questions/40618560
复制相似问题