Esempio n. 1
0
    def GetOutput( self, input = input ):
        """
        params : input : input image usually with one batch ( batch_size, channel, weight,height)
        type : input : numpy.ndarray

        """
        if input.dtype == theano.config.floatX:
            conv_out = self.conv( input )
        else:
            conv_out = self.conv( input.astype(theano.config.floatX) )

        if( conv_out.shape[1] == 1 ):
          conv_out = conv_out.reshape( conv_out.shape[2:4] )
        else: 
          conv_out = conv_out.reshape( conv_out.shape[1:4] )

        pooled_out, switch_map = max_pool_2d( conv_out , poolsize = self.poolsize)

        if( pooled_out.ndim == 2 ):
          pooled_out = pooled_out.reshape( [1,1] + list(pooled_out.shape))
        else:
          pooled_out = pooled_out.reshape( [1] + list(pooled_out.shape))

        output = self.activation( pooled_out )

        return np.asarray(output, dtype = theano.config.floatX), switch_map
Esempio n. 2
0
 def test_max_pool(self):
     input = np.asarray([[[0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3],
                          [2, 2, 3, 3]],
                         [[1, 2, -1, -2], [3, 4, -3, -4], [0, 2, 1, 1],
                          [3, 5, 0, 1]]])
     desired_output = np.asarray([[[0, 1], [2, 3]], [[4, -1], [5, 1]]])
     desired_switch_map = np.asarray([[[0, 0], [0, 0]], [[3, 0], [3, 0]]])
     poolsize = 2
     actual_output, actual_switch_map = max_pool_2d(input, poolsize)
     assert (desired_output == actual_output).all()
     assert (desired_switch_map == actual_switch_map).all()
Esempio n. 3
0
 def test_max_pool( self ):
     input = np.asarray( [ [ [0,0,1,1],
                                 [0,0,1,1],
                                 [2,2,3,3],
                                 [2,2,3,3]],
                                 [ [1,2,-1,-2],
                                 [3,4,-3,-4],
                                 [0,2,1,1],
                                 [3,5,0,1] ] ] )
     desired_output = np.asarray( [ [ [0,1],
                                                 [2,3]],
                                                 [ [4,-1],
                                                 [5,1] ] ] )
     desired_switch_map = np.asarray( [ [ [0,0],
                                                     [0,0]],
                                                     [ [3,0],
                                                     [3,0] ] ] )
     poolsize = 2
     actual_output, actual_switch_map = max_pool_2d( input, poolsize )
     assert ( desired_output == actual_output ).all()
     assert ( desired_switch_map == actual_switch_map ).all()