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.probability.bnn_layers.DenseLocalReparam

class mindspore.nn.probability.bnn_layers.DenseLocalReparam(in_channels, out_channels, activation=None, has_bias=True, weight_prior_fn=NormalPrior, weight_posterior_fn=<lambda name, shape: NormalPosterior(name=name, shape=shape)>, bias_prior_fn=NormalPrior, bias_posterior_fn=<lambda name, shape: NormalPosterior(name=name, shape=shape)>)[source]

Dense variational layers with Local Reparameterization.

For more details, refer to the paper Variational Dropout and the Local Reparameterization Trick.

Applies dense-connected layer to the input. This layer implements the operation as:

outputs=activation(inputsweight+bias),

where activation is the activation function passed as the activation argument (if passed in), activation is a weight matrix with the same data type as the inputs created by the layer, weight is a weight matrix sampling from posterior distribution of weight, and bias is a bias vector with the same data type as the inputs created by the layer (only if has_bias is True). The bias vector is sampling from posterior distribution of bias.

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

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

  • has_bias (bool) – Specifies whether the layer uses a bias vector. Default: False.

  • activation (str, Cell) – A regularization function applied to the output of the layer. The type of activation can be a string (eg. ‘relu’) or a Cell (eg. nn.ReLU()). Note that if the type of activation is Cell, it must be instantiated beforehand. Default: None.

  • weight_prior_fn – The prior distribution for weight. It must return a mindspore distribution instance. Default: NormalPrior. (which creates an instance of standard normal distribution). The current version only supports normal distribution.

  • weight_posterior_fn – The posterior distribution for sampling weight. It must be a function handle which returns a mindspore distribution instance. Default: lambda name, shape: NormalPosterior(name=name, shape=shape). The current version only supports normal distribution.

  • bias_prior_fn – The prior distribution for bias vector. It must return a mindspore distribution. Default: NormalPrior(which creates an instance of standard normal distribution). The current version only supports normal distribution.

  • bias_posterior_fn – The posterior distribution for sampling bias vector. It must be a function handle which returns a mindspore distribution instance. Default: lambda name, shape: NormalPosterior(name=name, shape=shape). The current version only supports normal distribution.

Inputs:
  • input (Tensor) - The shape of the tensor is (N,in_channels).

Outputs:

Tensor, the shape of the tensor is (N,out_channels).

Supported Platforms:

Ascend GPU

Examples

>>> net = DenseLocalReparam(3, 4)
>>> input = Tensor(np.random.randint(0, 255, [2, 3]), mindspore.float32)
>>> output = net(input).shape
>>> print(output)
(2, 4)