Ejemplo n.º 1
0
paths = sorted([
    str(path) for path in pathlib.Path(args.dataset).glob('wav48/*/*.wav')])
preprocess = Preprocess(
    sr=16000, n_fft=1024, hop_length=256, n_mels=128, top_db=20,
    length=args.length, quantize=args.a_channels)
dataset = chainer.datasets.TransformDataset(paths, preprocess)
train, valid = chainer.datasets.split_dataset_random(
    dataset, int(len(dataset) * 0.9), args.seed)

# Networks
encoder = UpsampleNet(args.n_loop * args.n_layer, args.r_channels)
decoder = WaveNet(
    args.n_loop, args.n_layer,
    args.a_channels, args.r_channels, args.s_channels,
    args.use_embed_tanh)
model = chainer.links.Classifier(EncoderDecoderModel(encoder, decoder))

# Optimizer
optimizer = chainer.optimizers.Adam(1e-4)
optimizer.setup(model)

# Iterators
train_iter = chainer.iterators.MultiprocessIterator(
    train, args.batchsize,
    n_processes=args.process, n_prefetch=args.prefetch)
valid_iter = chainer.iterators.MultiprocessIterator(
    valid, args.batchsize, repeat=False, shuffle=False,
    n_processes=args.process, n_prefetch=args.prefetch)

# Updater and Trainer
updater = chainer.training.StandardUpdater(
Ejemplo n.º 2
0
decoder = WaveNet(params.n_loop, params.n_layer, params.filter_size,
                  params.residual_channels, params.dilated_channels,
                  params.skip_channels, params.output_dim, params.quantize,
                  params.log_scale_min, params.condition_dim,
                  params.dropout_zero_rate)

if params.distribution_type == 'gaussian':
    loss_fun = decoder.calculate_gaussian_loss
    acc_fun = None
elif params.distribution_type == 'logistic':
    loss_fun = decoder.calculate_logistic_loss
    acc_fun = None
elif params.distribution_type == 'softmax':
    loss_fun = chainer.functions.softmax_cross_entropy
    acc_fun = chainer.functions.accuracy
model = EncoderDecoderModel(encoder, decoder, loss_fun, acc_fun)

# Optimizer
optimizer = chainer.optimizers.Adam(params.lr / len(args.gpus))
optimizer.setup(model)
optimizer.add_hook(chainer.optimizer.GradientClipping(10))

# Iterator
if args.process * args.prefetch > 1:
    train_iter = chainer.iterators.MultiprocessIterator(
        train,
        params.batchsize,
        n_processes=args.process,
        n_prefetch=args.prefetch)
    valid_iter = chainer.iterators.MultiprocessIterator(
        valid,