python - Theano隐藏层激活函数

标签 python machine-learning neural-network theano

在 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/

相关文章:

python - 我在 beautifulsoup 中找不到 table

python selenium.webdriver 返回结果 'The requested document was not found on this server'

python - Pyramid unicorn 和女服务员

machine-learning - TensorFlow - 使用 L2 损失进行正则化,如何应用于所有权重,而不仅仅是最后一个权重?

python - 是否需要为他们定位的每个站点编写爬虫?

machine-learning - 分割和分类之间的区别

python-3.x - Scikit 学习 : Incorporate Naive Bayes Model Predictions into Logistic Regression?

machine-learning - Google Cloud 上使用 GPU 的 Tensorflow

python - 喀拉斯 LSTM : Error when checking model input dimension

python - 绘制神经网络的基本示例