在Theano中实施Maxout激活

时间:2016-03-01 08:34:45

标签: theano deep-learning activation-function

Theano中maxout实现的唯一例子是link。我的理解是我使用任何激活函数,然后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]

如果我正确理解link,则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]

0 个答案:

没有答案
相关问题