Conv2DTranspose输出计算
输入图片矩阵为:NxN
# 卷积核大小,kernel_size:FxF
# 步长strides:S
# 边界扩充padding的值:P
则,输出大小W:
W
=
(
N
−
1
)
∗
S
−
2
P
+
F
W=(N−1)∗S−2P+F
W=(N−1)∗S−2P+F
举个例子,生成器将二分类转化为64643的图片
class Generator(keras.Model):
def __init__(self):
super(Generator, self).__init__()
# z:[b, 100]=>[b, 64, 64, 3]
self.fc = layers.Dense(3*3*512)
# (N−1)∗S−2P+F (3-1)*3 +3 =9
self.conv1 = layers.Conv2DTranspose(256, 3, 3, 'valid')
self.bn1 = layers.BatchNormalization()
# (9-1) * 2 + 5 =21
self.conv2 = layers.Conv2DTranspose(128, 5, 2, 'valid')
self.bn2 = layers.BatchNormalization()
# (23-1) * 3 + 4 =64
self.conv3 = layers.Conv2DTranspose(3, 4, 3, 'valid')
def call(self, inputs, training=None):
x = self.fc(inputs)
x = tf.reshape(x, [-1, 3, 3, 512])
x = tf.nn.leaky_relu(x)
x = tf.nn.leaky_relu(self.bn1(self.conv1(x),training=training))
x = tf.nn.leaky_relu(self.bn2(self.conv2(x), training=training))
x = self.conv3(x)
x = tf.tanh(x)
return x