@@ -36,10 +36,6 @@ def default_config(cls):
3636class uTensorRearchGraphLower (uTensorGraphLowerBase ):
3737 PART = 'rearch_graph_lower'
3838
39- def __init__ (self , config ):
40- final_config = Configuration (self .default_config , config )
41- self .tflite_use_quant_dws_conv = final_config ['tflite_use_quant_dws_conv' ]
42-
4339 class OptypeRenameManager (object ):
4440 NAME_MAP = {
4541 'Add' : 'AddOperator' ,
@@ -51,12 +47,23 @@ class OptypeRenameManager(object):
5147 def get_new_optype (cls , op_type ):
5248 return cls .NAME_MAP .get (op_type , op_type )
5349
54- class AddCodegenAttributes (object ):
50+ class CheckQuantization (object ):
5551
5652 @classmethod
57- def add_attributes (cls , ugraph ):
58- for op_info in ugraph .get_ops_by_type ('DepthwiseSeparableConvOperator' ):
59- op_info .code_gen_attributes ['namespaces' ] = ('TFLM' ,)
53+ def apply (cls , ugraph ):
54+ if cls ._check_quantized (ugraph ):
55+ for op_info in ugraph .get_ops_by_type ('DepthwiseSeparableConvOperator' ):
56+ op_info .op_type = 'QuantizedDepthwiseSeparableConvOperator'
57+ for op_info in ugraph .get_ops_by_type ('FullyConnectedOperator' ):
58+ op_info .op_type = 'QuantizedFullyConnectedOperator'
59+
60+ @classmethod
61+ def _check_quantized (cls , ugraph ):
62+ for op_info in ugraph .ops_info .values ():
63+ for tensor_info in op_info .output_tensors :
64+ # FIXME: better way to check quantization
65+ if 'quantization_zeros' in tensor_info .attributes :
66+ return True
6067
6168 @classmethod
6269 def add_name_map (cls , generic_name , target_specific_name ):
@@ -67,11 +74,8 @@ def handle_tensorflow(self, ugraph):
6774 op_info .op_type = self .OptypeRenameManager .get_new_optype (op_info .op_type )
6875
6976 def handle_tflite (self , ugraph ):
70- if self .tflite_use_quant_dws_conv :
71- self .AddCodegenAttributes .add_attributes (ugraph )
77+ self .CheckQuantization .apply (ugraph )
7278
7379 @class_property
7480 def default_config (cls ):
75- return {
76- 'tflite_use_quant_dws_conv' : True ,
77- }
81+ return {}
0 commit comments