當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python mxnet.symbol.Activation用法及代碼示例

用法:

mxnet.symbol.Activation(data=None, act_type=_Null, name=None, attr=None, out=None, **kwargs)

參數

  • data(Symbol) - 輸入數組。
  • act_type({'relu', 'sigmoid', 'softrelu', 'softsign', 'tanh'}, required) - 要應用的激活函數。
  • name(string, optional.) - 結果符號的名稱。

返回

結果符號。

返回類型

Symbol

將激活函數逐元素應用於輸入。

支持以下激活函數:

  • relu:整流線性單元,
  • sigmoid
  • tanh:雙曲正切,
  • softrelu:Soft ReLU,或 SoftPlus,
  • softsign

例子

帶有ReLU 激活的one-hidden-layer MLP:

>>> data = Variable('data')
>>> mlp = FullyConnected(data=data, num_hidden=128, name='proj')
>>> mlp = Activation(data=mlp, act_type='relu', name='activation')
>>> mlp = FullyConnected(data=mlp, num_hidden=10, name='mlp')
>>> mlp
<Symbol mlp>

ReLU 激活

>>> test_suites = [
... ('relu', lambda x: np.maximum(x, 0)),
... ('sigmoid', lambda x: 1 / (1 + np.exp(-x))),
... ('tanh', lambda x: np.tanh(x)),
... ('softrelu', lambda x: np.log(1 + np.exp(x)))
... ]
>>> x = test_utils.random_arrays((2, 3, 4))
>>> for act_type, numpy_impl in test_suites:
... op = Activation(act_type=act_type, name='act')
... y = test_utils.simple_forward(op, act_data=x)
... y_np = numpy_impl(x)
... print('%s: %s' % (act_type, test_utils.almost_equal(y, y_np)))
relu: True
sigmoid: True
tanh: True
softrelu: True

相關用法


注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 mxnet.symbol.Activation。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。