mindspore.nn.DenseThor
- class mindspore.nn.DenseThor(in_channels, out_channels, weight_init='normal', bias_init='zeros', has_bias=True, activation=None)[source]
The dense connected layer and saving the information needed for THOR.
Applies dense connected layer for the input and saves the information A and G in the dense connected layer needed for THOR, the detail can be seen in paper: https://www.aaai.org/AAAI21Papers/AAAI-6611.ChenM.pdf This layer implements the operation as:
\[\text{outputs} = \text{activation}(\text{inputs} * \text{kernel} + \text{bias}),\]where \(\text{activation}\) is the activation function , \(\text{kernel}\) is a weight matrix with the same data type as the inputs created by the layer, and \(\text{bias}\) is a bias vector with the same data type as the inputs created by the layer (only if has_bias is True).
- Parameters
in_channels (int) – The number of the input channels.
out_channels (int) – The number of the output channels.
weight_init (Union[Tensor, str, Initializer, numbers.Number]) – The trainable weight_init parameter. The dtype is same as x. The values of str refer to the function initializer. Default: ‘normal’.
bias_init (Union[Tensor, str, Initializer, numbers.Number]) – The trainable bias_init parameter. The dtype is same as x. The values of str refer to the function initializer. Default: ‘zeros’.
has_bias (bool) – Specifies whether the layer uses a bias vector. Default: True.
activation (str) – activate function applied to the output of the fully connected layer, eg. ‘ReLU’. Default: None.
- Inputs:
x (Tensor) - Tensor of shape \((N, in\_channels)\).
- Outputs:
Tensor of shape \((N, out\_channels)\).
- Raises
ValueError – If the shape of weight_init or bias_init is incorrect.
- Supported Platforms:
Ascend
GPU
Examples
>>> x = Tensor(np.array([[1, 2, 3], [3, 4, 5]]), mindspore.float32) >>> net = nn.DenseThor(3, 4, weight_init="ones") >>> output = net(x) >>> print(output) [[ 6. 6. 6. 6.] [ 12. 12. 12. 12. ]]