【发布时间】:2021-03-16 18:31:54
【问题描述】:
我构建了波纹管卷积自动编码器,并尝试对其进行调整以在不增加损失的情况下获得 [NxHxW] = 1024 的编码器输出形状 (x_encoder)。目前我的输出形状是 [4, 64, 64] 有什么想法吗?
# define the NN architecture
class ConvAutoencoder(nn.Module):
def __init__(self):
super(ConvAutoencoder, self).__init__()
## encoder layers ##
# conv layer (depth from in --> 16), 3x3 kernels
self.conv1 = nn.Conv2d(1, 16, 3, padding=1)
# conv layer (depth from 16 --> 4), 3x3 kernels
self.conv2 = nn.Conv2d(16, 4, 3, padding=1)
# pooling layer to reduce x-y dims by two; kernel and stride of 2
self.pool = nn.MaxPool2d(2, 2)
## decoder layers ##
## a kernel of 2 and a stride of 2 will increase the spatial dims by 2
self.t_conv1 = nn.ConvTranspose2d(4, 16, 2, stride=2)
self.t_conv2 = nn.ConvTranspose2d(16, 1, 2, stride=2)
def forward(self, x):
## encode ##
# add hidden layers with relu activation function
# and maxpooling after
x = F.relu(self.conv1(x))
x = self.pool(x)
# add second hidden layer
x = F.relu(self.conv2(x))
x = self.pool(x) # compressed representation
x_encoder = x
## decode ##
# add transpose conv layers, with relu activation function
x = F.relu(self.t_conv1(x))
# output layer (with sigmoid for scaling from 0 to 1)
x = F.sigmoid(self.t_conv2(x))
return x, x_encoder
【问题讨论】:
-
只用两个卷积层是不可能得到 1024*1024 的形状的。
-
@planet_pluto 抱歉不是 1024x1024,例如 [1,32,32] 或 [16,8,8] 可以视为 1024。
标签: pytorch artificial-intelligence conv-neural-network autoencoder