parameters: (self, model, candidate_layers, layer_metadata)
return_statement: return transformed_model, layer_metadata
docstring: Implement vitis 8-bit optimize transforms to make it more quantize-friendly.
  
      All the transforms should not break the float model structure, and
      the output of the transformed model should be consistant with the float 
      model.
docstring_summary: Implement vitis 8-bit optimize transforms to make it more quantize-friendly.
docstring_tokens: Implement vitis 8 - bit optimize transforms to make it more quantize - friendly .
function: def apply(self, model, candidate_layers, layer_metadata):
      """Implement vitis 8-bit optimize transforms to make it more quantize-friendly.
  
      All the transforms should not break the float model structure, and
      the output of the transformed model should be consistant with the float 
      model.
      """
      configs = self.get_configs()
  
      available_transforms = collections.OrderedDict({
          'remove_dropout': vitis_optimize_transforms.RemoveDropout(),
          'separate_conv_act': vitis_optimize_transforms.SeparateConvAct(),
          'replace_relu6': vitis_optimize_transforms.ReplaceReLU6WithReLU(),
          'replace_tf_op': vitis_optimize_transforms.ReplaceTFOpLayer(),
      })
  
      transformed_model, layer_metadata = _apply_availables(
          model, configs, available_transforms, candidate_layers, layer_metadata)
  
      # Train with bn is conflict with fold bn params
      model = transformed_model
      if configs['train_with_bn']:
        transforms = [
            vitis_optimize_transforms.FakeConvBNFold(),
        ]
        transformed_model, _ = model_transformer.ModelTransformer(
            model, transforms, None, None).recursive_transform()
      else:
        available_transforms = {
            'fold_conv_bn': vitis_optimize_transforms.Conv2DBatchNormFold(),
            'fold_bn': vitis_optimize_transforms.BatchNormFold(),
        }
        transformed_model, layer_metadata = _apply_availables(
            model, configs, available_transforms, candidate_layers,
            layer_metadata)
  
      # Cross Layer Equalization
      if configs['include_cle']:
        forced_cle = configs['forced_cle']
        balance_method = configs['balance_method']
        weight_threshold = configs['weight_threshold']
        cle_transforms = [
            vitis_equalization_transforms.ConvConvCLE(forced_cle, balance_method,
                                                      weight_threshold),
            vitis_equalization_transforms.ConvActConvCLE(forced_cle,
                                                         balance_method,
                                                         weight_threshold),
            vitis_equalization_transforms.ConvReLUConvCLE(forced_cle,
                                                          balance_method,
                                                          weight_threshold),
            vitis_equalization_transforms.ConvReLUPadConvCLE(
                forced_cle, balance_method, weight_threshold)
        ]
  
        cle_steps = configs['cle_steps']
        progbar = keras.utils.Progbar(cle_steps)
        logger.info('Start CrossLayerEqualization...')
        for i in range(cle_steps):
          progbar.update(i + 1)
          tmp_model = transformed_model
          transformed_model, layer_metadata = model_transformer.ModelTransformer(
              tmp_model, cle_transforms, candidate_layers,
              layer_metadata).recursive_transform()
        logger.info('CrossLayerEqualization Done.')
  
      if logger.debug_enabled():
        model_utils.save_model(transformed_model, 'optimized_model.h5',
                               './debug/')
      return transformed_model, layer_metadata
function_tokens: def apply ( self , model , candidate_layers , layer_metadata ) : configs = self . get_configs ( ) available_transforms = collections . OrderedDict ( { 'remove_dropout' : vitis_optimize_transforms . RemoveDropout ( ) , 'separate_conv_act' : vitis_optimize_transforms . SeparateConvAct ( ) , 'replace_relu6' : vitis_optimize_transforms . ReplaceReLU6WithReLU ( ) , 'replace_tf_op' : vitis_optimize_transforms . ReplaceTFOpLayer ( ) , } ) transformed_model , layer_metadata = _apply_availables ( model , configs , available_transforms , candidate_layers , layer_metadata ) # Train with bn is conflict with fold bn params model = transformed_model if configs [ 'train_with_bn' ] : transforms = [ vitis_optimize_transforms . FakeConvBNFold ( ) , ] transformed_model , _ = model_transformer . ModelTransformer ( model , transforms , None , None ) . recursive_transform ( ) else : available_transforms = { 'fold_conv_bn' : vitis_optimize_transforms . Conv2DBatchNormFold ( ) , 'fold_bn' : vitis_optimize_transforms . BatchNormFold ( ) , } transformed_model , layer_metadata = _apply_availables ( model , configs , available_transforms , candidate_layers , layer_metadata ) # Cross Layer Equalization if configs [ 'include_cle' ] : forced_cle = configs [ 'forced_cle' ] balance_method = configs [ 'balance_method' ] weight_threshold = configs [ 'weight_threshold' ] cle_transforms = [ vitis_equalization_transforms . ConvConvCLE ( forced_cle , balance_method , weight_threshold ) , vitis_equalization_transforms . ConvActConvCLE ( forced_cle , balance_method , weight_threshold ) , vitis_equalization_transforms . ConvReLUConvCLE ( forced_cle , balance_method , weight_threshold ) , vitis_equalization_transforms . ConvReLUPadConvCLE ( forced_cle , balance_method , weight_threshold ) ] cle_steps = configs [ 'cle_steps' ] progbar = keras . utils . Progbar ( cle_steps ) logger . info ( 'Start CrossLayerEqualization...' ) for i in range ( cle_steps ) : progbar . update ( i + 1 ) tmp_model = transformed_model transformed_model , layer_metadata = model_transformer . ModelTransformer ( tmp_model , cle_transforms , candidate_layers , layer_metadata ) . recursive_transform ( ) logger . info ( 'CrossLayerEqualization Done.' ) if logger . debug_enabled ( ) : model_utils . save_model ( transformed_model , 'optimized_model.h5' , './debug/' ) return transformed_model , layer_metadata