Hello,
I get this error when i run the model below on MNIST dataset. I use this script to get the data loaders:
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(1, 20, 5, 1)
self.conv2 = nn.Conv2d(20, 50, 5, 1)
self.fc1 = nn.Linear(4 * 4 * 50, 500)
self.fc2 = nn.Linear(500, 10)
def forward(self, x):
x = f.relu(self.conv1(x))
x = f.max_pool2d(x, 2, 2)
x = f.relu(self.conv2(x))
x = f.max_pool2d(x, 2, 2)
print("before view",x.shape)
x = x.view(-1, 4 * 4 * 50)
print("after view", x.shape)
x = f.relu(self.fc1(x))
x = self.fc2(x)
return f.log_softmax(x, dim=1)
I suspect that this the reshape in this function might be the cause. Am i right? any idea please?
def get_mnist():
'''Return MNIST train/test data and labels as numpy arrays'''
data_train = torchvision.datasets.MNIST(root=os.path.join(DATA_PATH, "MNIST"), train=True, download=True)
data_test = torchvision.datasets.MNIST(root=os.path.join(DATA_PATH, "MNIST"), train=False, download=True)
x_train, y_train = data_train.train_data.numpy().reshape(-1,1,28,28)/255, np.array(data_train.train_labels)
x_test, y_test = data_test.test_data.numpy().reshape(-1,1,28,28)/255, np.array(data_test.test_labels)
return x_train, y_train, x_test, y_test
I checked other conversations about the same issue and i tried the proposed solutions yet the same error.