1616# under the License.
1717# pylint: disable=invalid-name, unused-argument, too-many-lines, import-outside-toplevel
1818"""Tensorflow lite frontend."""
19- import math
2019import itertools
20+ import math
21+
2122import numpy as np
2223import tvm
24+ from tvm import relay
2325from tvm .ir import IRModule
2426
25- from tvm import relay
27+ from ... import nd as _nd
2628from .. import analysis
2729from .. import expr as _expr
2830from .. import function as _function
2931from .. import op as _op
3032from .. import qnn as _qnn
31- from ... import nd as _nd
3233from .common import ExprTable
33- from .common import infer_shape as _infer_shape , to_int_list
34+ from .common import infer_shape as _infer_shape
35+ from .common import to_int_list
3436from .tflite_flexbuffer import FlexBufferDecoder
3537
36-
3738__all__ = ["from_tflite" ]
3839
3940
@@ -53,9 +54,9 @@ class OperatorConverter(object):
5354 def __init__ (self , model , subgraph , exp_tab ):
5455
5556 try :
57+ from tflite .ActivationFunctionType import ActivationFunctionType
5658 from tflite .BuiltinOperator import BuiltinOperator
5759 from tflite .BuiltinOptions import BuiltinOptions
58- from tflite .ActivationFunctionType import ActivationFunctionType
5960 except ImportError :
6061 raise ImportError ("The tflite package must be installed" )
6162
@@ -1061,8 +1062,8 @@ def convert_log_softmax(self, op):
10611062 def convert_concatenation (self , op ):
10621063 """Convert TFLite concatenation"""
10631064 try :
1064- from tflite .ConcatenationOptions import ConcatenationOptions
10651065 from tflite .BuiltinOptions import BuiltinOptions
1066+ from tflite .ConcatenationOptions import ConcatenationOptions
10661067 except ImportError :
10671068 raise ImportError ("The tflite package must be installed" )
10681069
@@ -1242,10 +1243,10 @@ def _convert_elemwise(self, relay_op, op, ignore_qnn_params=False):
12421243 """Generic method to Convert TFLite elemwise"""
12431244 try :
12441245 from tflite .AddOptions import AddOptions
1245- from tflite .SubOptions import SubOptions
1246- from tflite .MulOptions import MulOptions
1247- from tflite .DivOptions import DivOptions
12481246 from tflite .BuiltinOptions import BuiltinOptions
1247+ from tflite .DivOptions import DivOptions
1248+ from tflite .MulOptions import MulOptions
1249+ from tflite .SubOptions import SubOptions
12491250 except ImportError :
12501251 raise ImportError ("The tflite package must be installed" )
12511252
@@ -1804,9 +1805,9 @@ def convert_reduce_any(self, op):
18041805 def _convert_arg_min_max (self , relay_op , op ):
18051806 """Generic method converting TFLite arg_min_max"""
18061807 try :
1807- from tflite .BuiltinOptions import BuiltinOptions
1808- from tflite .ArgMinOptions import ArgMinOptions
18091808 from tflite .ArgMaxOptions import ArgMaxOptions
1809+ from tflite .ArgMinOptions import ArgMinOptions
1810+ from tflite .BuiltinOptions import BuiltinOptions
18101811 except ImportError :
18111812 raise ImportError ("The tflite package must be installed" )
18121813
@@ -1853,8 +1854,8 @@ def convert_arg_max(self, op):
18531854 def convert_fully_connected (self , op ):
18541855 """Convert TFLite fully connected"""
18551856 try :
1856- from tflite .FullyConnectedOptions import FullyConnectedOptions
18571857 from tflite .BuiltinOptions import BuiltinOptions
1858+ from tflite .FullyConnectedOptions import FullyConnectedOptions
18581859 from tflite .TensorType import TensorType
18591860 except ImportError :
18601861 raise ImportError ("The tflite package must be installed" )
@@ -2024,10 +2025,10 @@ def convert_conv(self, op, conv_type):
20242025 """convolution implementation."""
20252026 try :
20262027 from tflite .BuiltinOptions import BuiltinOptions
2027- from tflite .TensorType import TensorType
20282028 from tflite .Conv2DOptions import Conv2DOptions
20292029 from tflite .DepthwiseConv2DOptions import DepthwiseConv2DOptions
20302030 from tflite .Padding import Padding
2031+ from tflite .TensorType import TensorType
20312032 except ImportError :
20322033 raise ImportError ("The tflite package must be installed" )
20332034
@@ -2434,8 +2435,8 @@ def convert_pool2d(self, op, pool_type):
24342435 """pool2d implementation."""
24352436 try :
24362437 from tflite .BuiltinOptions import BuiltinOptions
2437- from tflite .Pool2DOptions import Pool2DOptions
24382438 from tflite .Padding import Padding
2439+ from tflite .Pool2DOptions import Pool2DOptions
24392440 except ImportError :
24402441 raise ImportError ("The tflite package must be installed" )
24412442
@@ -2850,9 +2851,9 @@ def convert_transpose_conv(self, op):
28502851 """Convert TFLite TRANSPOSE_CONV"""
28512852 try :
28522853 from tflite .BuiltinOptions import BuiltinOptions
2854+ from tflite .Padding import Padding
28532855 from tflite .TensorType import TensorType
28542856 from tflite .TransposeConvOptions import TransposeConvOptions
2855- from tflite .Padding import Padding
28562857 except ImportError :
28572858 raise ImportError ("The tflite package must be installed" )
28582859
@@ -2946,7 +2947,7 @@ def convert_transpose_conv(self, op):
29462947 channels = int (out_channels ),
29472948 kernel_size = (int (kernel_h ), int (kernel_w )),
29482949 data_layout = "NHWC" ,
2949- kernel_layout = "OIHW " ,
2950+ kernel_layout = "IOHW " ,
29502951 out_dtype = "int32" ,
29512952 )
29522953 else :
@@ -2958,7 +2959,7 @@ def convert_transpose_conv(self, op):
29582959 channels = int (out_channels ),
29592960 kernel_size = (int (kernel_h ), int (kernel_w )),
29602961 data_layout = "NHWC" ,
2961- kernel_layout = "OIHW " ,
2962+ kernel_layout = "IOHW " ,
29622963 out_dtype = output_tensor_type_str ,
29632964 )
29642965
@@ -3717,8 +3718,8 @@ def from_tflite(model, shape_dict=None, dtype_dict=None, op_converter=OperatorCo
37173718 The parameter dict to be used by relay
37183719 """
37193720 try :
3720- import tflite .SubGraph
37213721 import tflite .BuiltinOperator
3722+ import tflite .SubGraph
37223723 except ImportError :
37233724 raise ImportError ("The tflite package must be installed" )
37243725
0 commit comments