diff options
author | Tim Hall <tim.hall@arm.com> | 2023-04-06 21:01:58 +0100 |
---|---|---|
committer | Tim Hall <tim.hall@arm.com> | 2023-04-21 18:23:03 +0100 |
commit | 2f18e172a3d727d7c610855e93d8aeccd2fca9b1 (patch) | |
tree | 3e5bf457df0334e9d398bb8b8be2a6903744e39d /ethosu/vela/tflite_reader.py | |
parent | 2180a172c31f27899d3bf77bfecccc1768667737 (diff) | |
download | ethos-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>
Diffstat (limited to 'ethosu/vela/tflite_reader.py')
-rw-r--r-- | ethosu/vela/tflite_reader.py | 20 |
1 files changed, 17 insertions, 3 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 = [] |