aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Hall <tim.hall@arm.com>2023-04-06 21:01:58 +0100
committerTim Hall <tim.hall@arm.com>2023-04-21 18:23:03 +0100
commit2f18e172a3d727d7c610855e93d8aeccd2fca9b1 (patch)
tree3e5bf457df0334e9d398bb8b8be2a6903744e39d
parent2180a172c31f27899d3bf77bfecccc1768667737 (diff)
downloadethos-u-vela-2f18e172a3d727d7c610855e93d8aeccd2fca9b1.tar.gz
MLBEDSW-7373: Vela sometimes write empty buffers in incorrect format
- Fixed an issue whereby a zero length buffer was written out instead of an empty buffer - Added a warning message to highlight when this type of semantically incorrect empty buffer is read from an input network Change-Id: Iac3bc71a2dbfda53737bbeb6e7f895552f0f13d0 Signed-off-by: Tim Hall <tim.hall@arm.com>
-rw-r--r--ethosu/vela/tflite_reader.py20
-rw-r--r--ethosu/vela/tflite_writer.py5
2 files changed, 18 insertions, 7 deletions
diff --git a/ethosu/vela/tflite_reader.py b/ethosu/vela/tflite_reader.py
index 2f3192b7..18b61e75 100644
--- a/ethosu/vela/tflite_reader.py
+++ b/ethosu/vela/tflite_reader.py
@@ -255,9 +255,23 @@ class TFLiteGraph:
parsing_step = "parsing buffers length"
self.buffers = []
- for idx in range(model.BuffersLength()):
- parsing_step = f"parsing buffer {idx}"
- self.buffers.append(self.parse_buffer(model.Buffers(idx)))
+ if not model.BuffersIsNone():
+ for idx in range(model.BuffersLength()):
+ parsing_step = f"parsing buffer {idx}"
+ buffer = model.Buffers(idx)
+ buffer_data = self.parse_buffer(buffer)
+ # buffers can be either; empty, or contain no data (zero length), or contain data (non-zero length).
+ # when a buffer is None it means that it is either empty or zero length, and an empty buffer
+ # will have DataIsNone() equal to true.
+ # we should detect zero length buffers and report a warning because the TFLite semantics for these
+ # types of buffers changed in TensorFlow 2.11, whereby they could result in runtime errors
+ if buffer_data is None and not buffer.DataIsNone():
+ print(
+ f"Warning: Input TensorFlow Lite network contains a zero length buffer (index = {idx})"
+ f" which is semantically not empty. However, it will be treated as an empty buffer."
+ )
+
+ self.buffers.append(buffer_data)
parsing_step = "parsing operator codes length"
self.operator_codes = []
diff --git a/ethosu/vela/tflite_writer.py b/ethosu/vela/tflite_writer.py
index 8d44774b..625cf7cc 100644
--- a/ethosu/vela/tflite_writer.py
+++ b/ethosu/vela/tflite_writer.py
@@ -259,16 +259,13 @@ class TFLiteSerialiser:
tens_shape = tens.original_shape
values = tens.values
- if values is None:
- values = np.empty(shape=(0), dtype=np.uint8)
-
if tens in self.tensors_to_reshape:
reorder = self.tensors_to_reshape[tens]
tens_shape = [tens_shape[idx] for idx in reorder]
values = values.transpose(reorder)
buf_id = self.buffer_map[tens]
- self.buffers_to_write[buf_id] = values.flatten().view(np.uint8)
+ self.buffers_to_write[buf_id] = None if values is None else values.flatten().view(np.uint8)
shape = self.write_int_vector(tens_shape)