@@ -34,10 +34,6 @@ def default_config(cls):
3434class uTensorRearchGraphLower (uTensorGraphLowerBase ):
3535 PART = 'rearch_graph_lower'
3636
37- def __init__ (self , config ):
38- final_config = Configuration (self .default_config , config )
39- self .tflite_use_quant_dws_conv = final_config ['tflite_use_quant_dws_conv' ]
40-
4137 class OptypeRenameManager (object ):
4238 NAME_MAP = {
4339 'Add' : 'AddOperator' ,
@@ -49,12 +45,23 @@ class OptypeRenameManager(object):
4945 def get_new_optype (cls , op_type ):
5046 return cls .NAME_MAP .get (op_type , op_type )
5147
52- class AddCodegenAttributes (object ):
48+ class CheckQuantization (object ):
5349
5450 @classmethod
55- def add_attributes (cls , ugraph ):
56- for op_info in ugraph .get_ops_by_type ('DepthwiseSeparableConvOperator' ):
57- op_info .code_gen_attributes ['namespaces' ] = ('TFLM' ,)
51+ def apply (cls , ugraph ):
52+ if cls ._check_quantized (ugraph ):
53+ for op_info in ugraph .get_ops_by_type ('DepthwiseSeparableConvOperator' ):
54+ op_info .op_type = 'QuantizedDepthwiseSeparableConvOperator'
55+ for op_info in ugraph .get_ops_by_type ('FullyConnectedOperator' ):
56+ op_info .op_type = 'QuantizedFullyConnectedOperator'
57+
58+ @classmethod
59+ def _check_quantized (cls , ugraph ):
60+ for op_info in ugraph .ops_info .values ():
61+ for tensor_info in op_info .output_tensors :
62+ # FIXME: better way to check quantization
63+ if 'quantization_zeros' in tensor_info .attributes :
64+ return True
5865
5966 @classmethod
6067 def add_name_map (cls , generic_name , target_specific_name ):
@@ -65,11 +72,8 @@ def handle_tensorflow(self, ugraph):
6572 op_info .op_type = self .OptypeRenameManager .get_new_optype (op_info .op_type )
6673
6774 def handle_tflite (self , ugraph ):
68- if self .tflite_use_quant_dws_conv :
69- self .AddCodegenAttributes .add_attributes (ugraph )
75+ self .CheckQuantization .apply (ugraph )
7076
7177 @class_property
7278 def default_config (cls ):
73- return {
74- 'tflite_use_quant_dws_conv' : True ,
75- }
79+ return {}
0 commit comments