Hi,
I’m new to pytorch,
trying to use a simple cnn model on my images.
However, seems like I’m not passing the correct input dimensions.
How do I correct that? and to what shape? (code example will be great)
Thanks!

Code below:
import torch.nn as nn
import torch.nn.functional as F
class Net(nn.Module):
def __init__(self):

    super(Net,self).__init__()

    self.layer1 = nn.Sequential(

        nn.Conv2d(1, 32, kernel_size=5, stride=1, padding=2),

        nn.ReLU(),

        nn.MaxPool2d(kernel_size=2, stride=2))

    self.layer2 = nn.Sequential(

        nn.Conv2d(32, 64, kernel_size=5, stride=1, padding=2),

        nn.ReLU(),

        nn.MaxPool2d(kernel_size=2, stride=2))

    self.drop_out = nn.Dropout()

    self.fc1 = nn.Linear(69*69, 100)

    self.fc2 = nn.Linear(100, 10)

def forward(self,x):

 out = self.layer1(x)

 out = self.layer2(out)

 out = out.reshape(out.size(0), -1)

 out = self.drop_out(out)

 out = self.fc1(out)

 out = self.fc2(out)

 return out


tranining_tensor = torch.stack([training_ds[i][0] for i in range(len(training_ds)) ])
training_labels = training_ds.labels.data.numpy()
validation_tensor = torch.stack([validation_ds[i][0] for i in range(len(validation_ds)) ])
validation_labels = validation_ds.labels.data.numpy()

def dataset_accuracy(tensor_dataset,targets,net,loss_func):
net.eval()

output = net(tensor_dataset)

loss = loss_func(output,torch.LongTensor(targets))

output = output.cpu().data.numpy()

prediction = np.argmax(output,axis=1)

n_correct = len(np.where(targets==prediction)[0])

n_total = len(targets)

return n_correct/n_total, loss.item()


This is where I get the error:
dataset_accuracy(tranining_tensor,training_labels, net, loss_func)