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.ops.PReLU.rst 2.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. mindspore.ops.PReLU
  2. ===================
  3. .. py:class:: mindspore.ops.PReLU(*args, **kwargs)
  4. 带参数的线性修正单元激活函数(Parametric Rectified Linear Unit activation function)。
  5. `Delving Deep into Rectifiers:Surpassing Human-Level Performance on ImageNet Classification <https://arxiv.org/abs/1502.01852>`_ 描述了PReLU激活函数。定义如下:
  6. .. math::
  7. prelu(x_i)= \max(0, x_i) + \min(0, w * x_i),
  8. 其中 :math:`x_i` 是输入的一个通道的一个元素,`w` 是通道权重。
  9. .. note::
  10. Ascend不支持0-D或1-D的x。
  11. **输入:**
  12. - **x** (Tensor) - 用于计算激活函数的Tensor。数据类型为float16或float32。shape为 :math:`(N, C, *)` ,其中 :math:`*` 表示任意的附加维度数。
  13. - **weight** (Tensor) - 权重Tensor。数据类型为float16或float32。只有两种shape是合法的,1或 `input_x` 的通道数。通道维度是输入的第二维。当输入为0-D或1-D Tensor时,通道数为1。
  14. **输出:**
  15. Tensor,数据类型与 `x` 的相同。
  16. 有关详细信息,请参考:class:`nn.PReLU`。
  17. **异常:**
  18. - **TypeError** - `x` 或 `weight` 的数据类型既不是float16也不是float32。
  19. - **TypeError** - `x` 或 `weight` 不是Tensor。
  20. - **ValueError** - `x` 是Ascend上的0-D或1-D Tensor。
  21. - **ValueError** - `weight` 不是1-D Tensor。
  22. **支持平台:**
  23. ``Ascend`` ``GPU``
  24. **样例:**
  25. >>> class Net(nn.Cell):
  26. ... def __init__(self):
  27. ... super(Net, self).__init__()
  28. ... self.prelu = ops.PReLU()
  29. ... def construct(self, x, weight):
  30. ... result = self.prelu(x, weight)
  31. ... return result
  32. ...
  33. >>> x = Tensor(np.arange(-6, 6).reshape((2, 3, 2)), mindspore.float32)
  34. >>> weight = Tensor(np.array([0.1, 0.6, -0.3]), mindspore.float32)
  35. >>> net = Net()
  36. >>> output = net(x, weight)
  37. >>> print(output)
  38. [[[-0.60 -0.50]
  39. [-2.40 -1.80]
  40. [ 0.60 0.30]]
  41. [[ 0.00 1.00]
  42. [ 2.00 3.00]
  43. [ 4.0 5.00]]]