Exemplo n.º 1
0
 def test_compose(self):
     wav = np.array([1, 3])
     assert torch.allclose(
         transforms.Compose([
             transforms.ZeroMean(),
             transforms.ToTensor(),
         ])(wav), torch.tensor([[-1, 1]], dtype=torch.float))
Exemplo n.º 2
0
from torch.nn import CrossEntropyLoss
from torch.utils.data import DataLoader
from torch.utils.data import random_split

import yews.datasets as dsets
import yews.transforms as transforms
from yews.models import Cpic
from yews.train import Trainer


if __name__ == '__main__':
    # Preprocessing
    waveform_transform = transforms.Compose([
        transforms.ZeroMean(),
        transforms.SoftClip(1e-4),
        transforms.ToTensor(),
    ])

    # Prepare dataset
    dset = dsets.Wenchuan(path='.', download=True,
                          sample_transform=waveform_transform)

    # Split datasets into training and validation
    train_length = int(len(dset) * 0.8)
    val_length = len(dset) - train_length
    train_set, val_set = random_split(dset, [train_length, val_length])

    # Prepare dataloaders
    train_loader = DataLoader(train_set, batch_size=100, shuffle=True, num_workers=4)
    val_loader = DataLoader(val_set, batch_size=1000, shuffle=False, num_workers=8)
Exemplo n.º 3
0
 def test_zero_mean_channel_mean(self):
     wav = np.random.rand(3, 2000)
     assert all([np.allclose(ch.mean(), 0) for ch in transforms.ZeroMean()(wav)])