# p(a|x,y,z) - a ~ Gaussian p_a_yz = Sequential(weight_initializer=config.weight_initializer, weight_init_std=config.weight_init_std) p_a_yz.add( Merge(num_inputs=2, out_size=500, use_weightnorm=config.use_weightnorm)) p_a_yz.add(BatchNormalization(500)) p_a_yz.add(Activation(config.nonlinearity)) p_a_yz.add(Linear(None, 500, use_weightnorm=config.use_weightnorm)) p_a_yz.add(BatchNormalization(500)) p_a_yz.add(Activation(config.nonlinearity)) p_a_yz.add(Linear(None, 500, use_weightnorm=config.use_weightnorm)) p_a_yz.add(BatchNormalization(500)) p_a_yz.add(Activation(config.nonlinearity)) p_a_yz.add(Gaussian(None, config.ndim_a)) # outputs mean and ln(var) # q(z|a,x,y) - z ~ Gaussian q_z_axy = Sequential(weight_initializer=config.weight_initializer, weight_init_std=config.weight_init_std) q_z_axy.add( Merge(num_inputs=3, out_size=500, use_weightnorm=config.use_weightnorm)) q_z_axy.add(BatchNormalization(500)) q_z_axy.add(Activation(config.nonlinearity)) q_z_axy.add(Linear(None, 500, use_weightnorm=config.use_weightnorm)) q_z_axy.add(BatchNormalization(500)) q_z_axy.add(Activation(config.nonlinearity)) q_z_axy.add(Linear(None, 500, use_weightnorm=config.use_weightnorm)) q_z_axy.add(BatchNormalization(500)) q_z_axy.add(Activation(config.nonlinearity))
discriminator.add(Activation(config.nonlinearity)) discriminator.add(Linear(None, 1000)) discriminator.add(Activation(config.nonlinearity)) discriminator.add(Linear(None, 1000)) discriminator.add(Activation(config.nonlinearity)) discriminator.add(Linear(None, 2)) generator = Sequential(weight_initializer=config.weight_initializer, weight_init_std=config.weight_init_std) generator.add(Linear(config.ndim_x, 1000)) generator.add(Activation(config.nonlinearity)) generator.add(Linear(None, 1000)) generator.add(Activation(config.nonlinearity)) if config.distribution_z == "deterministic": generator.add(Linear(None, config.ndim_z)) elif config.distribution_z == "gaussian": generator.add(Gaussian(None, config.ndim_z)) # outputs mean and ln(var) else: raise Exception() params = { "config": config.to_dict(), "decoder": decoder.to_dict(), "generator": generator.to_dict(), "discriminator": discriminator.to_dict(), } with open(model_filename, "w") as f: json.dump(params, f, indent=4, sort_keys=True, separators=(',', ': ')) aae = AAE(params) aae.load(args.model_dir)