我正在尝试运行此代码,但遇到了以下错误:RuntimeError:mat1和mat2形状不能相乘(16x196608和6


class DenoiseAutoencoder(nn.Module):
def __init__(self):
super(DenoiseAutoencoder, self).__init__()
# encoder
self.enc1 = nn.Linear(in_features=256 * 256, out_features=16384)
self.enc2 = nn.Linear(in_features=16384, out_features=4096)
self.enc3 = nn.Linear(in_features=4096, out_features=1024)
self.enc4 = nn.Linear(in_features=1024, out_features=256)
self.enc5 = nn.Linear(in_features=256, out_features=128)
self.enc6 = nn.Linear(in_features=128, out_features=64)
self.enc7 = nn.Linear(in_features=64, out_features=32)
self.enc8 = nn.Linear(in_features=32, out_features=16)
# decoder 
self.dec1 = nn.Linear(in_features=16, out_features=32)
self.dec2 = nn.Linear(in_features=32, out_features=64)
self.dec3 = nn.Linear(in_features=64, out_features=128)
self.dec4 = nn.Linear(in_features=128, out_features=256)
self.dec5 = nn.Linear(in_features=256, out_features=1024)
self.dec6 = nn.Linear(in_features=1024, out_features=4096)
self.dec7 = nn.Linear(in_features=4096, out_features=16384)
self.dec8 = nn.Linear(in_features=16834, out_features=256 * 256)
def forward(self, x):

x = F.relu(self.enc1(x))
x = F.relu(self.enc2(x))
x = F.relu(self.enc3(x))
x = F.relu(self.enc4(x))
x = F.relu(self.enc5(x))
x = F.relu(self.enc6(x))
x = F.relu(self.enc7(x))
x = F.relu(self.enc8(x))
x = F.relu(self.dec1(x))
x = F.relu(self.dec2(x))
x = F.relu(self.dec3(x))
x = F.relu(self.dec4(x))
x = F.relu(self.dec5(x))
x = F.relu(self.dec6(x))
x = F.relu(self.dec7(x))
x = F.relu(self.dec8(x))
return x
net = DenoiseAutoencoder()
print(net)

针对这个错误,我尝试在堆栈溢出中实现所有解决方案,但都不起作用。

运行时错误:mat1和mat2形状不能相乘(16x196608和65536x16384(

我不知道问题出在哪里。

在您的代码中,self.dec7中的输出功能(16384(与self.dec8中的输入功能(16834(不同。我想这应该行得通。

相关内容

  • 没有找到相关文章

最新更新