mindspore.mint.nn.Linear
- class mindspore.mint.nn.Linear(in_features, out_features, bias=True, weight_init=None, bias_init=None, dtype=None)[source]
The linear connected layer.
Applies linear connected layer for the input. This layer implements the operation as:
\[\text{outputs} = X * kernel + bias\]Warning
On the Ascend platform, if bias is
False, the x cannot be greater than 6D in PYNATIVE or KBK mode.where \(X\) is the input tensors, \(\text{kernel}\) is a weight matrix with the same data type as the \(X\) created by the layer, and \(\text{bias}\) is a bias vector with the same data type as the \(X\) created by the layer (only if the parameter bias is True).
Warning
In PyNative mode, if bias is
False, the x cannot be greater than 6D.- Parameters
in_features (int) – The number of features in the input space.
out_features (int) – The number of features in the output space.
bias (bool, optional) – Specify whether the layer use a bias vector \(\text{bias}\). Default:
True.weight_init (Union[Tensor, str, Initializer, numbers.Number], optional) – The trainable weight_init parameter. The dtype is same as x. The values of str refer to the function
mindspore.common.initializer.initializer(). Default:None, weight will be initialized using HeUniform.bias_init (Union[Tensor, str, Initializer, numbers.Number], optional) – The trainable bias_init parameter. The dtype is same as x. The values of str refer to the function
mindspore.common.initializer.initializer(). Default:None, bias will be initialized using Uniform.dtype (
mindspore.dtype, optional) – Data type of parameter. Default:None.
- Inputs:
x (Tensor) - Tensor of shape \((*, in\_features)\).
- Outputs:
Tensor of shape \((*, out\_features)\).
- Supported Platforms:
Ascend
Examples
>>> import mindspore >>> x = mindspore.tensor([[180, 234, 154], [244, 48, 247]], mindspore.float32) >>> net = mindspore.mint.nn.Linear(3, 4) >>> output = net(x) >>> print(output.shape) (2, 4)