I am trying to run my cnn module here.
class cnn(nn.Module):
def init(self, classes):
super(cnn, self).init()
self.conv1 = nn.Conv2d(1, 6, 3, padding = 1)# input = [N,1,28,28] output = [N,6,28,28]
self.conv2 = nn.Conv2d(6, 16, 3, padding = 1)# input = [N,6,14,14] output = [N,16,14,14]
self.conv3 = nn.Conv2d(16, 32, 3,padding = 1)# input = [N,16,7,7] output = [N,32,7,7]
self.fc1 = nn.Linear(32*7*7, 1204)
self.fc2 = nn.Linear(1204,120)
self.fc3 = nn.Linear(120,classes)
def forward(self, x):
y = F.max_pool2d(F.relu(self.conv1(x)), kernel_size = 2, stride = 2)# input = [N,6,28,28] output = [N,6,14,14]
y = F.max_pool2d(F.relu(self.conv2(y)), kernel_size = 2, stride = 2)# input = [N,16,14,14] output = [N,16,7,7]
y = F.relu(self.conv3(y))# input = [N,16,7,7] output = [N,32,7,7]
y = y.view(y.size()[0],-1)
y = F.relu(self.fc1(y))
y = F.relu(self.fc2(y))
y = F.relu(self.fc3(y))
then i ran this code to check if my module works
x = Variable(torch.randn(1,1,28,28))
o = model(x)
print o
i am getting this error
/usr/local/lib/python2.7/dist-packages/torch/nn/modules/module.pyc in call(self, *input, **kwargs)
213 var = result
214 while not isinstance(var, Variable):
–> 215 var = var[0]
216 creator = var.creator
217 if creator is not None and len(self._backward_hooks) > 0:
TypeError: ‘NoneType’ object has no attribute ‘getitem’
Can anybody solve this?