无法在Pytorch中实现模型
I have been trying to implement this paper (https://doi.org/10.1109/ICASSP40776.2020.9054563)。现在,在过去的几天里,我遇到了模型中的错误。 我想模仿的模型如下:
纸模型
class Net(nn.Module):
def __init__(self, upscale_factor = 2):
super(Net, self).__init__()
# self.input_start = nn.(16,256,3)
self.e1 = nn.Conv2d(16,16, (5,1),stride = (1,2),padding='valid')
self.e1_dr = nn.Dropout(.5)
self.e2 = nn.Conv2d(128,128, (5,1),stride = (1,2),padding='valid')
# self.e2.weight
self.e2_dr = nn.Dropout(.5)
self.e3 = nn.Conv2d(256, 256,(5,1),stride = (1,2),padding='valid')
self.e3_dr = nn.Dropout(.5)
self.e4 = nn.Conv2d(512, 512, (5,1),stride = (1,2),padding='valid')
self.e5 = nn.Conv2d(512,512, (5,1),stride = (2,2),padding='valid')
self.e6 = nn.Conv2d(512,512, (3,1),stride = (2,2),padding='valid')
self.e7 = nn.Conv2d(512,512, (3,1),stride = (2,2),padding='valid')
self.e8 = nn.Conv2d(512,512, (3,1),stride = (2,2),padding='valid')
self.d1 = nn.PixelShuffle(upscale_factor )
self.d2 = nn.PixelShuffle(upscale_factor)
self.d3 = nn.PixelShuffle(upscale_factor)
self.d4 = nn.PixelShuffle(upscale_factor)
self.d5 = nn.PixelShuffle(upscale_factor )
self.d6 = nn.PixelShuffle(upscale_factor)
self.d7 = nn.PixelShuffle(upscale_factor)
self.d8 = nn.PixelShuffle(upscale_factor)
def forward(self, x):
# x = (F.leaky_relu(self.input_start(x)))
x = (F.leaky_relu(self.e1(x)))
x = (F.leaky_relu(self.e1(x)))
x = (F.leaky_relu(self.e1_dr(x)))
x = (F.leaky_relu(self.e2(x)))
x = (F.leaky_relu(self.e2_dr(x)))
x = (F.leaky_relu(self.e3(x)))
x = (F.leaky_relu(self.e3_dr(x)))
x = (F.leaky_relu(self.e4(x)))
x = (F.leaky_relu(self.e5(x)))
x = (F.leaky_relu(self.e6(x)))
x = (F.leaky_relu(self.e7(x)))
x = (self.e8(x))
x = (F.leaky_relu(self.d1(x)))
x = (F.leaky_relu(self.d2(x)))
x = (F.leaky_relu(self.d3(x)))
x = (F.leaky_relu(self.d4(x)))
x = (F.leaky_relu(self.d5(x)))
x = (F.leaky_relu(self.d6(x)))
x = (F.leaky_relu(self.d7(x)))
x = (F.leaky_relu(self.d8(x)))
return x
每当我运行模型时,我都会收到以下错误: 给定的组= 1,大小的重量[128、128、5、1],预期输入[2、16、248、1]具有128个通道,但有16个通道。
I have been trying to implement this paper (https://doi.org/10.1109/ICASSP40776.2020.9054563). Now, for the last many days, I am stuck with an error in the model.
The model that I want to mimic is as follows:
Where deconvolution has been performed using subpixel layers.
The code for the model is as follows:
class Net(nn.Module):
def __init__(self, upscale_factor = 2):
super(Net, self).__init__()
# self.input_start = nn.(16,256,3)
self.e1 = nn.Conv2d(16,16, (5,1),stride = (1,2),padding='valid')
self.e1_dr = nn.Dropout(.5)
self.e2 = nn.Conv2d(128,128, (5,1),stride = (1,2),padding='valid')
# self.e2.weight
self.e2_dr = nn.Dropout(.5)
self.e3 = nn.Conv2d(256, 256,(5,1),stride = (1,2),padding='valid')
self.e3_dr = nn.Dropout(.5)
self.e4 = nn.Conv2d(512, 512, (5,1),stride = (1,2),padding='valid')
self.e5 = nn.Conv2d(512,512, (5,1),stride = (2,2),padding='valid')
self.e6 = nn.Conv2d(512,512, (3,1),stride = (2,2),padding='valid')
self.e7 = nn.Conv2d(512,512, (3,1),stride = (2,2),padding='valid')
self.e8 = nn.Conv2d(512,512, (3,1),stride = (2,2),padding='valid')
self.d1 = nn.PixelShuffle(upscale_factor )
self.d2 = nn.PixelShuffle(upscale_factor)
self.d3 = nn.PixelShuffle(upscale_factor)
self.d4 = nn.PixelShuffle(upscale_factor)
self.d5 = nn.PixelShuffle(upscale_factor )
self.d6 = nn.PixelShuffle(upscale_factor)
self.d7 = nn.PixelShuffle(upscale_factor)
self.d8 = nn.PixelShuffle(upscale_factor)
def forward(self, x):
# x = (F.leaky_relu(self.input_start(x)))
x = (F.leaky_relu(self.e1(x)))
x = (F.leaky_relu(self.e1(x)))
x = (F.leaky_relu(self.e1_dr(x)))
x = (F.leaky_relu(self.e2(x)))
x = (F.leaky_relu(self.e2_dr(x)))
x = (F.leaky_relu(self.e3(x)))
x = (F.leaky_relu(self.e3_dr(x)))
x = (F.leaky_relu(self.e4(x)))
x = (F.leaky_relu(self.e5(x)))
x = (F.leaky_relu(self.e6(x)))
x = (F.leaky_relu(self.e7(x)))
x = (self.e8(x))
x = (F.leaky_relu(self.d1(x)))
x = (F.leaky_relu(self.d2(x)))
x = (F.leaky_relu(self.d3(x)))
x = (F.leaky_relu(self.d4(x)))
x = (F.leaky_relu(self.d5(x)))
x = (F.leaky_relu(self.d6(x)))
x = (F.leaky_relu(self.d7(x)))
x = (F.leaky_relu(self.d8(x)))
return x
Whenever I run the model, I get the following error:
Given groups=1, weight of size [128, 128, 5, 1], expected input[2, 16, 248, 1] to have 128 channels, but got 16 channels instead.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
频道计数中存在不匹配。查看您的模型:第一卷积
e1
期望16
频道和输出16
,而以下卷积e2
期望128
!OUT_CHANNELS
e1
和in_channels
e2
必须相等。There is a mismatch in the channel counts. Take a look at your model: the first convolution
e1
expects16
channels and outputs16
while the following convolutione2
expects128
! Theout_channels
ofe1
and thein_channels
ofe2
must be equal.