MLBEDSW-2868 Refactor separation of scale + bias tensors
Changed so that there is an option to set if Tensor clone should be
seen as unique or not.
Signed-off-by: Patrik Gustavsson <patrik.gustavsson@arm.com>
Change-Id: Ie51c1a5e84b535380d498b105aa18ccba1c8b27c
diff --git a/ethosu/vela/tflite_reader.py b/ethosu/vela/tflite_reader.py
index 82feddd..24f9f87 100644
--- a/ethosu/vela/tflite_reader.py
+++ b/ethosu/vela/tflite_reader.py
@@ -41,9 +41,8 @@
return s.decode("utf-8")
-def clone_and_reshape_tensor(src_tens, reorder):
-
- tens = src_tens.clone("_reshape")
+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]
tens.bandwidth_shape = tens.shape
tens.storage_shape = tens.shape
@@ -153,17 +152,16 @@
if op.type.is_depthwise_conv2d_op() or op.type.is_conv2d_op() or op.type == Op.FullyConnected:
if inputs[1].values is not None:
if op.type == Op.FullyConnected:
- inputs[1] = clone_and_reshape_tensor(inputs[1], (1, 0))
+ inputs[1] = clone_and_reshape_tensor(inputs[1], (1, 0), False)
else:
- inputs[1] = clone_and_reshape_tensor(inputs[1], (1, 2, 3, 0))
+ inputs[1] = clone_and_reshape_tensor(inputs[1], (1, 2, 3, 0), False)
if op.type.needs_bias() and len(inputs) <= op_type.info.indices.biases[0]:
# No Bias tensor
inputs.append(None)
if inputs[-1] and inputs[-1].values is not None:
- inputs[-1] = clone_and_reshape_tensor(inputs[-1], (0,))
# Since bias tensor is used for both bias and scale,
- # set different equivalence_id for all bias tensors
- inputs[-1].set_random_equivalence_id()
+ # a clone with a unique equivalence_id is needed
+ inputs[-1] = clone_and_reshape_tensor(inputs[-1], (0,), True)
if opt_serializer is not None:
op.attrs = opt_serializer.deserialize(op_data)