def test_aggregation(): batch_size = 128 img_size = 10 num_out = 3 m = Model('test model cpu') l_in = m.add_layer(layers.InputLayer(shape=(batch_size,img_size)), name="l_in") l_out_mean = m.add_layer(layers.DenseLayer(l_in, num_out), name="l_out_mean") l_out_sum = m.add_layer(layers.DenseLayer(l_in, num_out), name="l_out_sum") m.bind_input(l_in, "pixels") m.bind_output(l_out_mean, lasagne.objectives.squared_error, "emotions", "label", "mean") m.bind_output(l_out_sum, lasagne.objectives.squared_error, "emotions", "label", "sum") from pprint import pprint pprint(m.to_dict()) global_update_settings = ParamUpdateSettings(update=lasagne.updates.nesterov_momentum,learning_rate=0.1, momentum=0.5) trainer = Trainer(m, global_update_settings) pixels = np.random.rand(batch_size,img_size).astype(theano.config.floatX) emotions = np.random.rand(batch_size,num_out).astype(theano.config.floatX) batch_dict = dict( # learning_rate_default=0.1, # momentum_default=0.5, pixels=pixels, emotions=emotions, exmotions=emotions.copy() ) outs = trainer.train_step(batch_dict) print "Aggregation test succeeded"
def _build_lr_net(batch_size, in_size, out_size): np.random.seed(100) m = Model() l_in = m.add_layer(InputLayer(shape=(batch_size,in_size))) l_out = m.add_layer(DenseLayer(l_in, out_size, nonlinearity=softmax)) m.bind_input(l_in, "inputs") m.bind_output(l_out, squared_error, "labels", "label", "mean") return m, l_in, l_out
def _build_lr_net(batch_size, in_size, out_size): np.random.seed(100) m = Model() l_in = m.add_layer(InputLayer(shape=(batch_size, in_size))) l_out = m.add_layer(DenseLayer(l_in, out_size, nonlinearity=softmax)) m.bind_input(l_in, "inputs") m.bind_output(l_out, squared_error, "labels", "label", "mean") return m, l_in, l_out
def test_build_model(): m = Model("test model") l_in = m.add_layer(xnn.layers.InputLayer(shape=(10, 200)), name="l_in") l_h1 = m.add_layer(xnn.layers.DenseLayer(l_in, 100), name="l_h1") l_out = m.add_layer(xnn.layers.DenseLayer(l_h1, 200), name="l_out") m.bind_input(l_in, "pixels") m.bind_output(l_h1, xnn.objectives.categorical_crossentropy, "emotions", "label", "mean") m.bind_output(l_out, xnn.objectives.squared_error, "l_in", "recon", "mean")
def test_build_model(): m = Model('test model') l_in = m.add_layer(xnn.layers.InputLayer(shape=(10, 200)), name="l_in") l_h1 = m.add_layer(xnn.layers.DenseLayer(l_in, 100), name="l_h1") l_out = m.add_layer(xnn.layers.DenseLayer(l_h1, 200), name="l_out") m.bind_input(l_in, "pixels") m.bind_output(l_h1, xnn.objectives.categorical_crossentropy, "emotions", "label", "mean") m.bind_output(l_out, xnn.objectives.squared_error, "l_in", "recon", "mean")
def _build_model(batch_size,img_size,num_hid): m = Model('test model cpu') l_in = m.add_layer(layers.InputLayer(shape=(batch_size,img_size)), name="l_in") l_loc = m.add_layer(layers.LocalLayer(l_in,num_units=3,img_shape=(2,5),local_filters=[(2,1)])) l_h1 = m.add_layer(layers.DenseLayer(l_loc, num_hid), name="l_h1") l_out = m.add_layer(layers.DenseLayer(l_h1, img_size), name="l_out") m.bind_input(l_in, "pixels") m.bind_output(l_h1, xnn.objectives.kl_divergence, "emotions", "label", "mean") m.bind_output(l_out, xnn.objectives.squared_error, "l_in", "recon", "mean") return m
def _build_model(batch_size, img_size, num_hid): m = Model('test model cpu') l_in = m.add_layer(layers.InputLayer(shape=(batch_size, img_size)), name="l_in") l_loc = m.add_layer( layers.LocalLayer(l_in, num_units=3, img_shape=(2, 5), local_filters=[(2, 1)])) l_h1 = m.add_layer(layers.DenseLayer(l_loc, num_hid), name="l_h1") l_out = m.add_layer(layers.DenseLayer(l_h1, img_size), name="l_out") m.bind_input(l_in, "pixels") m.bind_output(l_h1, xnn.objectives.kl_divergence, "emotions", "label", "mean") m.bind_output(l_out, xnn.objectives.squared_error, "l_in", "recon", "mean") return m
def test_aggregation(): batch_size = 128 img_size = 10 num_out = 3 m = Model('test model cpu') l_in = m.add_layer(layers.InputLayer(shape=(batch_size, img_size)), name="l_in") l_out_mean = m.add_layer(layers.DenseLayer(l_in, num_out), name="l_out_mean") l_out_sum = m.add_layer(layers.DenseLayer(l_in, num_out), name="l_out_sum") m.bind_input(l_in, "pixels") m.bind_output(l_out_mean, lasagne.objectives.squared_error, "emotions", "label", "mean") m.bind_output(l_out_sum, lasagne.objectives.squared_error, "emotions", "label", "sum") from pprint import pprint pprint(m.to_dict()) global_update_settings = ParamUpdateSettings( update=lasagne.updates.nesterov_momentum, learning_rate=0.1, momentum=0.5) trainer = Trainer(m, global_update_settings) pixels = np.random.rand(batch_size, img_size).astype(theano.config.floatX) emotions = np.random.rand(batch_size, num_out).astype(theano.config.floatX) batch_dict = dict( # learning_rate_default=0.1, # momentum_default=0.5, pixels=pixels, emotions=emotions, exmotions=emotions.copy()) outs = trainer.train_step(batch_dict) print "Aggregation test succeeded"