parameters: (weight, cell_quant)
return_statement: return weight, bias
docstring: r"""
      Fold the batchnorm in `Conv2dBnFoldQuant` to weight.
  
      Calculate from `FakeQuantWithMinMax`'s Parameter or Fake quant primitive.
  
      Args:
          weight (numpy.ndarray): Weight of `cell_quant`.
          cell_quant (Cell): Object of `mindspore.nn.layer.Conv2dBnFoldQuant`.
  
      Returns:
          weight (numpy.ndarray): Folded weight.
          bias (numpy.ndarray): Folded bias.
docstring_summary: r"""
      Fold the batchnorm in `Conv2dBnFoldQuant` to weight.
docstring_tokens: r Fold the batchnorm in Conv2dBnFoldQuant to weight .
function: def fold_batchnorm(weight, cell_quant):
      r"""
      Fold the batchnorm in `Conv2dBnFoldQuant` to weight.
  
      Calculate from `FakeQuantWithMinMax`'s Parameter or Fake quant primitive.
  
      Args:
          weight (numpy.ndarray): Weight of `cell_quant`.
          cell_quant (Cell): Object of `mindspore.nn.layer.Conv2dBnFoldQuant`.
  
      Returns:
          weight (numpy.ndarray): Folded weight.
          bias (numpy.ndarray): Folded bias.
      """
      variance = cell_quant.moving_variance.data.asnumpy()
      mean = cell_quant.moving_mean.data.asnumpy()
      gamma = cell_quant.gamma.data.asnumpy()
      beta = cell_quant.beta.data.asnumpy()
      epsilon = cell_quant.eps
      sigma = np.sqrt(variance + epsilon)
  
      if gamma.shape[0] == weight.shape[0]:
          # `Conv2d` or `Dense` op weight
          shape_list = [-1] + [1] * len(weight.shape[1:])
          _gamma = gamma.reshape(shape_list)
          _sigma = sigma.reshape(shape_list)
      elif gamma.shape[0] == weight.shape[1]:
          # `DepthwiseConv2d` op weight
          shape_list = [1, -1] + [1] * len(weight.shape[2:])
          _gamma = gamma.reshape(shape_list)
          _sigma = sigma.reshape(shape_list)
      else:
          raise ValueError("Unsupported weight shape({})".format(weight.shape))
  
      weight = weight * _gamma / _sigma
      bias = beta - gamma * mean / sigma
      return weight, bias
function_tokens: def fold_batchnorm ( weight , cell_quant ) : variance = cell_quant . moving_variance . data . asnumpy ( ) mean = cell_quant . moving_mean . data . asnumpy ( ) gamma = cell_quant . gamma . data . asnumpy ( ) beta = cell_quant . beta . data . asnumpy ( ) epsilon = cell_quant . eps sigma = np . sqrt ( variance + epsilon ) if gamma . shape [ 0 ] == weight . shape [ 0 ] : # `Conv2d` or `Dense` op weight shape_list = [ - 1 ] + [ 1 ] * len ( weight . shape [ 1 : ] ) _gamma = gamma . reshape ( shape_list ) _sigma = sigma . reshape ( shape_list ) elif gamma . shape [ 0 ] == weight . shape [ 1 ] : # `DepthwiseConv2d` op weight shape_list = [ 1 , - 1 ] + [ 1 ] * len ( weight . shape [ 2 : ] ) _gamma = gamma . reshape ( shape_list ) _sigma = sigma . reshape ( shape_list ) else : raise ValueError ( "Unsupported weight shape({})" . format ( weight . shape ) ) weight = weight * _gamma / _sigma bias = beta - gamma * mean / sigma return weight , bias