示例#1
0
    def test_batch_compute_deltas(self):
        specgram = torch.randn(2, 31, 2786)

        # Single then transform then batch
        expected = transforms.ComputeDeltas()(specgram).repeat(3, 1, 1, 1)

        # Batch then transform
        computed = transforms.ComputeDeltas()(specgram.repeat(3, 1, 1, 1))

        # shape = (3, 2, 201, 1394)
        self.assertTrue(computed.shape == expected.shape, (computed.shape, expected.shape))
        self.assertTrue(torch.allclose(computed, expected))
示例#2
0
 def test_compute_deltas_twochannel(self):
     specgram = torch.tensor([1., 2., 3., 4.]).repeat(1, 2, 1)
     expected = torch.tensor([[[0.5, 1.0, 1.0, 0.5],
                               [0.5, 1.0, 1.0, 0.5]]])
     transform = transforms.ComputeDeltas()
     computed = transform(specgram)
     self.assertTrue(computed.shape == specgram.shape, (computed.shape, specgram.shape))
示例#3
0
 def test_compute_deltas_twochannel(self):
     specgram = torch.tensor([1., 2., 3., 4.]).repeat(1, 2, 1)
     expected = torch.tensor([[[0.5, 1.0, 1.0, 0.5], [0.5, 1.0, 1.0, 0.5]]])
     transform = transforms.ComputeDeltas(win_length=3)
     computed = transform(specgram)
     assert computed.shape == expected.shape, (computed.shape,
                                               expected.shape)
     self.assertEqual(computed, expected, atol=1e-6, rtol=1e-8)
示例#4
0
 def test_compute_deltas(self):
     channel = 13
     n_mfcc = channel * 3
     time = 1021
     win_length = 2 * 7 + 1
     specgram = torch.randn(channel, n_mfcc, time)
     transform = transforms.ComputeDeltas(win_length=win_length)
     computed = transform(specgram)
     self.assertTrue(computed.shape == specgram.shape, (computed.shape, specgram.shape))
示例#5
0
    def test_compute_deltas_transform_same_as_functional(self, atol=1e-6, rtol=1e-8):
        channel = 13
        n_mfcc = channel * 3
        time = 1021
        win_length = 2 * 7 + 1
        specgram = torch.randn(channel, n_mfcc, time)

        transform = transforms.ComputeDeltas(win_length=win_length)
        computed_transform = transform(specgram)

        computed_functional = F.compute_deltas(specgram, win_length=win_length)
        torch.testing.assert_allclose(computed_functional, computed_transform, atol=atol, rtol=rtol)
示例#6
0
 def test_compute_deltas(self):
     transform = T.ComputeDeltas()
     spec = torch.rand(10, 20)
     self.assert_grad(transform, [spec])
示例#7
0
 def __init__(self, order=2, **kwargs):
     super(Delta, self).__init__()
     self.order = order
     self.compute_delta = transforms.ComputeDeltas(**kwargs)