Environment:
Hardware Environment(Ascend/GPU/CPU): All
Software Environment:
MindSpore version (source or binary): 1.6.0 & Earlier versions
Python version (e.g., Python 3.7.5): 3.7.6
OS platform and distribution (e.g., Linux Ubuntu 16.04): Ubuntu
GCC/Compiler version (if compiled from source): gcc 9.4.0
python code examples
from mindspore import nn
class Net(nn.Cell):
def __init__(self):
super(Net, self).__init__()
def construct(self, x):
return self.y + x
net = Net()
output = net(1)
Error reporting information
Traceback (most recent call last):
File "test_self.py", line 11, in <module>
output = net(1)
File "mindspore\nn\cell.py", line 477, in __call__
out = self.compile_and_run(*args)
File "mindspore\nn\cell.py", line 803, in compile_and_run
self.compile(*inputs)
File "mindspore\nn\cell.py", line 790, in compile
_cell_graph_executor.compile(self, *inputs, phase=self.phase, auto_parallel_mode=self._auto_parallel_mode)
File "mindspore\common\api.py", line 632, in compile
result = self._graph_executor.compile(obj, args_list, phase, self._use_vm_mode())
RuntimeError: mindspore\ccsrc\frontend\operator\composite\multitype_funcgraph.cc:162 GenerateFromTypes] The 'add' operation does not support the type [kMetaTypeNone, Int64].
The supported types of overload function `add` is: [Tuple, Tuple], [RowTensor, Tensor], [Tensor, Tensor], [List, List], [Tensor, List], [List, Tensor], [String, String], [Tuple, Tensor], [kMetaTypeNone, kMetaTypeNone], [Number, Number], [Number, Tensor], [Tensor, Number], [Tensor, Tuple].
The function call stack (See file 'rank_0/om/analyze_fail.dat' for more details):
# 0 In file test_self.py(8)
return self.y + x
Solution:
Since the execution error is caused by using an undefined variable, the solution is to define the variable in the network’s initialization function __init__(self):. Note that only variables defined as members of self can be used in the construct(self, x) method.
from mindspore import nn
class Net(nn.Cell):
def __init__(self):
super(Net, self).__init__()
self.y = 1.0
def construct(self, x):
return self.y + x
net = Net()
output = net(1)
If you write self.y = 1.0 instead of y = 1.0, you will also get an error because the variable is undefined.
Read More:
- [ONNXRuntimeError] : 10 : INVALID_Graph loading model error
- How to Solve Turtle_tf Error in ROS
- [Solved] theano-GPU Error: pygpu.gpuarray.GpuArrayException: b‘cuMemAlloc: CUDA_ERROR_OUT_OF_MEMORY: out of memory
- [How to Solve] ImportError: No module named typing
- Python Openyxl Error: AttributeError: ‘int‘ object has no attribute ‘upper‘ [How to Solve]
- OSError libespeak.so.1 error: no such file or directory [How to Solve]
- Tensorflow: Common Usage of tf.get_variable_scope()
- python: File Processing and Input and Output
- [Solved] Pygame.error: mixer not initialized & pygame.error: WASAPI can‘t find requested audio endpoint: Could not Find the Element.
- [Solved] Mindspot error: Error: runtimeerror:_kernel.cc:88 CheckParam] AddN output shape must be equal to input…
- [Solved] PyQt: RuntimeError: wrapped C/C++ object has been deleted & has no attribute of flush in python
- [Solved] ERROR: Could not build wheels for cryptography which use PEP 517 and cannot be installed directly
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- About the solution of ERROR: Failed building wheel for dlib
- Gunicorn Flask Error: [ERROR] Socket error processing request
- RuntimeError: Address already in use [How to Solve]
- pandas.DataFrame() Initializes NULL Error: DataFrame [How to Solve]
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]
- [Solved] AttributeError: module ‘logging‘ has no attribute ‘Handler‘
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768