MindSpore报错解决TypeError: object is not callable
        【摘要】 MindSpore报错笔记
    
    
    
    MindSpore
- MindScience是基于昇思MindSpore融合架构打造的科学计算行业套件,包含了业界领先的数据集、基础模型、预置高精度模型和前后处理工具,加速了科学行业应用开发。
 
1 环境安装
前置安装
- 确认是安装Windows 10/11是x86架构64位操作系统。
 - 安装Minicanda或者Anaconda。
 - 安装Python 环境 3.7.5 或3.9.0(如何使用Conda安装可以直接创建命令即可,如果手动安装则需要配置Python环境变量)
 
conda env list
conda activate py39_ms18
# 指定版本
pip install --upgrade mindspore==1.8.1
 
 2 报错信息
2.1 问题描述
- 问题一和问题二均由于单词大小写拼写错误,与API中存在差异导致
 
2.1 问题描述
报错一:
- TypeError: nodule() takes at nost 2 arguments (3 given)
 
报错二:
- TypeError: ‘mindspore._c_expression.typing.TensorType’ object is not callable
 
2.2 脚本代码
代码一:
import mindspore.nn as nn
import mindspore.ops as ops
class MyCell(nn.cell):
  def _init__(self, forward_net):
    super(MyCelL, self)._init__(auto_prefix=False)
    sef.relu = ops.ReLU()
    self.net = forward_net
 
 代码二:
import mindspore
t1 = mindspore.tensor([[1,2,3],[3,4,5]])
# = { 'dΘ':[1,2,3],'d1':mindspore.Tensor(a),'c....}
print(t1)
 
 3 根因分析
代码一问题:
- 拼写错误:
nn.cell应为nn.Cell,MyCelL应为MyCell,sef应为self 
nn.cell
super(MyCelL, self)._init__(auto_prefix=False)
sef.relu = ops.ReLU()
 
 代码二问题:
- 拼写错误:
tensor应为Tensor 
t1 = mindspore.tensor([[1,2,3],[3,4,5]])
 
 4 解决方案
- 代码一:修改代码中的错误拼写两处,
nn.cell为nn.Cell,MyCelL为MyCell,sef为self 
import mindspore.nn as nn
import mindspore.ops as ops
class MyCell(nn.Cell):
  def _init__(self, forward_net):
    super(MyCell, self)._init__(auto_prefix=False)
    self.relu = ops.ReLU()
    self.net = forward_net
 
 - 代码一:修改代码中的错误拼写, 
tensor为Tensor 
import mindspore
t1 = mindspore.Tensor([[1,2,3],[3,4,5]])
# = { 'dΘ':[1,2,3],'d1':mindspore.Tensor(a),'c....}
print(t1)
 
            【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
                cloudbbs@huaweicloud.com
                
            
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)