elif args.dataset == 'binary_mnist': d = dataset.MNIST(binary=True) elif args.dataset == 'mnist': d = dataset.MNIST() elif args.dataset in ['omniglot', 'omni']: d = dataset.Omniglot() elif args.dataset == 'dsprites': d = dataset.DSprites() elif args.dataset == "cifar10" or args.dataset == 'cifar': d = dataset.Cifar10() if args.per_label is not None: d.shrink_supervised(args.per_label) m = model.NoiseModel(d, config=config, filename=args.filename, verbose=args.verbose) m.lagrangian_fit = args.fit_tf if args.noise is not None: if args.noise == 'multiplicative': m.layers[0]['layer_kwargs']['multiplicative'] = True if args.noise == 'additive': m.layers[0]['layer_kwargs']['multiplicative'] = False if args.beta is not None: for loss in m.losses: if not isinstance( loss, dict): # reconstruction is a Loss object, so will be skipped continue if 'mmd' in loss['type']:
import importlib import model import dataset import layers import loss_args import losses from keras.layers import Dense, Input import argparse import tensorflow as tf parser = argparse.ArgumentParser() parser.add_argument('--config', type=str, default='test_config.json') d = dataset.MNIST(binary=True) #i = Input(shape = (d.x_train.shape[-1],)) #l = Dense(10)(i) #print(l, callable(l)) #l = Dense(10) #l = l(i) #print(l, callable(l)) mi_inits = [1, 2] for i in range(len(mi_inits)): mi_init = mi_inits[i] with tf.name_scope(str("run_" + str(i))): m = model.NoiseModel(d, config='test_config.json', filename=str('mi_' + str(round(mi_init, 2)))) m.layers[0]['layer_kwargs']['init'] = mi_init m.fit(d.x_train)
else: args.filename = args.filename + (str( args.count) if args.count is not None else '') + '_beta_' + str( args.beta if args.beta is not None else 1) + '_tc_' + str( args.tc_weight if args.tc_weight is not None else 0) + ( '_remove_' + str(args.remove_prob) if 'corr' in args.dataset else 'full') args.filename = os.path.join(args.folder, args.filename) print("FILENAME ", args.filename) dd = copy.copy(d) m = model.NoiseModel(dd, config=config, filename=args.filename, verbose=args.verbose, seed=args.seed) ep = m.epochs if args.epochs is None else args.epochs try: ep = ep * epoch_mult except: pass m.epochs = 0 m.fit(dd.x_train, verbose=args.verbose, validate=args.validate, fit_gen=args.fit_gen, epochs=0)