parameters: (self, nodes, scaled_output)
docstring: Given a node, this function handles bias add by adding a "reshape" node on bias and an "add" node
              parameter nodes: new nodes would be appended into nodes
              parameter node: current node (Conv)
              parameter scaled_output: output of quant conv without bias
              parameter output: output of Conv
              parameter bias_name: bias of Conv
              return: the name of output
docstring_summary: Given a node, this function handles bias add by adding a "reshape" node on bias and an "add" node
              parameter nodes: new nodes would be appended into nodes
              parameter node: current node (Conv)
              parameter scaled_output: output of quant conv without bias
              parameter output: output of Conv
              parameter bias_name: bias of Conv
              return: the name of output
docstring_tokens: Given a node this function handles bias add by adding a reshape node on bias and an add node parameter nodes : new nodes would be appended into nodes parameter node : current node ( Conv ) parameter scaled_output : output of quant conv without bias parameter output : output of Conv parameter bias_name : bias of Conv return : the name of output
function: def add_bias(self, nodes, scaled_output):
          '''
          Given a node, this function handles bias add by adding a "reshape" node on bias and an "add" node
              parameter nodes: new nodes would be appended into nodes
              parameter node: current node (Conv)
              parameter scaled_output: output of quant conv without bias
              parameter output: output of Conv
              parameter bias_name: bias of Conv
              return: the name of output
          '''
          node = self.node
          model = self.quantizer.model
          # Add tensors for the shape to be reshaped to
          weight = find_by_name(node.input[1], model.initializer())
          if weight is None:
              raise ValueError("Expected {} to be an initializer".format(node.input[1]))
  
          # Add reshape for correct broadcase
          output = node.output[0]
          reshape_input_data = node.input[2] # bias of Conv
          reshape_input_shape = output + "_bias_reshape_shape"
          reshape_output = output + "_bias_reshape_output"
  
          shape = np.ones((len(weight.dims)), dtype=np.int64)
          shape[1] = -1
          init_shape = onnx.helper.make_tensor(reshape_input_shape, onnx_proto.TensorProto.INT64, [len(weight.dims)],
                                               shape)
          model.add_initializer(init_shape)
  
          reshape_node = onnx.helper.make_node("Reshape", [reshape_input_data, reshape_input_shape], [reshape_output])
          nodes.append(reshape_node)
  
          # Add an Add operation for bias
          add_node = onnx.helper.make_node("Add", [scaled_output, reshape_output], [output], output + "_bias_add")
          nodes.append(add_node)
function_tokens: def add_bias ( self , nodes , scaled_output ) : node = self . node model = self . quantizer . model # Add tensors for the shape to be reshaped to weight = find_by_name ( node . input [ 1 ] , model . initializer ( ) ) if weight is None : raise ValueError ( "Expected {} to be an initializer" . format ( node . input [ 1 ] ) ) # Add reshape for correct broadcase output = node . output [ 0 ] reshape_input_data = node . input [ 2 ] # bias of Conv reshape_input_shape = output + "_bias_reshape_shape" reshape_output = output + "_bias_reshape_output" shape = np . ones ( ( len ( weight . dims ) ) , dtype = np . int64 ) shape [ 1 ] = - 1 init_shape = onnx . helper . make_tensor ( reshape_input_shape , onnx_proto . TensorProto . INT64 , [ len ( weight . dims ) ] , shape ) model . add_initializer ( init_shape ) reshape_node = onnx . helper . make_node ( "Reshape" , [ reshape_input_data , reshape_input_shape ] , [ reshape_output ] ) nodes . append ( reshape_node ) # Add an Add operation for bias add_node = onnx . helper . make_node ( "Add" , [ scaled_output , reshape_output ] , [ output ] , output + "_bias_add" ) nodes . append ( add_node )