diff options
Diffstat (limited to 'python/pyarmnn/src/pyarmnn/_tensor')
-rw-r--r-- | python/pyarmnn/src/pyarmnn/_tensor/const_tensor.py | 19 | ||||
-rw-r--r-- | python/pyarmnn/src/pyarmnn/_tensor/workload_tensors.py | 1 |
2 files changed, 14 insertions, 6 deletions
diff --git a/python/pyarmnn/src/pyarmnn/_tensor/const_tensor.py b/python/pyarmnn/src/pyarmnn/_tensor/const_tensor.py index 94995bdd8c..ab4305c18e 100644 --- a/python/pyarmnn/src/pyarmnn/_tensor/const_tensor.py +++ b/python/pyarmnn/src/pyarmnn/_tensor/const_tensor.py @@ -59,24 +59,31 @@ class ConstTensor(AnnConstTensor): Raises: TypeError: Unsupported input data type. - ValueError: Unsupported tensor data type and incorrect input data size. + ValueError: Unsupported tensor data type, incorrect input data size and creation of ConstTensor from non-constant TensorInfo. """ self.__memory_area = None # TensorInfo as first argument and numpy array as second if len(args) > 1 and isinstance(args[0], TensorInfo): - if isinstance(args[1], np.ndarray): + if not isinstance(args[1], np.ndarray): + raise TypeError('Data must be provided as a numpy array.') + # if TensorInfo IsConstant is false + elif not args[0].IsConstant(): + raise ValueError('TensorInfo when initializing ConstTensor must be set to constant.') + else: self.__create_memory_area(args[0].GetDataType(), args[0].GetNumBytes(), args[0].GetNumElements(), args[1]) super().__init__(args[0], self.__memory_area.data) - else: - raise TypeError('Data must be provided as a numpy array.') # copy constructor - reference to memory area is passed from copied const # tensor and armnn's copy constructor is called elif len(args) > 0 and isinstance(args[0], (ConstTensor, Tensor)): - self.__memory_area = args[0].get_memory_area() - super().__init__(args[0]) + # if TensorInfo IsConstant is false + if not args[0].GetInfo().IsConstant(): + raise ValueError('TensorInfo of Tensor when initializing ConstTensor must be set to constant.') + else: + self.__memory_area = args[0].get_memory_area() + super().__init__(args[0]) # empty tensor elif len(args) == 0: diff --git a/python/pyarmnn/src/pyarmnn/_tensor/workload_tensors.py b/python/pyarmnn/src/pyarmnn/_tensor/workload_tensors.py index 22b876896d..532db56cc3 100644 --- a/python/pyarmnn/src/pyarmnn/_tensor/workload_tensors.py +++ b/python/pyarmnn/src/pyarmnn/_tensor/workload_tensors.py @@ -54,6 +54,7 @@ def make_input_tensors(inputs_binding_info: List[Tuple], for in_bind_info, in_data in zip(inputs_binding_info, input_data): in_tensor_id = in_bind_info[0] in_tensor_info = in_bind_info[1] + in_tensor_info.SetConstant() input_tensors.append((in_tensor_id, ConstTensor(in_tensor_info, in_data))) return input_tensors |