From 515c956c9cc6d45493e45d57b822e30a7317d1ed Mon Sep 17 00:00:00 2001 From: Michael McGeagh Date: Wed, 2 Sep 2020 15:52:43 +0100 Subject: 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 Change-Id: If79817100869e712a75264889f401e38de0b1e7a --- ethosu/vela/tflite_writer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'ethosu/vela') 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) -- cgit v1.2.1