def forward(self):
pad = [[self.lay.pad, self.lay.pad]] * 2;
temp = tf.pad(self.inp.out, [[0, 0]] + pad + [[0, 0]])
k = self.lay.w['kernels']
ksz = self.lay.ksize
half = int(ksz / 2)
out = list()
for i in range(self.lay.h_out):
row_i = list()
for j in range(self.lay.w_out):
kij = k[i * self.lay.w_out + j]
i_, j_ = i + 1 - half, j + 1 - half
tij = temp[:, i_ : i_ + ksz, j_ : j_ + ksz,:]
row_i.append(
tf.nn.conv2d(tij, kij,
padding = 'VALID',
strides = [1] * 4))
out += [tf.concat(row_i, 2)]
self.out = tf.concat(out, 1)
评论列表
文章目录