Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.nn.Conv2dBnFoldQuantOneConv

class mindspore.nn.Conv2dBnFoldQuantOneConv(in_channels, out_channels, kernel_size, stride=1, pad_mode='same', padding=0, dilation=1, group=1, eps=1e-05, momentum=0.997, has_bias=False, weight_init='normal', bias_init='zeros', beta_init='zeros', gamma_init='ones', mean_init='zeros', var_init='ones', fake=True, quant_config=quant_config_default, quant_dtype=QuantDtype.INT8)[source]

2D convolution which use the convolution layer statistics once to calculate Batch Normalization operation folded construct.

This part is a more detailed overview of Conv2d operation. For more details about Quantization, please refer to the implementation of class of FakeQuantWithMinMaxObserver, FakeQuantWithMinMaxObserver.

wq=quant(wvarG+ϵγ)b=μGvarG+ϵγ+βy=wq×x+b

where quant is the continuous execution of quant and dequant, you can refer to the implementation of subclass of FakeQuantWithMinMaxObserver, mindspore.nn.FakeQuantWithMinMaxObserver. mu _{G} and var_{G} represent the global mean and variance respectively.

Parameters
  • in_channels (int) – The number of input channel Cin.

  • out_channels (int) – The number of output channel Cout.

  • kernel_size (Union[int, tuple[int]]) – Specifies the height and width of the 2D convolution window.

  • stride (Union[int, tuple[int]]) – Specifies stride for all spatial dimensions with the same value. Default: 1.

  • pad_mode (str) – Specifies padding mode. The optional values are “same”, “valid”, “pad”. Default: “same”.

  • padding (Union[int, tuple[int]]) – Implicit paddings on both sides of the x. Default: 0.

  • dilation (Union[int, tuple[int]]) – Specifies the dilation rate to use for dilated convolution. Default: 1.

  • group (int) – Splits filter into groups, in_ channels and out_channels must be divisible by the number of groups. Default: 1.

  • eps (float) – Parameters for Batch Normalization. Default: 1e-5.

  • momentum (float) – Parameters for Batch Normalization op. Default: 0.997.

  • has_bias (bool) – Specifies whether the layer uses a bias vector, which is temporarily invalid. Default: False.

  • weight_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the convolution kernel. Default: ‘normal’.

  • bias_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the bias vector. Default: ‘zeros’.

  • beta_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the beta vector. Default: ‘zeros’.

  • gamma_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the gamma vector. Default: ‘ones’.

  • mean_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the mean vector. Default: ‘zeros’.

  • var_init (Union[Tensor, str, Initializer, numbers.Number]) – Initializer for the variance vector. Default: ‘ones’.

  • fake (bool) – Whether Conv2dBnFoldQuant Cell adds FakeQuantWithMinMaxObserver. Default: True.

  • quant_config (QuantConfig) – Configures the types of quant observer and quant settings of weight and activation. Note that, QuantConfig is a special namedtuple, which is designed for quantization and can be generated by mindspore.compression.quant.create_quant_config() method. Default: QuantConfig with both items set to default FakeQuantWithMinMaxObserver.

  • quant_dtype (QuantDtype) – Specifies the FakeQuant datatype. Default: QuantDtype.INT8.

Inputs:
  • x (Tensor) - Tensor of shape (N,Cin,Hin,Win).

Outputs:

Tensor of shape (N,Cout,Hout,Wout).

Raises
  • TypeError – If in_channels, out_channels or group is not an int.

  • TypeError – If kernel_size, stride, padding or dilation is neither an int nor a tuple.

  • TypeError – If has_bias or fake is not a bool.

  • TypeError – If data_format is not a string.

  • ValueError – If in_channels, out_channels, kernel_size, stride or dilation is less than 1.

  • ValueError – If padding is less than 0.

  • ValueError – If pad_mode is not one of ‘same’, ‘valid’, ‘pad’.

Supported Platforms:

Ascend GPU

Examples

>>> import mindspore
>>> from mindspore.compression import quant
>>> from mindspore import Tensor
>>> qconfig = quant.create_quant_config()
>>> conv2d_bnfold = nn.Conv2dBnFoldQuantOneConv(1, 1, kernel_size=(2, 2), stride=(1, 1), pad_mode="valid",
...                                             weight_init="ones", quant_config=qconfig)
>>> x = Tensor(np.array([[[[1, 0, 3], [1, 4, 7], [2, 5, 2]]]]), mindspore.float32)
>>> result = conv2d_bnfold(x)
>>> print(result)
[[[[5.9296875 13.8359375]
   [11.859375 17.78125]]]]
extend_repr()[source]

Display instance object as string.