def __init__(self, **kwargs): """ Initializes geometric mean layer parameters. Parameters ---------- : dict like object Contains hyperparameters """ # Set parameter dictionary self.__params = dd() self.__params.encoder_weights = None if 'import_path' in kwargs: for param in self.__params.values: fn = os.path.join(kwargs.import_path, "{}.npy".format(str(param))) param.set_value(np.load(fn)) print 'Loading parameter {} from file with shape {}'.format(str(param), param.get_value().shape) # Hyperparameters self.hp = dd(kwargs) # Parameter not to be optimized init = binomial(1, self.hp.selection_prob, size=(self.hp.nb_out, self.hp.nb_out)).astype(th.config.floatX) init /= np.sqrt((init**2).sum(0)) self.encoder_selection = th.shared(init, name='encoder_selection') # Format layer_id self.layer_id = '_' + str(self.hp.layer_id) if 'layer_id' in self.hp else '' self.output_debug = False
def __init__(self, hp, layer_id=''): """ Initializes maxout parameters. Parameters ---------- hp dict like object Contains hyperparameters .nb_inp = number of layer inputs .nb_max = number of inputs per maxout units .nb_out = number of maxout units .inp_corruption_level .inp_corruption_type .hid_corruption_level .hid_corruption_type """ # Format layer_id self.layer_id = '_' + str(layer_id) # Hyperparameters self.hp = hp # Set parameter dictionary self.__params = [('encoder_weights', None)] self.__params = dd(self.__params)
def __init__(self, hp, layer_id=''): """ Initializes geometric mean layer parameters. Parameters ---------- hp: dict like object Contains hyperparameters .nb_inp = number of layer inputs .nb_geo = number of elements per geometric mean .nb_out = number of output units .inp_corruption_level .inp_corruption_type .hid_corruption_level .hid_corruption_type .debug_path .patch_sz = input patch size (if coming from image), for debug purpose """ self.output_debug = False # Format layer_id self.layer_id = '_' + str(layer_id) # Hyperparameters self.hp = hp # Set parameter dictionary self.__params = dd() self.__params.encoder_weights = None self.__params.selection_biases = None self.__params.selection_factor = None
""" for param in self.__params.values: fn = os.path.join(path, "{}.npy".format(str(param))) param.set_value(np.load(fn)) print 'Loading parameter {} from file with shape {}'.format( str(param), param.get_value().shape) if __name__ == '__main__': # For testing the maxout model x = T.matrix('tensor2', dtype=th.config.floatX) hp = dd() hp.nb_inp = 5 hp.nb_max = 3 hp.nb_out = 7 hp.inp_corruption_level = 0 hp.inp_corruption_type = None hp.hid_corruption_level = 0 hp.hid_corruption_type = None params = maxout_params(hp) layer = maxout(x, params) h = layer.enc(x) d = layer.dec(h) c = layer.cost(d, x) enc_fn = th.function(inputs=[x], outputs=h) dec_fn = th.function(inputs=[x], outputs=d)
make_dir(join(debug_path, 'histograms')) self.__pca_weights = pca_weights self.__patch_sz = patch_sz self.__debug_path = debug_path self.__prefix = '' if prefix == None else prefix self.output_debug = True if __name__ == '__main__': from learn.utils.activation import relu, sigmoid, linear # For testing the maxout model x = T.matrix('tensor2', dtype=th.config.floatX) hp = dd() hp.nb_inp = 5 hp.nb_geo = 3 hp.nb_out = 7 hp.inp_corruption_level = 0 hp.inp_corruption_type = None hp.hid_corruption_level = 0 hp.hid_corruption_type = None hp = dd() hp.type = 'geometric' hp.nb_inp = 25 hp.nb_geo = 3 hp.nb_out = 7 hp.variant = 'product' hp.inp_act = relu if hp.variant == 'product' else linear