首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用tf.contrib.layers.convolution2d时共享参数

使用tf.contrib.layers.convolution2d时共享参数
EN

Stack Overflow用户
提问于 2016-11-15 19:54:51
回答 1查看 1.5K关注 0票数 1

我正在建立一个神经网络,它并行处理两组图像。我希望这两列共享参数。我就是这么做的。

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类时,我找不到如何正确地这样做的例子。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-15 20:48:32

这是不正确的,把它变成这样的函数:

代码语言:javascript
复制
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)

现在,当使用不同的输入调用时,同样的权重将被重用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40618560

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档