parameters: (graph,
               weight_bits=8,
               weight_narrow_range=False,
               activation_bits=8,
               ema_decay=0.999,
               quant_delay=None,
               vars_collection=ops.GraphKeys.MOVING_AVERAGE_VARIABLES,
               is_training=True,
               quantize_folded_weights_use_ema=False)
docstring: Updates graph with quantization operations.
  
    Args:
      graph: Graph to modify.
      weight_bits: Number of bits to use for quantizing weights.
      weight_narrow_range: Whether to use a more efficient narrow range for
        weights quantization.  With weight_narrow_range true, the range is
        [1; 2^weight_bits - 1], with it false [0; 2^weight_bits - 1].
      activation_bits: Number of bits to use for quantizing activations.
      ema_decay: (Optional) Float, EMA decay parameter.  EMA is used to update
        quantization intervals for quantizing activations (see here about EMA:
        https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average).
      quant_delay: (Optional, default None) Int, count of global steps for which
        to delay quantization.  This helps weights stabilize at the start of
        training.
      vars_collection: (Optional) Collection where to store the variables for
        quantization interval ends.
      is_training: (Optional) Whether quantizing training graph or eval graph.
      quantize_folded_weights_use_ema: (Optional, default False) Whether to
        quantize weights after batchnorm-folding with exponential average
        quantization.
    Raises:
      ValueError: When quantization fails.
docstring_summary: Updates graph with quantization operations.
docstring_tokens: Updates graph with quantization operations .
function: def Quantize(graph,
               weight_bits=8,
               weight_narrow_range=False,
               activation_bits=8,
               ema_decay=0.999,
               quant_delay=None,
               vars_collection=ops.GraphKeys.MOVING_AVERAGE_VARIABLES,
               is_training=True,
               quantize_folded_weights_use_ema=False):
    """Updates graph with quantization operations.
  
    Args:
      graph: Graph to modify.
      weight_bits: Number of bits to use for quantizing weights.
      weight_narrow_range: Whether to use a more efficient narrow range for
        weights quantization.  With weight_narrow_range true, the range is
        [1; 2^weight_bits - 1], with it false [0; 2^weight_bits - 1].
      activation_bits: Number of bits to use for quantizing activations.
      ema_decay: (Optional) Float, EMA decay parameter.  EMA is used to update
        quantization intervals for quantizing activations (see here about EMA:
        https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average).
      quant_delay: (Optional, default None) Int, count of global steps for which
        to delay quantization.  This helps weights stabilize at the start of
        training.
      vars_collection: (Optional) Collection where to store the variables for
        quantization interval ends.
      is_training: (Optional) Whether quantizing training graph or eval graph.
      quantize_folded_weights_use_ema: (Optional, default False) Whether to
        quantize weights after batchnorm-folding with exponential average
        quantization.
    Raises:
      ValueError: When quantization fails.
    """
    context = _QuantizeContext(graph, weight_bits, weight_narrow_range,
                               activation_bits, ema_decay, quant_delay,
                               vars_collection, is_training,
                               quantize_folded_weights_use_ema)
  
    graph_ops = graph.get_operations()
  
    # Filter out backprop and summary related operations, leave only interesting
    # op types.
    def _IsInterestingOpWithWeights(op):
      return (op.type in _QUANTIZABLE_TYPES and
              not op.name.startswith(common.SKIPPED_PREFIXES))
  
    for op in (op for op in graph_ops if _IsInterestingOpWithWeights(op)):
      if op.name.endswith('/depthwise'):
        # Separable convolution may consist of 2 convolution nodes.  If so,
        # skip .../depthwise and only quantize the top one.
        separable_conv = context.GetOperationByNameDontThrow(
            op.name[:-len('/depthwise')])
        if separable_conv and separable_conv.type == 'Conv2D':
          continue
      if not op.name.endswith('_Fold'):
        folded_op = context.GetOperationByNameDontThrow(op.name + '_Fold')
        # Do nothing if found, it will be quantized when it is iterated over.
        if not folded_op:
          context.QuantizeOpWithWeights(op, folded=False)
      else:
        context.QuantizeOpWithWeights(op, folded=True)
  
    # Once all quantization ops have been inserted in the graph, collect update
    # ops for their variables and modify the TF Slim update barrier (see
    # https://www.tensorflow.org/code/tensorflow/contrib/slim/python/slim/learning.py)
    # to depend on them.
    try:
      update_barrier = graph.get_operation_by_name('update_barrier')
    except KeyError:
      # In evaluation graph, this barrier may not exist.
      return None
    update_quant_ops = graph.get_collection_ref(_UPDATE_QUANT_OPS)
    graph_editor.add_control_inputs(update_barrier, update_quant_ops)
function_tokens: def Quantize ( graph , weight_bits = 8 , weight_narrow_range = False , activation_bits = 8 , ema_decay = 0.999 , quant_delay = None , vars_collection = ops . GraphKeys . MOVING_AVERAGE_VARIABLES , is_training = True , quantize_folded_weights_use_ema = False ) : context = _QuantizeContext ( graph , weight_bits , weight_narrow_range , activation_bits , ema_decay , quant_delay , vars_collection , is_training , quantize_folded_weights_use_ema ) graph_ops = graph . get_operations ( ) # Filter out backprop and summary related operations, leave only interesting # op types. def _IsInterestingOpWithWeights ( op ) : return ( op . type in _QUANTIZABLE_TYPES and not op . name . startswith ( common . SKIPPED_PREFIXES ) ) for op in ( op for op in graph_ops if _IsInterestingOpWithWeights ( op ) ) : if op . name . endswith ( '/depthwise' ) : # Separable convolution may consist of 2 convolution nodes.  If so, # skip .../depthwise and only quantize the top one. separable_conv = context . GetOperationByNameDontThrow ( op . name [ : - len ( '/depthwise' ) ] ) if separable_conv and separable_conv . type == 'Conv2D' : continue if not op . name . endswith ( '_Fold' ) : folded_op = context . GetOperationByNameDontThrow ( op . name + '_Fold' ) # Do nothing if found, it will be quantized when it is iterated over. if not folded_op : context . QuantizeOpWithWeights ( op , folded = False ) else : context . QuantizeOpWithWeights ( op , folded = True ) # Once all quantization ops have been inserted in the graph, collect update # ops for their variables and modify the TF Slim update barrier (see # https://www.tensorflow.org/code/tensorflow/contrib/slim/python/slim/learning.py) # to depend on them. try : update_barrier = graph . get_operation_by_name ( 'update_barrier' ) except KeyError : # In evaluation graph, this barrier may not exist. return None update_quant_ops = graph . get_collection_ref ( _UPDATE_QUANT_OPS ) graph_editor . add_control_inputs ( update_barrier , update_quant_ops )