You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.nn.Dense.rst 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. mindspore.nn.Dense
  2. ===================
  3. .. py:class:: mindspore.nn.Dense(in_channels, out_channels, weight_init='normal', bias_init='zeros', has_bias=True, activation=None)
  4. 全连接层。
  5. 公式如下:
  6. .. math::
  7. \text{outputs} = \text{activation}(\text{X} * \text{kernel} + \text{bias}),
  8. 其中 :math:`X` 是输入Tensor, :math:`\text{activation}` 是激活函数, :math:`\text{kernel}` 是一个权重矩阵,其数据类型与 :math:`X` 相同, :math:`\text{bias}` 是一个偏置向量,其数据类型与 :math:`X` 相同(仅当has_bias为True时)。
  9. **参数:**
  10. - **in_channels** (int) - Dense层输入Tensor的空间维度。
  11. - **out_channels** (int) - Dense层输出Tensor的空间维度。
  12. - **weight_init** (Union[Tensor, str, Initializer, numbers.Number]) - 权重参数的初始化方法。数据类型与 `x` 相同。str的值引用自函数 `initializer`。默认值:'normal'。
  13. - **bias_init** (Union[Tensor, str, Initializer, numbers.Number]) - 偏置参数的初始化方法。数据类型与 `x` 相同。str的值引用自函数 `initializer`。默认值:'zeros'。
  14. - **has_bias** (bool) - 是否使用偏置向量 :math:`\text{bias}` 。默认值:True。
  15. - **activation** (Union[str, Cell, Primitive]) - 应用于全连接层输出的激活函数,例如‘ReLU’。默认值:None。
  16. **输入:**
  17. - **x** (Tensor) - shape为 :math:`(*,in\_channels)` 的Tensor。 参数中的 `in_channels` 应等于输入中的 :math:`in\_channels` 。
  18. **输出:**
  19. shape为 :math:`(*,out\_channels)` 的Tensor。
  20. **异常:**
  21. - **TypeError** - `in_channels` 或 `out_channels` 不是整数。
  22. - **TypeError** - `has_bias` 不是bool值。
  23. - **TypeError** - `activation` 不是str、Cell、Primitive或者None。
  24. - **ValueError** - `weight_init` 的shape长度不等于2,`weight_init` 的shape[0]不等于 `out_channels`,或者 `weight_init` 的shape[1]不等于 `in_channels`。
  25. - **ValueError** - `bias_init` 的shape长度不等于1或 `bias_init` 的shape[0]不等于 `out_channels`。