コード例 #1
0
    def load(self, checkpoint_path, hparams, model_name='WaveNet'):
        log('Constructing model: {}'.format(model_name))
        self._hparams = hparams
        local_cond, global_cond = self._check_conditions()

        self.local_conditions = tf.placeholder(
            tf.float32,
            shape=[1, None, hparams.num_mels],
            name='local_condition_features') if local_cond else None
        self.global_conditions = tf.placeholder(
            tf.int32, shape=(),
            name='global_condition_features') if global_cond else None
        self.synthesis_length = tf.placeholder(
            tf.int32, shape=(),
            name='synthesis_length') if not local_cond else None

        with tf.variable_scope('model') as scope:
            self.model = create_model(model_name, hparams)
            self.model.initialize(y=None,
                                  c=self.local_conditions,
                                  g=self.global_conditions,
                                  input_lengths=None,
                                  synthesis_length=self.synthesis_length)

            self._hparams = hparams
            sh_saver = create_shadow_saver(self.model)

            log('Loading checkpoint: {}'.format(checkpoint_path))
            self.session = tf.Session()
            self.session.run(tf.global_variables_initializer())
            load_averaged_model(self.session, sh_saver, checkpoint_path)
コード例 #2
0
def model_test_mode(args, feeder, hparams, global_step):
	with tf.variable_scope('model', reuse=tf.AUTO_REUSE) as scope:
		model_name = 'WaveNet'
		model = create_model(model_name, hparams)
		#initialize model to test mode
		model.initialize(feeder.eval_targets, feeder.eval_local_condition_features, feeder.eval_global_condition_features,
			feeder.eval_input_lengths)
		model.add_loss()
		return model
コード例 #3
0
def model_train_mode(args, feeder, hparams, global_step):
	with tf.variable_scope('model', reuse=tf.AUTO_REUSE) as scope:
		model_name = 'WaveNet'
		model = create_model(model_name, hparams)
		#initialize model to train mode
		model.initialize(feeder.targets, feeder.local_condition_features, feeder.global_condition_features,
			feeder.input_lengths, x=feeder.inputs)
		model.add_loss()
		model.add_optimizer(global_step)
		stats = add_train_stats(model)
		return model, stats
コード例 #4
0
ファイル: train.py プロジェクト: duvtedudug/Tacotron-2
def model_test_mode(args, feeder, hparams, global_step):
	with tf.variable_scope('model', reuse=tf.AUTO_REUSE) as scope:
		model_name = None
		if args.model in ('Tacotron-2', 'Both'):
			model_name = 'WaveNet'
		model = create_model(model_name or args.model, hparams)
		#initialize model to test mode
		model.initialize(feeder.eval_targets, feeder.eval_local_condition_features, feeder.eval_global_condition_features,
			feeder.eval_input_lengths)
		model.add_loss()
		return model
コード例 #5
0
ファイル: train.py プロジェクト: duvtedudug/Tacotron-2
def model_train_mode(args, feeder, hparams, global_step):
	with tf.variable_scope('model', reuse=tf.AUTO_REUSE) as scope:
		model_name = None
		if args.model in ('Tacotron-2', 'Both'):
			model_name = 'WaveNet'
		model = create_model(model_name or args.model, hparams)
		#initialize model to train mode
		model.initialize(feeder.targets, feeder.local_condition_features, feeder.global_condition_features,
			feeder.input_lengths, x=feeder.inputs)
		model.add_loss()
		model.add_optimizer(global_step)
		stats = add_train_stats(model)
		return model, stats
コード例 #6
0
    def load(self, checkpoint_path, hparams, model_name='WaveNet'):
        print('Constructing model: {}'.format(model_name))
        log('Constructing model: {}'.format(model_name))
        self._hparams = hparams
        local_cond, global_cond = self._check_conditions()

        self.local_conditions = tf.placeholder(
            tf.float32,
            shape=(None, None, hparams.num_mels),
            name='local_condition_features') if local_cond else None
        self.global_conditions = tf.placeholder(
            tf.int32, shape=(None, 1),
            name='global_condition_features') if global_cond else None
        self.synthesis_length = tf.placeholder(
            tf.int32, shape=(),
            name='synthesis_length') if not local_cond else None
        self.targets = tf.placeholder(
            tf.float32, shape=(1, None, 1), name='audio_targets'
        ) if hparams.wavenet_synth_debug else None  #Debug only with 1 wav
        self.input_lengths = tf.placeholder(
            tf.int32, shape=(1, ),
            name='input_lengths') if hparams.wavenet_synth_debug else None
        self.synth_debug = hparams.wavenet_synth_debug

        with tf.variable_scope('WaveNet_model') as scope:
            self.model = create_model(model_name, hparams)
            self.model.initialize(y=None,
                                  c=self.local_conditions,
                                  g=self.global_conditions,
                                  input_lengths=self.input_lengths,
                                  synthesis_length=self.synthesis_length,
                                  test_inputs=self.targets)

            self._hparams = hparams
            sh_saver = create_shadow_saver(self.model)

            print('Loading checkpoint: {}'.format(checkpoint_path))
            log('Loading checkpoint: {}'.format(checkpoint_path))
            #Memory allocation on the GPU as needed
            config = tf.ConfigProto()
            config.gpu_options.allow_growth = True
            config.allow_soft_placement = True

            self.session = tf.Session(config=config)
            self.session.run(tf.global_variables_initializer())

        load_averaged_model(self.session, sh_saver, checkpoint_path)