1 系统环境
硬件环境(Ascend/GPU/CPU): Ascend/GPU/CPU
MindSpore版本: MindSpore=2.6.0
执行模式(PyNative/ Graph): 不限
Python版本: Python=3.8
操作系统平台: linux
2 报错信息
2.1 问题描述
在用MindSpore训练一个简单的全连接网络时遇到如下报错:
TypeError: For 'MatMul', the input data must be float16, float32, uint16 but got int32
- 为什么会出现这个类型错误?
- 应该如何正确设置Tensor的数据类型?
2.2 脚本信息
import mindspore.nn as nn
from mindspore import Tensor
# 网络定义
class SimpleNet(nn.Cell):
def __init__(self):
super().__init__()
self.fc = nn.Dense(10, 5) # 输入10维,输出5维
def construct(self, x):
return self.fc(x)
# 数据准备
x = Tensor([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) # 输入数据
net = SimpleNet()
output = net(x) # 这里报错
3 根因分析
此处由用户填写
4 解决方案
此处由用户填写
包含文字方案和最终脚本代码 请将正确的脚本打包并上传附件