def test_compose(input, idx, axis): t = transforms.Compose( [transforms.Crop(idx, axis=axis), transforms.Normalize(axis=axis)]) expected_output = F.crop(input, idx, axis=axis) expected_output = F.normalize(expected_output, axis=axis) assert np.array_equal(t(input), expected_output)
def test_stft(input, window_size, hop_size, axis): expected_output = input samples = input.shape[axis] spectrogram = F.stft(input, window_size, hop_size, axis=axis) magnitude, phase = librosa.magphase(spectrogram) output = F.istft(spectrogram, window_size, hop_size, axis=axis) output = F.crop(output, (0, samples), axis=axis) np.testing.assert_almost_equal(output, expected_output, decimal=6)
def test_expand(input, size, axis, method): t = transforms.Expand(size=size, axis=axis, method=method) if method == 'pad': assert np.array_equal(t(input), F.pad( input, (0, size - input.shape[axis]), axis=axis)) else: assert np.array_equal(t(input), F.crop(F.replicate( input, repetitions=size // input.shape[axis] + 1, axis=axis), (0, size), axis=axis))
def test_crop(input, idx, axis, expected_output): output = F.crop(input, idx, axis=axis) assert np.array_equal(output, expected_output)
def test_randomcrop(input, size, axis): t = transforms.RandomCrop(size, axis=axis) t.fix_randomization = True assert np.array_equal(t(input), t(input)) assert np.array_equal(t(input), F.crop(input, t.idx, axis=t.axis))