mindspore.ops.Dense
- class mindspore.ops.Dense[源代码]
全连接融合算子。
适用于输入的密集连接算子。算子的实现如下:
其中
是输入Tensor, 是一个权重矩阵,其数据类型与 相同, 是一个偏置向量,其数据类型与 相同(仅当 b 不为None
时)。- 输入:
x (Tensor) - 输入Tensor。shape必须满足:
。w (Tensor) - 权重Tensor。shape必须满足: 若
,则 。若 ,则 。 。b (Union[Tensor, None]) - 偏置Tensor。当 b 不为
None
时,shape必须满足: 若 ,则 或 。若 , 则 。若 ,则 。
- 输出:
若
,则输出shape为 的Tensor。若 ,则输出shape为 的Tensor。- 支持平台:
Ascend
GPU
CPU
样例:
>>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.random.random((4, 5, 6, 7)).astype(np.float32)) >>> weight = Tensor(np.random.random((6, 7)).astype(np.float32)) >>> bias = Tensor(np.random.random((6,)).astype(np.float32)) >>> dense = ops.Dense() >>> output = dense(x, weight, bias) >>> print(output.shape) (4, 5, 6, 6)