【问题标题】:In Tensorflow, can I use tf.gather() for partial connection?在 Tensorflow 中,我可以使用 tf.gather() 进行部分连接吗?
【发布时间】:2016-04-19 16:35:13
【问题描述】:

我正在尝试实现层之间的部分连接。假设我只想使用一些特征图,例如第一个和第三个。

  • 为此目的使用 tf.gather() 是否正确?
  • 我可以只使用索引运算符 [ ] 而不是 tf.gather() 吗?
  • 在反向传播方面收集索引是否有效?我很难想象 Tensorflow 如何在内部知道连接来自内部反向传播过程中的第一个和第三个(哪些信息是硬编码的)。函数 tf.gather 是否记得连接?

代码:

# let say, L1 is layer1 output of shape [batch_size x image_size x image_size x depth1]
partL1 = L1[:, :, :, [0,2]]
# W2 is a tf variable of shape [5, 5, 2, depth2]
conv2 = tf.nn.conv2d(partL1, W2)

【问题讨论】:

    标签: python tensorflow deep-learning


    【解决方案1】:

    是的,不,是的。 :-) (a) 是的,您可以按照您的建议,使用gather 选择一个层的子集以传播到下一层。

    (b) 不,很遗憾,您不能使用索引运算符。您需要显式调用tf.gather()。

    (c) 是的,TensorFlow 将存储用于收集的索引的副本并将它们保存以用于反向传播。如果您对如何操作感到好奇,可以查看the implementation of Gather's Gradient - 它查看操作的输入并使用这些输入进行传播。

    【讨论】:

      猜你喜欢
      • 2011-08-05
      • 2016-07-24
      • 2018-09-30
      • 1970-01-01
      • 1970-01-01
      • 2020-09-07
      • 1970-01-01
      • 2014-08-02
      • 2013-03-03
      相关资源
      最近更新 更多