ang*_*nko 8 python neural-network theano conv-neural-network keras
我正在使用Keras和Theano作为后端,我有顺序神经网络模型.
我想知道以下是否有区别?
model.add(Convolution2D(32, 3, 3, activation='relu'))
Run Code Online (Sandbox Code Playgroud)
和
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
Run Code Online (Sandbox Code Playgroud)
它们基本相同.单独放置它的好处是你可以BatchNormalization在其间添加其他层(比方说).
在Keras中,如果未指定,Convolution2D默认情况下将使用"线性"激活,这只是标识功能
def linear(x):
'''
The function returns the variable that is passed in, so all types work.
'''
return x
Run Code Online (Sandbox Code Playgroud)
并且该Activation层所做的就是将激活函数应用于输入
def call(self, x, mask=None):
return self.activation(x)
Run Code Online (Sandbox Code Playgroud)
编辑:
因此
Convolution2D(activation = 'relu')在执行卷积后基本上应用relu激活函数,这与应用Activation('relu')之后相同Convolution2D(32, 3, 3)
图层call功能的最后两行Convolution2D是
output = self.activation(output)
return output
Run Code Online (Sandbox Code Playgroud)
output卷积的输出在哪里.所以我们知道应用激活函数是最后一步Convolution2D.
源代码:
Convolution2Dlayer:https
Activation://github.com/fchollet/keras/blob/a981a8c42c316831183cac7598266d577a1ea96a/keras/layers/convolutional.py layer:https://github.com/fchollet/keras/blob/a981a8c42c316831183cac7598266d577a1ea96a/keras/layers/ core.py
激活函数:https://github.com/fchollet/keras/blob/master/keras/activations.py