mindspore.mint.nn.Linear

View Source On AtomGit
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
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)