def __call__(self, x, test):
h = F.relu(self.b1(self.c1(x), test=test))
h = self.b2(self.c2(h), test=test)
if x.data.shape != h.data.shape:
xp = chainer.cuda.get_array_module(x.data)
n, c, hh, ww = x.data.shape
pad_c = h.data.shape[1] - c
p = xp.zeros((n, pad_c, hh, ww), dtype=xp.float32)
p = chainer.Variable(p, volatile=test)
x = F.concat((p, x))
if x.data.shape[2:] != h.data.shape[2:]:
x = F.average_pooling_2d(x, 1, 2)
return h + x
评论列表
文章目录