def GetOutput( self, input, switch_map ): """ params : input : input image usually with one batch ( batch_size, channel, weight,height) type : input : numpy.ndarray params :switch_map: map that stores the exact location of max value ( see max_pool.max_uppool_2d()) type :switch_map: numpy.ndarray params :activation: activation function type :activation: function """ input = self.activation( input ) if( input.shape[1] == 1 ): input = input.reshape( input.shape[2:4] ) else: input = input.reshape( input.shape[1:4] ) up_pooled_out = max_uppool_2d( input, switch_map, poolsize = self.poolsize ) if( up_pooled_out.ndim == 2 ): up_pooled_out = up_pooled_out.reshape( [1,1] + list(up_pooled_out.shape)) else: up_pooled_out = up_pooled_out.reshape( [1] + list(up_pooled_out.shape)) if up_pooled_out.dtype == theano.config.floatX: conv_out = self.conv( up_pooled_out ) else: conv_out = self.conv( up_pooled_out.astype(theano.config.floatX) ) output = conv_out#self.activation( conv_out ) return np.asarray(output, dtype = theano.config.floatX )
def test_max_uppool(self): input = np.asarray([[[0, 1], [2, 3]], [[4, -1], [5, 1]]]) switch_map = np.asarray([[[0, 0], [0, 0]], [[3, 0], [3, 0]]]) desired_output = np.asarray([[[0, 0, 1, 0], [0, 0, 0, 0], [2, 0, 3, 0], [0, 0, 0, 0]], [[0, 0, -1, 0], [0, 4, 0, 0], [0, 0, 1, 0], [0, 5, 0, 0]]]) poolsize = 2 assert (desired_output == max_uppool_2d(input, switch_map, poolsize)).all()
def test_max_uppool( self ): input = np.asarray( [ [ [0,1], [2,3]], [ [4,-1], [5,1] ] ] ) switch_map = np.asarray( [ [ [0,0], [0,0]], [ [3,0], [3,0] ] ] ) desired_output = np.asarray([[[0,0,1,0], [0,0,0,0], [2,0,3,0], [0,0,0,0]], [[0,0,-1,0], [0,4,0,0], [0,0,1,0], [0,5,0,0]]]) poolsize = 2; assert ( desired_output == max_uppool_2d( input, switch_map, poolsize ) ).all()