1

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]
4

0 回答 0