def main(unused_args=None): ''' NOTE: The input is rescaled to [-1, 1] ''' #module = import_module(args.model_module, package=None) #MODEL = getattr(module, args.model) #print("=== ",MODEL,"") #module = import_module(args.trainer_module, package=None) #TRAINER = getattr(module, args.trainer) dirs = validate_log_dirs(args) try: os.makedirs(dirs['logdir']) except OSError as e: if e.errno != errno.EEXIST: raise with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(dirs['logdir'], args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/{}_xmax.npf'.format(args.corpus_name)), xmin=np.fromfile('./etc/{}_xmin.npf'.format(args.corpus_name)), ) s_x_y = read( file_pattern=arch['training']['src_dir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, data_format='NHWC', ) t_x_y = read( file_pattern=arch['training']['trg_dir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, data_format='NHWC', ) machine = Trainer() machine.load_data(s_x_y, t_x_y) machine.train()
def main(unused_args=None): ''' NOTE: The input is rescaled to [-1, 1] ''' module = import_module(args.model_module, package=None) MODEL = getattr(module, args.model) module = import_module(args.trainer_module, package=None) TRAINER = getattr(module, args.trainer) dirs = validate_log_dirs(args) tf.gfile.MakeDirs(dirs['logdir']) with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(dirs['logdir'], args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/{}_xmax.npf'.format(args.corpus_name)), xmin=np.fromfile('./etc/{}_xmin.npf'.format(args.corpus_name)), ) x_s, y_s, f0_s = read( file_pattern=arch['training']['src_dir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, data_format='NHWC', ) x_t, y_t, f0_t = read( file_pattern=arch['training']['trg_dir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, data_format='NHWC', ) machine = MODEL(arch, is_training=True) # y_s_new = tf.stack([y_s,f0_s],axis=1) # y_t_new = tf.stack([y_t,f0_t],axis=1) loss = machine.loss(x_s, y_s, f0_s, x_t, y_t, f0_t) trainer = TRAINER(loss, arch, args, dirs) trainer.train(nIter=arch['training']['max_iter'], machine=machine)
def test(): # ==== Test: batch mixer (conclusion: capacity should be larger to make sure good mixing) ==== x, y = read('./dataset/vcc2016/bin/*/*/1*001.bin', 32, min_after_dequeue=1024, capacity=2048) sv = tf.train.Supervisor() with sv.managed_session() as sess: for _ in range(200): x_, y_ = sess.run([x, y]) print(y_) # ===== Read binary ==== features = read_whole_features('./dataset/vcc2016/bin/Training Set/SF1/*001.bin') sv = tf.train.Supervisor() with sv.managed_session() as sess: features = sess.run(features) y = pw2wav(features) librosa.output.write_wav('test1.wav', y, 16000) # TODO fs should be specified externally. # ==== Direct read ===== f = './dataset/vcc2016/bin/Training Set/SF1/100001.bin' features = np.fromfile(f, np.float32) features = np.reshape(features, [-1, 513*2 + 1 + 1 + 1]) # f0, en, spk y = pw2wav(features) librosa.output.write_wav('test2.wav', y, 16000)
def main(): ''' NOTE: The input is rescaled to [-1, 1] ''' dirs = validate_log_dirs(args) tf.gfile.MakeDirs(dirs['logdir']) with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(dirs['logdir'], args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/xmax.npf'), xmin=np.fromfile('./etc/xmin.npf'), ) image, label = read( file_pattern=arch['training']['datadir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, ) machine = MODEL(arch) loss = machine.loss(image, label) trainer = TRAINER(loss, arch, args, dirs) trainer.train(nIter=arch['training']['max_iter'], machine=machine)
def main(): ''' NOTE: The input is rescaled to [-1, 1] ''' dirs = validate_log_dirs(args) if args.restore_from is None: tf.gfile.MakeDirs(dirs['logdir']) with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/xmax.npf'), xmin=np.fromfile('./etc/xmin.npf'), ) image, label = read( file_pattern=arch['training']['datadir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, ) #image format NHWC print "image shape:",image print "label shape:",label machine = MODEL(arch, args, True, False) loss = machine.loss(image, label, True) #sample = machine.sample()#np.asarray([SPEAKERS.index(args.trg)])) # sample, trainer = TRAINER(loss, arch, args, dirs) trainer.train(nIter=arch['training']['max_iter'], n_unroll=arch['training']['n_unroll'], machine=machine)
def main(): ''' NOTE: The input is rescaled to [-1, 1] ''' dirs = validate_log_dirs(args) tf.gfile.MakeDirs(dirs['logdir']) with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(dirs['logdir'], args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/xmax.npf'), xmin=np.fromfile('./etc/xmin.npf'), ) image, label = read( file_pattern=arch['training']['datadir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, ) machine = MODEL(arch) loss = machine.loss(image, label) trainer = TRAINER(loss, arch, args, dirs) trainer.train(nIter=arch['training']['max_iter'], machine=machine)
def main(): """ NOTE: The input is rescaled to [-1, 1] """ dirs = validate_log_dirs(args) tf.gfile.MakeDirs(dirs['logdir']) # dirs = dict() # dirs['logdir'] = '.' with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(dirs['logdir'], args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/xmax.npf'), xmin=np.fromfile('./etc/xmin.npf'), ) machine = MODEL(arch) if args.model in ['VAWGAN_I']: image, label, i_vec = read_i_all( file_pattern=arch['training']['datadir'], file_pattern2=arch['training']['ivectordir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, ) # loss = machine.loss(image, label, text_emb) loss = machine.loss(image, label, i_vec) elif args.model in ['VAWGAN_S', 'SentWGAN']: image, label, text_emb = read_all( file_pattern=arch['training']['datadir'], file_pattern2=arch['training']['textdir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, ) loss = machine.loss(image, label, text_emb) else: image, label = read( file_pattern=arch['training']['datadir'], batch_size=arch['training']['batch_size'], capacity=2048, min_after_dequeue=1024, normalizer=normalizer, ) loss = machine.loss(image, label) trainer = TRAINER(loss, arch, args, dirs) trainer.train(nIter=arch['training']['max_iter'], machine=machine)
def main(unused_args): ''' NOTE: The input is rescaled to [-1, 1] ''' if args.model is None or args.trainer is None: raise ValueError( '\n Both `model` and `trainer` should be assigned.' +\ '\n Use `python main.py --help` to see applicable options.' ) module = import_module(args.model_module, package=None) MODEL = getattr(module, args.model) module = import_module(args.trainer_module, package=None) TRAINER = getattr(module, args.trainer) dirs = validate_log_dirs(args) tf.gfile.MakeDirs(dirs['logdir']) with open(args.architecture) as f: arch = json.load(f) with open(os.path.join(dirs['logdir'], args.architecture), 'w') as f: json.dump(arch, f, indent=4) normalizer = Tanhize( xmax=np.fromfile('./etc/xmax.npf'), xmin=np.fromfile('./etc/xmin.npf'), ) x, y = read( file_pattern=arch['training']['datadir'], batch_size=arch['training']['batch_size'], capacity=4096, min_after_dequeue=3000, normalizer=normalizer, ) machine = MODEL(arch, is_training=True) loss = machine.loss(x, y) trainer = TRAINER(loss, arch, args, dirs) trainer.train(nIter=arch['training']['max_iter'], machine=machine)