Skip to content

Target is not converted to 'Long' error #302

@mrT23

Description

@mrT23

i am trying to run simple PETS dataset training.

when i use the following simple learner with label smooth:
learn = cnn_learner(dbunch, resnet34, metrics=[accuracy, top_k_accuracy], loss_func=LabelSmoothingCrossEntropy()) learn.fit_one_cycle(4)

i get the following error immediately when the training starts:

File "...\fastai2\layers.py", line 254, in forward
return loss*self.eps/c + (1-self.eps) * F.nll_loss(log_preds, target, reduction=self.reduction)
File "D:\Anaconda3\envs\torch_conda\lib\site-packages\torch\nn\functional.py", line 1824, in nll_loss
ret = torch._C._nn.nll_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index)
RuntimeError: Expected object of scalar type Long but got scalar type Int for argument #2 'target'

if i use CrossEntropyLossFlat loss instead, i get an error at the validation phase:

File "...\fastai2\metrics.py", line 76, in accuracy
return (pred == targ).float().mean()
File "...\fastai2\torch_core.py", line 176, in _f
res = getattr(super(TensorBase, self), fn)(*args, **kwargs)
RuntimeError: Expected object of scalar type Int but got scalar type Long for argument #2 'other'

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions