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=normal_post_fn, bias_prior_fn=NormalPrior, bias_posterior_fn=normal_post_fn)[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:
where
is the activation function passed as the activation argument (if passed in), is a weight matrix with the same data type as the inputs created by the layer, is a weight matrix sampling from posterior distribution of weight, and 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 .- 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: normal_post_fn. 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: normal_post_fn. The current version only supports normal distribution.
- Inputs:
input (Tensor) - The shape of the tensor is
.
- Outputs:
Tensor, the shape of the tensor is
.- 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)