相当于链接器中的 tf.dense
equivalent of tf.dense in chainer
正如 tf.dense 的文档所述,该层的输出张量与输入的形状相同,除了最后一个维度是大小单位。我试图在 Chainer 中有类似的行为,但我没有成功。
在 Tensorflow 中,可以有一个 (32, 28, 28, 512) 张量并将其作为输入提供给线性层并得到 (32, 28, 28, 256)。正如我 关于 tf.dense 一样,当输入的维度超过 2 维时,它会共享权重并且在执行函数之前不会展平输入。
chainer.links.Linear 确实使输入变平,因此它不适合内存。我想知道是否有可能在 Chainer 中以某种方式具有与 tf.dense 相同的功能?
应用L.Linear
前后reshape
的输入如何?
import chainer.functions as F
import chainer.links as L
l = L.Linear(512, 256)
# x is (32, 28, 28, 512)
s0, s1, s2, s3 = x.shape
h= F.reshape(x, (s0*s1*s2, s3)
h = l(h)
h = F.reshape(x, (s0, s1, s2, 256))
# Now h should be (32, 28, 28, 256)
正如 tf.dense 的文档所述,该层的输出张量与输入的形状相同,除了最后一个维度是大小单位。我试图在 Chainer 中有类似的行为,但我没有成功。
在 Tensorflow 中,可以有一个 (32, 28, 28, 512) 张量并将其作为输入提供给线性层并得到 (32, 28, 28, 256)。正如我
chainer.links.Linear 确实使输入变平,因此它不适合内存。我想知道是否有可能在 Chainer 中以某种方式具有与 tf.dense 相同的功能?
应用L.Linear
前后reshape
的输入如何?
import chainer.functions as F
import chainer.links as L
l = L.Linear(512, 256)
# x is (32, 28, 28, 512)
s0, s1, s2, s3 = x.shape
h= F.reshape(x, (s0*s1*s2, s3)
h = l(h)
h = F.reshape(x, (s0, s1, s2, 256))
# Now h should be (32, 28, 28, 256)