subgraphs in .tflite

162 views
Skip to first unread message

Iosif Hamlatzis

unread,
Apr 29, 2022, 4:33:44 AM4/29/22
to TensorFlow Lite
I have a model saved in r2.0 as checkpoint format. When later I load it and try to convert it to tflite I have a crash because toco doesn't know how to handle "if op" and tries to import it as an unsupported operation

=> strange because there is an if kernel registered in tflite

The crash is inside "tensorflow/lite/toco/import_tensorflow.cc:114". It tries to import a list by first checking for the word "_output_types" and because it doesn't find it the next check is for the word "Tout". When it finds this tries to load the type but one of the checks inside "GetDataTypeAttr" is for AttrValue::kType but finds AttrValue::kList, so "CHECK_EQ(attr.value_case(), AttrValue::kType);" fails

I've re-written the code to handle both cases, so now I have my .tflite file

Next problem is that at runtime I get an error that custom op If doesn't exists

=> strange because there is an if kernel registered in tflite

Again fixed this by re-registering the code of "If" as a custom op

Now there are several problems with "init", "prepare" and "eval" functions.

=> The way the "init" tries to read the params is wrong and returns incorrect results
       This is solvable, instead of using reinterpret_cast<const TfLiteIfParams*>(buffer); one can read the buffer as flextbffer into a flexbuffers::Map and query the values

=> The "prepare" and "eval" functions expect the .tflite file to have subgraphs, but only one exists in the file. This to me is unsolvable. 

I have no clue how either to write a new "if op" or have toco create a .tflite with multiple subgraphs (different subgraph per "if op" per branch (true/false))

Any help?

thnx

Karim Nosseir

unread,
May 3, 2022, 3:07:00 PM5/3/22
to Iosif Hamlatzis, TensorFlow Lite
Hi Iosif,

toco is deprecated, and TFLite support control flow ops (If and While) in the new converter. You don't need to do anything special to use the new converter, it is the default when you try to convert your model through our python API. See the guide

--
You received this message because you are subscribed to the Google Groups "TensorFlow Lite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tflite+un...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/tflite/b0c4d5fb-6ec1-4220-aa93-3292b6a02bdbn%40tensorflow.org.


--
Regards,
Karim Nosseir
Reply all
Reply to author
Forward
0 new messages