问题描述

在使用nn.CrossEntropyLoss时出现报错:

loss_id = self.IDLoss(id_preds, id_targets)
Traceback (most recent call last):
  File "/home/hgx/pycharm-2020.1.3/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/home/hgx/anaconda3/envs/bytetrack/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1102, in _call_impl
    return forward_call(*input, **kwargs)
  File "/home/hgx/anaconda3/envs/bytetrack/lib/python3.7/site-packages/torch/nn/modules/loss.py", line 1152, in forward
    label_smoothing=self.label_smoothing)
  File "/home/hgx/anaconda3/envs/bytetrack/lib/python3.7/site-packages/torch/nn/functional.py", line 2846, in cross_entropy
    return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(reduction), ignore_index, label_smoothing)
RuntimeError: "nll_loss_forward_reduce_cuda_kernel_2d_index" not implemented for 'Int'

问题分析

数据类型导致的错误

解决方案

进行数据类型转换

id_targets = id_targets.to(torch.int64)     # TODO: ReID. [matched_anchor], float16 to int
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐