I have the following code,
import torch.nn as nn
class MaqamCNN(nn.Module):
def __init__(self):
super(MaqamCNN, self).__init__()
self.conv1 = nn.Conv2d(1, 16, kernel_size=(5, 1), stride=(1, 1), padding=(2, 0))
self.bn1 = nn.BatchNorm2d(16)
self.relu1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(kernel_size=(4, 1), stride=(4, 1))
self.conv2 = nn.Conv2d(16, 32, kernel_size=(5, 1), stride=(1, 1), padding=(2, 0))
self.bn2 = nn.BatchNorm2d(32)
self.relu2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(kernel_size=(4, 1), stride=(4, 1))
self.fc1 = nn.Linear(32 * 5 * 20, 128)
self.bn3 = nn.BatchNorm1d(128)
self.relu3 = nn.ReLU()
self.dropout = nn.Dropout(p=0.5)
self.fc2 = nn.Linear(128, 8)
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu1(x)
x = self.pool1(x)
x = self.conv2(x)
x = self.bn2(x)
x = self.relu2(x)
x = self.pool2(x)
print(x.shape)
x = x.view(-1, 16*90000*1)
x = self.fc1(x)
x = self.bn3(x)
x = self.relu3(x)
x = self.dropout(x)
x = self.fc2(x)
return x
And the error I get is:
C:\Users\omari\anaconda3\lib\site-packages\torch\nn\functional.py:718: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject
to change. Please do not use them for anything important until they are released as stable. (Triggered internally at ..\c10/core/TensorImpl.h:1156.)
return torch.max_pool2d(input, kernel_size, stride, padding, dilation, ceil_mode)
torch.Size([16, 32, 90000, 1])
Traceback (most recent call last):
File "C:\Users\omari\Documents\GitHub\Classifying_Maqams\model3\train.py", line 29, in <module>
outputs = model(inputs)
File "C:\Users\omari\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\omari\Documents\GitHub\Classifying_Maqams\model3\model.py", line 31, in forward
x = self.fc1(x)
File "C:\Users\omari\anaconda3\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Users\omari\anaconda3\lib\site-packages\torch\nn\modules\linear.py", line 96, in forward
return F.linear(input, self.weight, self.bias)
File "C:\Users\omari\anaconda3\lib\site-packages\torch\nn\functional.py", line 1847, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (32x1440000 and 3200x128)
previously I edited the x.view size to be according to the shape of x, but now I don’t know how to solve this error<<
Any help?