Theano での maxout 実装の唯一の例は、このリンクにあります。私の理解では、アクティベーション関数を使用し、maxout は非表示レイヤー出力の後処理にすぎません。
これを自分のHiddenLayer
クラスに適用しようとしました。以下は、maxout の前のクラスです。
class HiddenLayer(object):
def __init__(self, rng, input, n_in, n_out, W=None, b=None, activation=T.tanh):
'''
Initialise the Hidden Layer
Parameters:
rng - random number generator
input - input values from the preceding layer
n_in - number of input nodes (number of nodes of the preceding layer)
n_out - number of output nodes (number of nodes of this hidden layer)
W - the Weights of the layer
b - the bias of the layer
activation - the activation function: T.tanh(), relu()
'''
self.input = input
W, b = self.init_weights(rng, n_in, n_out, W, b, activation) # initialise the wrights of a hidden layer
self.W = W; self.b = b;
lin_output = T.dot(input, self.W) + self.b
self.output = (lin_output if activation is None else activation(lin_output))
# parameters of the model
self.params = [self.W, self.b]
リンクを正しく理解していれば、maxout 実装後のクラスは次のようになります。これは正しいです?そうでない場合、私が誤解した部分を指摘していただけますか?
class HiddenLayer(object):
def __init__(self, rng, input, n_in, n_out, W=None, b=None, activation=T.tanh, maxout=False):
'''
maxout - whether to apply maxout after the activation function
'''
self.input = input
W, b = self.init_weights(rng, n_in, n_out, W, b, activation) # initialise the wrights of a hidden layer
self.W = W; self.b = b;
lin_output = T.dot(input, self.W) + self.b
self.output = (lin_output if activation is None else activation(lin_output))
if maxout: #apply maxout to the 'activated' hidden layer output
maxout_out = None
maxoutsize = n_out
for i in xrange(maxoutsize):
t = self.output[:,i::maxoutsize]
if maxout_out is None:
maxout_out = t
else:
maxout_out = T.maximum(maxout_out, t)
self.output = maxout_out
# parameters of the model
self.params = [self.W, self.b]