计算loss时报类型不匹配:the input argument[indices] must be a type of {Tensor[Int32], Tensor[Int64]}, but got Tensor[Float64]
收藏回复举报
计算loss时报类型不匹配:the input argument[indices] must be a type of {Tensor[Int32], Tensor[Int64]}, but got Tensor[Float64]
发表于2023-05-22 19:11:41
0 查看

1 系统环境

硬件环境(Ascend/GPU/CPU): CPU

MindSpore版本: 2.0.0-nightly

执行模式(PyNative/ Graph): Graph

Python版本: Python=3.7.5

操作系统平台: Linux 18.04

2 报错信息

2.1  问题描述

在计算loss时会抛出数据精度类型不匹配的问题:期望的输入精度是int32,得到的却是float64

2.2  报错信息

TypeError: For primitive[OneHot], the input argument[indices] must be a type of {Tensor[Int32], Tensor[Int64], Tensor[UInt8]}, but got Tensor[Float64].
----------------------------------------------------
- The Traceback of Net Construct Code:
----------------------------------------------------
The function call stack (See file '/home/jenkins/issue/rank_0/om/analyze_fail.dat' for more details. Get instructions about `analyze_fail.dat` at https://www.mindspore.cn/search?inputValue=analyze_fail.dat):
# 0 In file /home/miniconda3/envs/ci/lib/python3.7/site-packages/mindspore/ops/composite/base.py:574
                        return grad_(fn, weights)(*args)
                               ^
# 1 In file issue.py:39
    label = onehot(ms.Tensor(label, dtype=mindspore.int32), ops.shape(logit)[1], on_value, off_value)
            ^
----------------------------------------------------
- C++ Call Stack: (For framework developers
----------------------------------------------------
mindspore/core/utils/check_convert_utils.cc:831 CheckTensorSubClass

2.3  脚本代码(代码格式,可上传附件)

请下载附件中的脚本文件,执行命令python issue.py 运行网络

3 根因分析

******此处由用户补充详细的定位过程******

4 解决方案

******此处由用户填写******

包含文字方案和最终脚本代码

支持上传附件

本帖最后由 匿名用户2023/06/29 10:49:16 编辑

我要发帖子