(self, original_node)
Replaces a MatMul node with the eight bit equivalent sub-graph.
Replaces a MatMul node with the eight bit equivalent sub-graph.
Replaces a MatMul node with the eight bit equivalent sub - graph .
def eightbitize_batch_norm_node(self, original_node):
    """Replaces a MatMul node with the eight bit equivalent sub-graph."""
    namespace_prefix = original_node.name + "_eightbit"
    original_input_name = original_node.input[0]
    original_mean_name = original_node.input[1]
    original_variance_name = original_node.input[2]
    original_beta_name = original_node.input[3]
    original_gamma_name = original_node.input[4]
    quantized_batch_norm_name = namespace_prefix + "_quantized_batch_norm"

    reshape_dims_name, reduction_dims_name = self.add_common_quantization_nodes(
        namespace_prefix)
    quantize_input_name, min_input_name, max_input_name = (
        self.eightbitize_input_to_node(namespace_prefix, original_input_name,
                                       reshape_dims_name, reduction_dims_name))
    quantize_mean_name, min_mean_name, max_mean_name = (
        self.eightbitize_input_to_node(namespace_prefix, original_mean_name,
                                       reshape_dims_name, reduction_dims_name))
    quantize_variance_name, min_variance_name, max_variance_name = (
        self.eightbitize_input_to_node(namespace_prefix, original_variance_name,
                                       reshape_dims_name, reduction_dims_name))
    quantize_beta_name, min_beta_name, max_beta_name = (
        self.eightbitize_input_to_node(namespace_prefix, original_beta_name,
                                       reshape_dims_name, reduction_dims_name))
    quantize_gamma_name, min_gamma_name, max_gamma_name = (
        self.eightbitize_input_to_node(namespace_prefix, original_gamma_name,
                                       reshape_dims_name, reduction_dims_name))
    quantized_batch_norm_node = create_node(
        "QuantizedBatchNormWithGlobalNormalization", quantized_batch_norm_name,
        [
            quantize_input_name, min_input_name, max_input_name,
            quantize_mean_name, min_mean_name, max_mean_name,
            quantize_variance_name, min_variance_name, max_variance_name,
            quantize_beta_name, min_beta_name, max_beta_name,
            quantize_gamma_name, min_gamma_name, max_gamma_name
        ])
    set_attr_dtype(quantized_batch_norm_node, "Tinput", dtypes.quint8)
    set_attr_dtype(quantized_batch_norm_node, "out_type", dtypes.qint32)
    copy_attr(quantized_batch_norm_node, "scale_after_normalization",
              original_node.attr["scale_after_normalization"])
    copy_attr(quantized_batch_norm_node, "variance_epsilon",
              original_node.attr["variance_epsilon"])
    self.add_output_graph_node(quantized_batch_norm_node)
    quantize_down_name = self.add_quantize_down_nodes(original_node,
                                                      quantized_batch_norm_name)
    self.add_dequantize_result_node(quantize_down_name, original_node.name)
def eightbitize_batch_norm_node ( self , original_node ) : namespace_prefix = original_node . name + "_eightbit" original_input_name = original_node . input [ 0 ] original_mean_name = original_node . input [ 1 ] original_variance_name = original_node . input [ 2 ] original_beta_name = original_node . input [ 3 ] original_gamma_name = original_node . input [ 4 ] quantized_batch_norm_name = namespace_prefix + "_quantized_batch_norm" reshape_dims_name , reduction_dims_name = self . add_common_quantization_nodes ( namespace_prefix ) quantize_input_name , min_input_name , max_input_name = ( self . eightbitize_input_to_node ( namespace_prefix , original_input_name , reshape_dims_name , reduction_dims_name ) ) quantize_mean_name , min_mean_name , max_mean_name = ( self . eightbitize_input_to_node ( namespace_prefix , original_mean_name , reshape_dims_name , reduction_dims_name ) ) quantize_variance_name , min_variance_name , max_variance_name = ( self . eightbitize_input_to_node ( namespace_prefix , original_variance_name , reshape_dims_name , reduction_dims_name ) ) quantize_beta_name , min_beta_name , max_beta_name = ( self . eightbitize_input_to_node ( namespace_prefix , original_beta_name , reshape_dims_name , reduction_dims_name ) ) quantize_gamma_name , min_gamma_name , max_gamma_name = ( self . eightbitize_input_to_node ( namespace_prefix , original_gamma_name , reshape_dims_name , reduction_dims_name ) ) quantized_batch_norm_node = create_node ( "QuantizedBatchNormWithGlobalNormalization" , quantized_batch_norm_name , [ quantize_input_name , min_input_name , max_input_name , quantize_mean_name , min_mean_name , max_mean_name , quantize_variance_name , min_variance_name , max_variance_name , quantize_beta_name , min_beta_name , max_beta_name , quantize_gamma_name , min_gamma_name , max_gamma_name ] ) set_attr_dtype ( quantized_batch_norm_node , "Tinput" , dtypes . quint8 ) set_attr_dtype ( quantized_batch_norm_node , "out_type" , dtypes . qint32 ) copy_attr ( quantized_batch_norm_node , "scale_after_normalization" , original_node . attr [ "scale_after_normalization" ] ) copy_attr ( quantized_batch_norm_node , "variance_epsilon" , original_node . attr [ "variance_epsilon" ] ) self . add_output_graph_node ( quantized_batch_norm_node ) quantize_down_name = self . add_quantize_down_nodes ( original_node , quantized_batch_norm_name ) self . add_dequantize_result_node ( quantize_down_name , original_node . name )