Hi everyone,
I was doing some simple work until I came across this error.
File "C:\Users\bala006\Miniconda3.8\lib\site-packages\torch\nn\functional.py", line 1753, in linear
return torch._C._nn.linear(input, weight, bias)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (50176x3 and 256x300)
The relevant code is a followed
class NN (nn.Module):
def __init__(self, input_size, output_size):
super(NN, self).__init__()
self.flatten = nn.Flatten()
self.LinearStack = nn.Sequential(
nn.Linear(input_size, 300),
nn.ReLU(),
nn.Linear(300, 300),
nn.ReLU(),
nn.Linear(300, 256),
nn.ReLU(),
nn.Linear(256, 256),
nn.ReLU(),
nn.Linear(256, 150),
nn.ReLU(),
nn.Linear(150,100),
nn.ReLU(),
nn.Linear(100,75),
nn.ReLU(),
nn.Linear(75, output_size),
nn.ReLU()
)
def forward (self,out):
logits = self.LinearStack(out)
return logits
model = NN(256,2)
y_label, imagepre = dataset.__getitem__(1)
print (y_label)
print (imagepre)
loss_func = nn.CrossEntropyLoss()
optimiser = optim.SGD(model.parameters(), lr = 0.001)
epochs = 2
def run (loss_fn, dataloader, model):
size = dataset.__len__()
for y_label in enumerate(dataloader):
image = torch.from_numpy(imagepre)
Pred = model(image)
print (Pred)
# Loss
loss = loss_fn(pred, y_label)
# Backprop
optimiser.zero_grad()
loss.backward()
optimiser.step()
print (loss)
for t in range(epochs):
print ("Epoch #######################")
run(loss_func, dataloader, model)
print ("Done")
I got some weird errors before this that I ironed out with some compromise but am really stuck on this. Thanks for any help!