diff options
author | Johan Alfvén <johan.alfven@arm.com> | 2022-10-26 12:52:17 +0200 |
---|---|---|
committer | Johan Alfvén <johan.alfven@arm.com> | 2022-10-27 14:32:22 +0200 |
commit | 53605be9fb83fb0a0fa873a0f4d7435654d3df6b (patch) | |
tree | 165a3ebdcfd81b088b50024efa7d970bfec27b5f /ethosu | |
parent | 993ea53f9aabb5746aa96512286bae2dc06ded1b (diff) | |
download | ethos-u-vela-53605be9fb83fb0a0fa873a0f4d7435654d3df6b.tar.gz |
MLBEDSW-7060: Bias tensor should be in 1D shape
Always make sure the bias is a 1D tensor.
Signed-off-by: Johan Alfven <johan.alfven@arm.com>
Change-Id: Ic0cb85d4fb9d2e07b4d1b7ac6059bffa432e28a3
Diffstat (limited to 'ethosu')
-rw-r--r-- | ethosu/vela/reader_util.py | 14 | ||||
-rw-r--r-- | ethosu/vela/tflite_reader.py | 4 |
2 files changed, 14 insertions, 4 deletions
diff --git a/ethosu/vela/reader_util.py b/ethosu/vela/reader_util.py index 476b70aa..b5a058e3 100644 --- a/ethosu/vela/reader_util.py +++ b/ethosu/vela/reader_util.py @@ -15,6 +15,8 @@ # limitations under the License. # Description: # Utlity function for reading .tosa and .tflite files +import numpy as np + from .operation import Op from .operation import Operation @@ -27,12 +29,20 @@ def decode_str(s): def clone_and_reshape_tensor(src_tens, reorder, set_unique): tens = src_tens.clone("_reshape", set_unique) - tens.shape = [src_tens.shape[idx] for idx in reorder] + if reorder is None: + # 1D shape requested + tens.shape = [np.prod(src_tens.shape)] + else: + tens.shape = [src_tens.shape[idx] for idx in reorder] tens.bandwidth_shape = tens.shape tens.storage_shape = tens.shape if tens.values is not None: - tens.values = tens.values.transpose(reorder) + if reorder is None: + # 1D shape requested + tens.values = tens.values.reshape(tens.shape) + else: + tens.values = tens.values.transpose(reorder) op = Operation(Op.Const, tens.name) op.set_output_tensor(tens) diff --git a/ethosu/vela/tflite_reader.py b/ethosu/vela/tflite_reader.py index fa90ad9e..9fe9ff58 100644 --- a/ethosu/vela/tflite_reader.py +++ b/ethosu/vela/tflite_reader.py @@ -141,8 +141,8 @@ class TFLiteSubgraph: inputs.append(None) if inputs[-1] and inputs[-1].values is not None: # Since bias tensor is used for both bias and scale, - # a clone with a unique equivalence_id is needed - inputs[-1] = clone_and_reshape_tensor(inputs[-1], (0,), True) + # a clone with a unique equivalence_id is needed. + inputs[-1] = clone_and_reshape_tensor(inputs[-1], None, True) if opt_serializer is not None: op.attrs = opt_serializer.deserialize(op_data) |