diff options
author | Louis Verhaard <louis.verhaard@arm.com> | 2020-05-07 08:12:58 +0200 |
---|---|---|
committer | Tim Hall <tim.hall@arm.com> | 2020-06-18 17:53:52 +0100 |
commit | 3c07c97e0202c1cf01eba06c24b37a8f15ff7a7c (patch) | |
tree | 5856b7727a99b3c0baa00f5486f0c3b53e8e38e6 /ethosu/vela/tflite_reader.py | |
parent | 86d49935c3736c7aaa419abda07fa20c37c991a8 (diff) | |
download | ethos-u-vela-3c07c97e0202c1cf01eba06c24b37a8f15ff7a7c.tar.gz |
MLBEDSW-1941: Bug fix shared weights
If same weight tensor was used with different block configs,
errors would occur.
Fixed by always cloning weight tensors, using a global weight
compression cache and modifying the linear allocator to
detect multiple usage of same weight compression.
Change-Id: I91ca59176e1c59c66e0ac7a4227f2b5f0b47053f
Signed-off-by: Louis Verhaard <louis.verhaard@arm.com>
Diffstat (limited to 'ethosu/vela/tflite_reader.py')
-rw-r--r-- | ethosu/vela/tflite_reader.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/ethosu/vela/tflite_reader.py b/ethosu/vela/tflite_reader.py index 109ae0ec..5ab90f04 100644 --- a/ethosu/vela/tflite_reader.py +++ b/ethosu/vela/tflite_reader.py @@ -39,24 +39,24 @@ def decode_str(s): return s.decode("utf-8") -def reshape_tensor_add_const_op(tens, reorder): - if not tens.reshaped: - original_shape = tens.shape - tens.name = tens.name + "_reshape" - tens.shape = [original_shape[idx] for idx in reorder] - tens.bandwidth_shape = tens.shape - tens.storage_shape = tens.shape +def clone_and_reshape_tensor(src_tens, reorder): - if tens.values is not None: - tens.values = tens.values.transpose(reorder) + tens = src_tens.clone("_reshape") + tens.shape = [src_tens.shape[idx] for idx in reorder] + tens.bandwidth_shape = tens.shape + tens.storage_shape = tens.shape - if tens.quant_values is not None: - tens.quant_values = tens.quant_values.transpose(reorder) + if tens.values is not None: + tens.values = tens.values.transpose(reorder) - op = Operation("Const", tens.name) - op.outputs = [tens] - tens.ops = [op] - tens.reshaped = True + if tens.quant_values is not None: + tens.quant_values = tens.quant_values.transpose(reorder) + + op = Operation("Const", tens.name) + op.outputs = [tens] + tens.ops = [op] + + return tens class TFLiteSubgraph: @@ -137,10 +137,10 @@ class TFLiteSubgraph: activation_function_to_split_out = None if op_type.startswith("DepthwiseConv2d") or op_type.startswith("Conv2D"): - reshape_tensor_add_const_op(inputs[1], (1, 2, 3, 0)) + inputs[1] = clone_and_reshape_tensor(inputs[1], (1, 2, 3, 0)) if op_type.startswith("FullyConnected"): - reshape_tensor_add_const_op(inputs[1], (1, 0)) + inputs[1] = clone_and_reshape_tensor(inputs[1], (1, 0)) if opt_serializer is not None: op.attrs = opt_serializer.deserialize(op_data.BuiltinOptions(), op_data.CustomOptionsAsNumpy()) |