Skip to content

Commit 14584b3

Browse files
authored
Merge pull request #215 from ZDisket/multiband-pwgan
🎧 Add Multi-Band MelGAN with ParallelWaveGAN discriminator (no master commits)
2 parents 4ae9582 + 9de58b8 commit 14584b3

File tree

7 files changed

+956
-0
lines changed

7 files changed

+956
-0
lines changed

examples/multiband_pwgan/README.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Multi-band MelGAN: Faster Waveform Generation for High-Quality Text-to-Speech (With ParallelWaveGAN discriminator)
2+
Based on the script [`train_multiband_pwgan.py`](https://github.com/tensorspeech/TensorflowTTS/tree/master/examples/multiband_pwgan/train_multiband_pwgan.py).
3+
4+
## Training Multi-band MelGAN with PWGAN generator from scratch with LJSpeech dataset.
5+
This example code show you how to train MelGAN from scratch with Tensorflow 2 based on custom training loop and tf.function. The data used for this example is LJSpeech, you can download the dataset at [link](https://keithito.com/LJ-Speech-Dataset/).
6+
7+
### Step 1: Create Tensorflow based Dataloader (tf.dataset)
8+
Please see detail at [examples/melgan/](https://github.com/tensorspeech/TensorflowTTS/tree/master/examples/melgan#step-1-create-tensorflow-based-dataloader-tfdataset)
9+
10+
### Step 2: Training from scratch
11+
After you re-define your dataloader, pls modify an input arguments, train_dataset and valid_dataset from [`train_multiband_pwgan.py`](https://github.com/tensorspeech/TensorflowTTS/tree/master/examples/multiband_pwgan/train_multiband_pwgan.py). Here is an example command line to training melgan-stft from scratch:
12+
13+
First, you need training generator with only stft loss:
14+
15+
```bash
16+
CUDA_VISIBLE_DEVICES=0 python examples/multiband_pwgan/train_multiband_pwgan.py \
17+
--train-dir ./dump/train/ \
18+
--dev-dir ./dump/valid/ \
19+
--outdir ./examples/multiband_pwgan/exp/train.multiband_pwgan.v1/ \
20+
--config ./examples/multiband_pwgan/conf/multiband_pwgan.v1.yaml \
21+
--use-norm 1 \
22+
--generator_mixed_precision 1 \
23+
--resume ""
24+
```
25+
26+
Then resume and start training generator + discriminator:
27+
28+
```bash
29+
CUDA_VISIBLE_DEVICES=0 python examples/multiband_pwgan/train_multiband_pwgan.py \
30+
--train-dir ./dump/train/ \
31+
--dev-dir ./dump/valid/ \
32+
--outdir ./examples/multiband_pwgan/exp/train.multiband_pwgan.v1/ \
33+
--config ./examples/multiband_pwgan/conf/multiband_pwgan.v1.yaml \
34+
--use-norm 1 \
35+
--resume ./examples/multiband_pwgan/exp/train.multiband_pwgan.v1/checkpoints/ckpt-200000
36+
```
37+
38+
IF you want to use MultiGPU to training you can replace `CUDA_VISIBLE_DEVICES=0` by `CUDA_VISIBLE_DEVICES=0,1,2,3` for example. You also need to tune the `batch_size` for each GPU (in config file) by yourself to maximize the performance. Note that MultiGPU now support for Training but not yet support for Decode.
39+
40+
In case you want to resume the training progress, please following below example command line:
41+
42+
```bash
43+
--resume ./examples/multiband_pwgan/exp/train.multiband_pwgan.v1/checkpoints/ckpt-100000
44+
```
45+
46+
**IMPORTANT NOTES**:
47+
48+
- If Your Dataset is 16K, upsample_scales = [2, 4, 8] worked.
49+
- If Your Dataset is > 16K (22K, 24K, ...), upsample_scales = [2, 4, 8] didn't worked, used [8, 4, 2] instead.
50+
51+
### Step 3: Decode audio from folder mel-spectrogram
52+
To running inference on folder mel-spectrogram (eg valid folder), run below command line:
53+
54+
```bash
55+
CUDA_VISIBLE_DEVICES=0 python examples/multiband_pwgan/decode_mb_melgan.py \
56+
--rootdir ./dump/valid/ \
57+
--outdir ./prediction/multiband_melgan.v1/ \
58+
--checkpoint ./examples/multiband_pwgan/exp/train.multiband_pwgan.v1/checkpoints/generator-940000.h5 \
59+
--config ./examples/multiband_pwgan/conf/multiband_pwgan.v1.yaml \
60+
--batch-size 32 \
61+
--use-norm 1
62+
```
63+
64+
## Finetune Multi-Band MelGAN + PWGAN Disc with ljspeech pretrained on other languages
65+
Download generator weights of (any) Multi-Band MelGAN model, pass to `--pretrained` argument.
66+
It's recommended to use (and tune if necessary), the dedicated finetuning config `multiband_pwgan.v1ft.yaml`
67+
68+
```bash
69+
CUDA_VISIBLE_DEVICES=0 python examples/multiband_pwgan/train_multiband_pwgan.py \
70+
--train-dir ./dump/train/ \
71+
--dev-dir ./dump/valid/ \
72+
--outdir ./examples/multiband_pwgan/exp/train.multiband_pwgan.v1/ \
73+
--config ./examples/multiband_pwgan/conf/multiband_pwgan.v1ft.yaml \
74+
--use-norm 1 \
75+
--generator_mixed_precision 1 \
76+
--pretrained "ptgen.h5"
77+
```
78+
79+
## Notes
80+
1. Using RAdam for discriminator
81+
82+
## Reference
83+
84+
1. https://github.com/kan-bayashi/ParallelWaveGAN
85+
2. [Parallel WaveGAN: A fast waveform generation model based on generative adversarial networks with multi-resolution spectrogram](https://arxiv.org/abs/1910.11480)
86+
3. [Multi-band MelGAN: Faster Waveform Generation for High-Quality Text-to-Speech](https://arxiv.org/abs/2005.05106)
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
# This is the hyperparameter configuration file for Multi-Band MelGAN with PWGAN discriminator.
3+
# Please make sure this is adjusted for the LJSpeech dataset. If you want to
4+
# apply to the other dataset, you might need to carefully change some parameters.
5+
# This configuration performs 1000k iters.
6+
7+
###########################################################
8+
# FEATURE EXTRACTION SETTING #
9+
###########################################################
10+
sampling_rate: 22050
11+
hop_size: 256 # Hop size.
12+
format: "npy"
13+
14+
15+
###########################################################
16+
# GENERATOR NETWORK ARCHITECTURE SETTING #
17+
###########################################################
18+
model_type: "multiband_melgan_generator"
19+
20+
multiband_melgan_generator_params:
21+
out_channels: 4 # Number of output channels (number of subbands).
22+
kernel_size: 7 # Kernel size of initial and final conv layers.
23+
filters: 384 # Initial number of channels for conv layers.
24+
upsample_scales: [8, 4, 2] # List of Upsampling scales.
25+
stack_kernel_size: 3 # Kernel size of dilated conv layers in residual stack.
26+
stacks: 4 # Number of stacks in a single residual stack module.
27+
is_weight_norm: false # Use weight-norm or not.
28+
29+
###########################################################
30+
# DISCRIMINATOR NETWORK ARCHITECTURE SETTING #
31+
###########################################################
32+
parallel_wavegan_discriminator_params:
33+
out_channels: 1 # Number of output channels.
34+
kernel_size: 3 # Number of output channels.
35+
n_layers: 10 # Number of conv layers.
36+
conv_channels: 64 # Number of chnn layers.
37+
use_bias: true # Whether to use bias parameter in conv.
38+
nonlinear_activation: "LeakyReLU" # Nonlinear function after each conv.
39+
nonlinear_activation_params: # Nonlinear function parameters
40+
alpha: 0.2 # Alpha in LeakyReLU.
41+
42+
###########################################################
43+
# STFT LOSS SETTING #
44+
###########################################################
45+
stft_loss_params:
46+
fft_lengths: [1024, 2048, 512] # List of FFT size for STFT-based loss.
47+
frame_steps: [120, 240, 50] # List of hop size for STFT-based loss
48+
frame_lengths: [600, 1200, 240] # List of window length for STFT-based loss.
49+
50+
subband_stft_loss_params:
51+
fft_lengths: [384, 683, 171] # List of FFT size for STFT-based loss.
52+
frame_steps: [30, 60, 10] # List of hop size for STFT-based loss
53+
frame_lengths: [150, 300, 60] # List of window length for STFT-based loss.
54+
55+
###########################################################
56+
# ADVERSARIAL LOSS SETTING #
57+
###########################################################
58+
lambda_feat_match: 10.0 # Loss balancing coefficient for feature matching loss
59+
lambda_adv: 2.5 # Loss balancing coefficient for adversarial loss.
60+
61+
###########################################################
62+
# DATA LOADER SETTING #
63+
###########################################################
64+
batch_size: 64 # Batch size.
65+
batch_max_steps: 8192 # Length of each audio in batch for training. Make sure dividable by hop_size.
66+
batch_max_steps_valid: 81920 # Length of each audio for validation. Make sure dividable by hope_size.
67+
remove_short_samples: true # Whether to remove samples the length of which are less than batch_max_steps.
68+
allow_cache: true # Whether to allow cache in dataset. If true, it requires cpu memory.
69+
is_shuffle: true # shuffle dataset after each epoch.
70+
71+
###########################################################
72+
# OPTIMIZER & SCHEDULER SETTING #
73+
###########################################################
74+
generator_optimizer_params:
75+
lr_fn: "PiecewiseConstantDecay"
76+
lr_params:
77+
boundaries: [100000, 200000, 300000, 400000, 500000, 600000, 700000]
78+
values: [0.0005, 0.0005, 0.00025, 0.000125, 0.0000625, 0.00003125, 0.000015625, 0.000001]
79+
amsgrad: false
80+
81+
discriminator_optimizer_params:
82+
lr_fn: "ExponentialDecay"
83+
lr_params:
84+
initial_learning_rate: 0.0005
85+
decay_steps: 200000
86+
decay_rate: 0.5
87+
88+
89+
###########################################################
90+
# INTERVAL SETTING #
91+
###########################################################
92+
discriminator_train_start_steps: 200000 # steps begin training discriminator
93+
train_max_steps: 4000000 # Number of training steps.
94+
save_interval_steps: 20000 # Interval steps to save checkpoint.
95+
eval_interval_steps: 5000 # Interval steps to evaluate the network.
96+
log_interval_steps: 200 # Interval steps to record the training log.
97+
98+
###########################################################
99+
# OTHER SETTING #
100+
###########################################################
101+
num_save_intermediate_results: 1 # Number of batch to be saved as intermediate results.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
# This is the hyperparameter configuration file for Multi-Band MelGAN with PWGAN discriminator.
3+
# This one is adjusted for finetuning, used to finetune the LJSpeech pretrained Multi-Band MelGAN generator on a 50-minute male speaker dataset
4+
# You may have to tune this for your own
5+
6+
# Main differences from regular training config are:
7+
# 1. We start training the discriminator from the start
8+
# 2. The learning rate is very low
9+
# 3. Max iterations, save intervals, and associates are lowered because this gets done very quickly
10+
11+
###########################################################
12+
# FEATURE EXTRACTION SETTING #
13+
###########################################################
14+
sampling_rate: 22050
15+
hop_size: 256 # Hop size.
16+
format: "npy"
17+
18+
19+
###########################################################
20+
# GENERATOR NETWORK ARCHITECTURE SETTING #
21+
###########################################################
22+
model_type: "multiband_melgan_generator"
23+
24+
multiband_melgan_generator_params:
25+
out_channels: 4 # Number of output channels (number of subbands).
26+
kernel_size: 7 # Kernel size of initial and final conv layers.
27+
filters: 384 # Initial number of channels for conv layers.
28+
upsample_scales: [8, 4, 2] # List of Upsampling scales.
29+
stack_kernel_size: 3 # Kernel size of dilated conv layers in residual stack.
30+
stacks: 4 # Number of stacks in a single residual stack module.
31+
is_weight_norm: false # Use weight-norm or not.
32+
33+
###########################################################
34+
# DISCRIMINATOR NETWORK ARCHITECTURE SETTING #
35+
###########################################################
36+
parallel_wavegan_discriminator_params:
37+
out_channels: 1 # Number of output channels.
38+
kernel_size: 3 # Number of output channels.
39+
n_layers: 10 # Number of conv layers.
40+
conv_channels: 64 # Number of chnn layers.
41+
use_bias: true # Whether to use bias parameter in conv.
42+
nonlinear_activation: "LeakyReLU" # Nonlinear function after each conv.
43+
nonlinear_activation_params: # Nonlinear function parameters
44+
alpha: 0.2 # Alpha in LeakyReLU.
45+
46+
###########################################################
47+
# STFT LOSS SETTING #
48+
###########################################################
49+
stft_loss_params:
50+
fft_lengths: [1024, 2048, 512] # List of FFT size for STFT-based loss.
51+
frame_steps: [120, 240, 50] # List of hop size for STFT-based loss
52+
frame_lengths: [600, 1200, 240] # List of window length for STFT-based loss.
53+
54+
subband_stft_loss_params:
55+
fft_lengths: [384, 683, 171] # List of FFT size for STFT-based loss.
56+
frame_steps: [30, 60, 10] # List of hop size for STFT-based loss
57+
frame_lengths: [150, 300, 60] # List of window length for STFT-based loss.
58+
59+
###########################################################
60+
# ADVERSARIAL LOSS SETTING #
61+
###########################################################
62+
lambda_feat_match: 10.0 # Loss balancing coefficient for feature matching loss
63+
lambda_adv: 2.5 # Loss balancing coefficient for adversarial loss.
64+
65+
###########################################################
66+
# DATA LOADER SETTING #
67+
###########################################################
68+
batch_size: 64 # Batch size.
69+
batch_max_steps: 8192 # Length of each audio in batch for training. Make sure dividable by hop_size.
70+
batch_max_steps_valid: 81920 # Length of each audio for validation. Make sure dividable by hope_size.
71+
remove_short_samples: true # Whether to remove samples the length of which are less than batch_max_steps.
72+
allow_cache: true # Whether to allow cache in dataset. If true, it requires cpu memory.
73+
is_shuffle: true # shuffle dataset after each epoch.
74+
75+
###########################################################
76+
# OPTIMIZER & SCHEDULER SETTING #
77+
###########################################################
78+
generator_optimizer_params:
79+
lr_fn: "PiecewiseConstantDecay"
80+
lr_params:
81+
boundaries: [1000, 5000, 10000, 20000]
82+
values: [0.00000000001, 0.000000000005, 0.000000000002, 0.0000000000005, 0.0000000000002]
83+
amsgrad: false
84+
85+
86+
discriminator_optimizer_params:
87+
lr_fn: "ExponentialDecay"
88+
lr_params:
89+
initial_learning_rate: 0.0000000005
90+
decay_steps: 70000
91+
decay_rate: 0.5
92+
93+
###########################################################
94+
# INTERVAL SETTING #
95+
###########################################################
96+
discriminator_train_start_steps: 0 # steps begin training discriminator
97+
train_max_steps: 10000 # Number of training steps.
98+
save_interval_steps: 1500 # Interval steps to save checkpoint.
99+
eval_interval_steps: 500 # Interval steps to evaluate the network.
100+
log_interval_steps: 100 # Interval steps to record the training log.
101+
102+
###########################################################
103+
# OTHER SETTING #
104+
###########################################################
105+
num_save_intermediate_results: 1 # Number of batch to be saved as intermediate results.

0 commit comments

Comments
 (0)