Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve dataset statistics for sourcefolder dataset #33

Closed
faroit opened this issue Mar 10, 2020 · 4 comments
Closed

Improve dataset statistics for sourcefolder dataset #33

faroit opened this issue Mar 10, 2020 · 4 comments
Assignees

Comments

@faroit
Copy link
Member

faroit commented Mar 10, 2020

🐛 Dataset Statistics do not work for sourcefolder dataset

The get_statistics function was designed to iterate over the complete audio data in an deterministic manner, therefore loading the full audio samples. This doesn't work together with the sourcefolder dataset as it allows to have different length of files as it get short chunks of fixed lengths from each item.

Expected behavior

sourcefolder dataset should work with get_statistics

Proposed solutions

Solution 1

replace dataset_scaler.seq_duration = None with dataset_scaler.seq_duration = args.seq_dur. That would solve the issue but then would only train the dataset statistics on the first n seconds from each sample.

Solution 2

use stochastic sampling and use a dataloader instead of a dataset: e.g.:

def get_statistics(args, dataloader):
    scaler = sklearn.preprocessing.StandardScaler()

    spec = torch.nn.Sequential(
        model.STFT(n_fft=args.nfft, n_hop=args.nhop),
        model.Spectrogram(mono=True)
    )

    pbar = tqdm.tqdm(dataloader, disable=args.quiet)
    for x, y in pbar:
        pbar.set_description("Compute dataset statistics")
        X = spec(x)
        scaler.partial_fit(np.squeeze(X))

    std = np.maximum(
        scaler.scale_,
        1e-4*np.max(scaler.scale_)
    )
    return scaler.mean_, std

stats_sampler = torch.utils.data.DataLoader(
    train_dataset, batch_size=1,
    sampler=sampler, **dataloader_kwargs
)

the second option would get better distributed samples and users can maybe specify an argument that selects the number of samples randomly drawn to train the dataset statistics

@faroit
Copy link
Member Author

faroit commented Mar 10, 2020

ping @TE-StefanUhlich

@StefanUhlich-sony
Copy link

I think I would go for the first solution and additionally set the following:

if isinstance(dataset_scaler, SourceFolderDataset):
    dataset_scaler.random_chunks = True
    dataset_scaler.split = 'valid'

Then we extract random chunks (random start positions) and it would still be deterministic because we use the dataset in valid mode.

@faroit
Copy link
Member Author

faroit commented Jul 22, 2020

@TE-StefanUhlich coming back to this:

Then we extract random chunks (random start positions) and it would still be deterministic because we use the dataset in valid mode.

that would work, but then we will use the validation set instead of the training set. Maybe we introduce a deterministic flag for all dataloaders instead of making this depend on valid vs. train?

@StefanUhlich-sony
Copy link

Yes, this is better - then this feature is more visible to the user and we can also use it for the training set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants