在 Theano 中是否有使用线性修正单元 (ReLU) 作为隐藏层的激活函数而不是 tanh()
或 sigmoid()
的方法?隐藏层的实现如下,据我在网上搜索到ReLU没有在Theano内部实现。
class HiddenLayer(object):
def __init__(self, rng, input, n_in, n_out, W=None, b=None, activation=T.tanh):
pass
最佳答案
relu 在 Theano 中很容易做到:
switch(x<0, 0, x)
要在您的案例中使用它,请创建一个将实现 relu 并将其传递给激活的 python 函数:
def relu(x):
return theano.tensor.switch(x<0, 0, x)
HiddenLayer(..., activation=relu)
有些人使用这个实现:x * (x > 0)
更新:较新的 Theano 版本有可用的 theano.tensor.nnet.relu(x)。
关于python - Theano隐藏层激活函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26497564/