From 734d9c8371b3c9cccac9b4db61cca6ff1211f76d Mon Sep 17 00:00:00 2001 From: Taikang Hu Date: Tue, 19 May 2020 16:28:04 +0800 Subject: [PATCH] [SDK] compatible with tflite 2.1.0 see commit 8599f7c61c84b70adec659c8e0c99ac963ce0796 [TFLite] Model importer to be compatible with tflite 2.1.0 (#5497) Signed-off-by: Taikang Hu --- python/asr/nn.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/python/asr/nn.py b/python/asr/nn.py index 03aac568c5164..5131c9bfe23a5 100644 --- a/python/asr/nn.py +++ b/python/asr/nn.py @@ -75,10 +75,16 @@ def _load_frontend_model(path, input_tensor): input_dtype = 'float32' if info.frontend == 'tflite': - import tflite.Model + import tflite tflite_model_buf = open(path, 'rb').read() - tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model_buf, 0) + # TFLite.Model.Model has changed to TFLite.Model from 1.14 to 2.1 + try: + tflite_model = tflite.Model.Model.GetRootAsModel(tflite_model_buf, 0) + except AttributeError: + tflite_model = tflite.Model.GetRootAsModel(tflite_model_buf, 0) + except ImportError: + raise ImportError("The tflite package must be installed") mod, param = relay.frontend.from_tflite(tflite_model, shape_dict={input_tensor: input_shape},