Skip to content

Commit

Permalink
[SDK] compatible with tflite 2.1.0
Browse files Browse the repository at this point in the history
see commit 8599f7c
[TFLite] Model importer to be compatible with tflite 2.1.0 (apache#5497)

Signed-off-by: Taikang Hu <[email protected]>
  • Loading branch information
Taikang Hu committed Jul 2, 2020
1 parent 03fa40b commit ecfa27d
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions python/asr/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,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},
Expand Down

0 comments on commit ecfa27d

Please sign in to comment.