def flow(self): self.ori_embed = speaker_embedding(self.ori_spk, hp.SPK_NUM, hp.EMBED_SIZE, reuse=False) # [N, 1] -> [N, E] self.aim_embed = speaker_embedding(self.aim_spk, hp.SPK_NUM, hp.EMBED_SIZE, reuse=True) # [N, 1] -> [N, E] with tf.variable_scope(self.model_name, reuse=tf.AUTO_REUSE): self.ori_out, self.ori_mu, self.ori_log_var = generator( self.ori_embed, self.ori_feat, is_training=self.is_training, reuse=False, scope_name='generator') self.aim_out, self.aim_mu, self.aim_log_var = generator( self.aim_embed, self.ori_feat, is_training=self.is_training, reuse=True, scope_name='generator') self.cycle_ori_out, self.cycle_mu, self.cycle_log_var = generator( self.ori_embed, self.aim_out, is_training=self.is_training, reuse=True, scope_name='generator') self.predict_real_P = discriminator(self.aim_feat, reuse=False, scope_name='discriminator') self.predict_fake_P = discriminator(self.aim_out, reuse=True, scope_name='discriminator')
def _create_GANs(self): """ 创建生成器、判别器相应符号 :return: """ self.fakeA = generator(self.realB_ph, False, name='Gb2a') self.fakeB = generator(self.realA_ph, False, name='Ga2b') self.cycA = generator(self.fakeB, True, name='Gb2a') self.cycB = generator(self.fakeA, True, name='Ga2b') self.Da_fake = discriminator(self.fakeA, False, name='Da') self.Db_fake = discriminator(self.fakeB, False, name='Db') self.Da_real = discriminator(self.realA_ph, True, name='Da') self.Db_real = discriminator(self.realB_ph, True, name='Db') self.Da_fake_sample = discriminator(self.fakeA_ph, True, name='Da') self.Db_fake_sample = discriminator(self.fakeB_ph, True, name='Db')
def inference(self): self.ori_mel = tf.placeholder(name='ori_mel', shape=[None, None, hp.CODED_DIM], dtype=tf.float32) # self.aim_spk = tf.placeholder(name='aim_spk', shape=[None, None], dtype=tf.int64) ### self.flow() # self.aim_embed = speaker_embedding(self.aim_spk, hp.SPK_NUM, hp.EMBED_SIZE) # [N, 1] -> [N, E] with tf.variable_scope(self.model_name, reuse=tf.AUTO_REUSE): self.aim_out, self.aim_mu, self.aim_log_var = generator(self.ori_mel, is_training=self.is_training, scope_name='generator')
def __init__(self, **kwargs): # hyperparams self.__dict__.update(self.default_hyperparams) self.__dict__.update(kwargs) # deserialize some hyperparams for k in ('image_shape', 'tf_config_proto'): self.__dict__[k] = json.loads(self.__dict__[k]) assert isinstance(self.image_shape, list) and len(self.image_shape)==3 self.tf_config = tf.ConfigProto(**self.tf_config_proto) # instantiate optimizers self.disc_optimizer = tf.train.AdamOptimizer(self.disc_learning_rate) self.gen_optimizer = tf.train.AdamOptimizer(self.gen_learning_rate) # instantiate models self.discriminator_A = modules.discriminator(input_shape=self.image_shape) self.discriminator_B = modules.discriminator(input_shape=self.image_shape) self.generator_A2B = modules.generator(input_shape=self.image_shape, n_resnet_blocks=self.generator_n_resnet_blocks) self.generator_B2A = modules.generator(input_shape=self.image_shape, n_resnet_blocks=self.generator_n_resnet_blocks) for model in (self.discriminator_A, self.discriminator_B, self.generator_A2B, self.generator_B2A): # 'sgd' and 'mse' are not actually used, just placeholders for compiling model.compile('sgd', 'mse')
def flow(self): # 不需要embeding了 # self.ori_embed = speaker_embedding(self.ori_spk, hp.SPK_NUM, hp.EMBED_SIZE, reuse=False) # [N, 1] -> [N, E] # self.aim_embed = speaker_embedding(self.aim_spk, hp.SPK_NUM, hp.EMBED_SIZE, reuse=True) # [N, 1] -> [N, E] with tf.variable_scope(self.model_name, reuse=tf.AUTO_REUSE): # self.ori_out, self.ori_mu, self.ori_log_var = generator(self.ori_mel, # is_training=self.is_training, # reuse=False, # scope_name='generator') # # 没有自己变自己的需求了 self.aim_out, self.aim_mu, self.aim_log_var = generator(self.ori_mel, is_training=self.is_training, reuse=tf.AUTO_REUSE, scope_name='generator')
def __init__(self, args, config): self.args = args model_name = config.get('config', 'experiment') task_channel = config.getint('task', 'channel') task_module_type = config.get('task', 'classifier_type') image_fc = config.getint('task', 'image_fc') measurement_fc = config.getint('task', 'measurement_fc') branch_fc = config.getint('task', 'branch_fc') self.source_only = config.getboolean('config', 'source_only') self.t2s_task = config.getboolean('config', 't2s_task') self.style_weights = config.getlist('discriminator', 'style_weights') self.share_all_image = config.getboolean('generator', 'share_all_image') if not self.source_only: discriminator_channel = config.getint('discriminator', 'channel') self.discriminator_dropout_prob = config.getfloat( 'discriminator', 'dropout_prob') self.patch = config.getboolean('discriminator', 'patch') self.generator_type = config.get('generator', 'type') generator_channel = config.getint('generator', 'channel') self.generator_out_channel = config.getint('generator', 'out_channel') self.generator = modules.generator(generator_channel, config, args) self.discriminator = modules.discriminator(discriminator_channel, group_size=1) # List of 4 branch modules self.task = modules.task(task_channel, image_fc, measurement_fc, branch_fc, self.args.training, classifier_type=task_module_type) self.summary = dict()
def __init__(self, args, config): self.args = args model_name = config.get('config', 'experiment') discriminator_channel = config.getint('discriminator', 'channel') generator_channel = config.getint('generator', 'channel') classifier_channel = config.getint('task', 'channel') self.generator_type = config.get('generator', 'type') self.generator_out_channel = config.getint('generator', 'out_channel') self.generator = modules.generator(generator_channel, config, self.args) self.discriminator = modules.discriminator(discriminator_channel, group_size=self.args.batch_size) self.patch = config.getboolean('discriminator', 'patch') self.discriminator_dropout_prob = config.getfloat('discriminator', 'dropout_prob') self.t2s_task = config.getboolean('config', 't2s_task') self.style_weights = config.getlist('discriminator', 'style_weights') self.transferred_classifier = modules.task_classifier(classifier_channel, num_classes=3, training=self.args.training) self.transferred_task_weight = config.getfloat(model_name, 'task_weight') self.t2s_task_weight = config.getfloat(model_name, 't2s_task_weight') self.summary = dict()