[debug] RuntimeError: “nll_loss_forward_reduce_cuda_kernel_2d_index“ not implemented for ‘Int‘

本文描述了在使用PyTorch的nn.CrossEntropyLoss时遇到的一个运行时错误,并提供了详细的错误堆栈跟踪。错误源于数据类型不匹配,文章进一步提供了解决方案——确保目标张量的数据类型为torch.int64。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

在使用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
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值