label=torch.Tensor(labels)
n_epochs = 10
valid_loss_min = np.Inf # track change in validation loss
model.train()
for epoch in range(1, n_epochs+1):
train_loss = 0.0
for i in range((images.shape)[0]):
      data=images[i]
      target=label[i]
      target = target.unsqueeze(0)
        # clear the gradients of all optimized variables
      optimizer.zero_grad()
        # forward pass: compute predicted outputs by passing inputs to the model
      output = model(data)
        # calculate the batch loss
      loss = criterion(output, target)
        # backward pass: compute gradient of the loss with respect to model parameters
      loss.backward()
        # perform a single optimization step (parameter update)
      optimizer.step()
        # update training loss
      train_loss += loss.item()*data.size(0)
      print("ALL ABOUT LOSS--------",train_loss,"----------/n")

RuntimeError                              Traceback (most recent call last)
 in ()
15           output = model(data)
16             # calculate the batch loss
—> 17           loss = criterion(output, target)
18             # backward pass: compute gradient of the loss with respect to model parameters
19           loss.backward()
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py in call(self, *input, **kwargs)
487             result = self._slow_forward(*input, **kwargs)
488         else:
–> 489             result = self.forward(*input, **kwargs)
490         for hook in self._forward_hooks.values():
491             hook_result = hook(self, input, result)
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/loss.py in forward(self, input, target)
902     def forward(self, input, target):
903         return F.cross_entropy(input, target, weight=self.weight,
–> 904                                ignore_index=self.ignore_index, reduction=self.reduction)
905
906
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in cross_entropy(input, target, weight, size_average, ignore_index, reduce, reduction)
1968     if size_average is not None or reduce is not None:
1969         reduction = _Reduction.legacy_get_string(size_average, reduce)
-> 1970     return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction)
1971
1972
/usr/local/lib/python3.6/dist-packages/torch/nn/functional.py in nll_loss(input, target, weight, size_average, ignore_index, reduce, reduction)
1788                          .format(input.size(0), target.size(0)))
1789     if dim == 2:
-> 1790         ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
1791     elif dim == 4:
1792         ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Expected object of scalar type Long but got scalar type Double for argument #2 ‘target’

AND WHEN i convert it to type long using label.long() so it giving error–
TypeError                                 Traceback (most recent call last)
 in ()
9
10           data=images[i]
—> 11           target=label[i]
12           target = target.unsqueeze(0)
13             # clear the gradients of all optimized variables
TypeError: ‘builtin_function_or_method’ object is not subscriptable