aboutsummaryrefslogtreecommitdiff
path: root/ethosu/vela/tflite_writer.py
diff options
context:
space:
mode:
authorMichael McGeagh <michael.mcgeagh@arm.com>2020-09-02 15:52:43 +0100
committerpatrik.gustavsson <patrik.gustavsson@arm.com>2020-09-07 06:26:08 +0000
commit515c956c9cc6d45493e45d57b822e30a7317d1ed (patch)
tree27ea9ffcc815349bbc0d6c27bb555ef90249ff78 /ethosu/vela/tflite_writer.py
parent835d8e10f33f411664cebe65d3f6a872f6cc849a (diff)
downloadethos-u-vela-515c956c9cc6d45493e45d57b822e30a7317d1ed.tar.gz
MLBEDSW-2874 Fix writing out empty tflite files
If a tflite file with no ops but just the input/output tensor is given, vela wrote an empty optimised tflite file with no tensors given. This fixes that by allowing all placeholder tensors to also be serialised on write. Signed-off-by: Michael McGeagh <michael.mcgeagh@arm.com> Change-Id: If79817100869e712a75264889f401e38de0b1e7a
Diffstat (limited to 'ethosu/vela/tflite_writer.py')
-rw-r--r--ethosu/vela/tflite_writer.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/ethosu/vela/tflite_writer.py b/ethosu/vela/tflite_writer.py
index 77e6f953..cb208d7e 100644
--- a/ethosu/vela/tflite_writer.py
+++ b/ethosu/vela/tflite_writer.py
@@ -75,10 +75,8 @@ class TFLiteSerialiser:
self.scratch_buf_id = 0 # Always assign scratch to buffer 0
self.scratch_fast_buf_id = 1 # Always assign scratch_fast to buffer 1
- self.buffer_offsets_map = {}
self.buffers_to_write = [] # have an empty array there
- self.input_tensors = []
self.ops_to_ignore = set(("Const", "Placeholder", "SubgraphInput"))
self.tensors_to_reshape = {}
@@ -301,14 +299,20 @@ class TFLiteSerialiser:
def serialise_subgraph(self, sg):
builder = self.builder
tensor_set = set()
-
all_ops = []
+ placeholder_ops = []
+
for ps in sg.passes:
for op in ps.ops:
if op.type not in self.ops_to_ignore:
all_ops.append(op)
+ elif op.type == "Placeholder":
+ placeholder_ops.append(op)
- for op in all_ops:
+ # Add the tensors from all valid ops, as well as the tensors from placeholder ops
+ # This allows us to serialise tensors which arent attached to any specific ops,
+ # e.g. due to an empty graph containing no ops
+ for op in all_ops + placeholder_ops:
for tens in op.inputs + op.outputs:
tensor_set.add(tens)