Well, I’m trying to make a simple net but can’t deal this error. Any help will be appreciated
for i, (x, l) in enumerate(zip(dataloader(X), labels)):
# wrap inputs in Variable
inputs, labels = Variable(torch.from_numpy(x)), Variable(torch.from_numpy(np.array(l)))
inputs = inputs.float()
labels = labels.float()
# zero the parameter gradients
optimizer.zero_grad()
# forward + backward + optimize
outputs = net(inputs)
The error happening at the outputs = net(inputs) line.
RuntimeError: invalid argument 2: dimension 0 out of range of 0D tensor at /Users/soumith/minicondabuild3/conda-bld/pytorch_1512381214802/work/torch/lib/TH/generic/THTensor.c:24
My dataloader returns numpy arrays with shape = (4, 1, 80, 80)
Model is declared as
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.conv1 = nn.Conv2d(1, 6, 5)
self.pool = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.fc2 = nn.Linear(120, 84)
self.fc3 = nn.Linear(84, 10)
def forward(self, x):
x = self.conv1(x)
x = F.relu(x)
x = self.pool(x)
x = self.pool(F.relu(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = self.fc3(x)
return x