Expected object of scalar type Long but got scalar type Byte for argument #2 'target'
I am running a nn on colab and came across this error which was not there when i ran the same code on my local system. I have tried with reduced batch size too but the error still persists. 

Loading dataset
Start training
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
&lt;ipython-input-4-37432f9d142a&gt; in &lt;module&gt;()
     70           start_epoch=start_epoch, log=log_interval,
     71           checkpoint_path=os.path.join(dataset_dir, "cnn_block_frame_flow"),
---&gt; 72           validate=True, resume=False, flow=True, use_cuda=cuda)
     73 
     74     #model = models.model()

/content/KTH-Action-Recognition/main/train_helper.py in train(model, num_epochs, train_set, dev_set, lr, batch_size, start_epoch, log, checkpoint_path, validate, resume, flow, use_cuda)
    107             outputs = get_outputs(model, samples["instance"], flow=flow,
    108                                   use_cuda=use_cuda)
--&gt; 109             loss = criterion(outputs, labels)
    110             loss.backward()
    111             optimizer.step()

/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:
--&gt; 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,
--&gt; 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)
-&gt; 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:
-&gt; 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 Byte for argument #2 'target'


Can someone tell me what is causing this error? thank you

The title of your question is telling what is causing this error. The target should have type torch.LongTensor, but it is instead torch.ByteTensor. Before calling nll_loss do:

target = target.type(torch.LongTensor)

