Exemple #1
0
    def test_no_change_source(self):
        data = AudioLoader.load_mel_spectrogram(self.sample_wav_file, n_mels=128)
        aug = nas.LoudnessAug(stateless=False)
        aug_data = aug.augment(data)

        comparison = data == aug_data
        self.assertFalse(comparison.all())
Exemple #2
0
    def test_spectrogram(self):
        mel_spectrogram = AudioLoader.load_mel_spectrogram(
            self.sample_wav_file, n_mels=128)

        flow = naf.Sequential([
            nas.FrequencyMaskingAug(stateless=False),
            nas.TimeMaskingAug(stateless=False),
            nas.TimeMaskingAug(stateless=False)
        ])

        augmented_mel_spectrogram = flow.augment(mel_spectrogram)

        for aug in flow:
            if aug.name == 'FrequencyMasking_Aug':
                aug_data = augmented_mel_spectrogram[
                    aug.f0:aug.f0 + aug.f, aug.time_start:aug.time_end]
                orig_data = mel_spectrogram[aug.f0:aug.f0 + aug.f,
                                            aug.time_start:aug.time_end]

                self.assertEqual(orig_data.size, np.count_nonzero(orig_data))
                self.assertEqual(0, np.count_nonzero(aug_data))
            elif aug.name == 'TimeMasking_Aug':
                self.assertEqual(len(mel_spectrogram[:, aug.t0]),
                                 np.count_nonzero(mel_spectrogram[:, aug.t0]))
                self.assertEqual(
                    0, np.count_nonzero(augmented_mel_spectrogram[:, aug.t0]))
            else:
                raise ValueError('Unexpected flow for {} augmenter'.format(
                    aug.name))

        self.assertTrue(len(flow) > 0)
    def test_no_change_source(self):
        data = AudioLoader.load_mel_spectrogram(self.sample_wav_file,
                                                n_mels=128)
        aug = nas.FrequencyMaskingAug()
        aug_data = aug.augment(data)

        comparison = data == aug_data
        self.assertFalse(comparison.all())
Exemple #4
0
    def test_substitute(self):
        data = AudioLoader.load_mel_spectrogram(self.sample_wav_file, n_mels=128)
        aug = nas.LoudnessAug(stateless=False)

        aug_data = aug.augment(data)
        comparison = data[:, aug.time_start:aug.time_end] == aug_data[:, aug.time_start:aug.time_end]
        self.assertFalse(comparison.all())
        comparison = data[:, :aug.time_start] == aug_data[:, :aug.time_start]
        self.assertTrue(comparison.all())
        comparison = data[:, aug.time_end:] == aug_data[:, aug.time_end:]
        self.assertTrue(comparison.all())
Exemple #5
0
    def test_multi_thread(self):
        mel_spectrogram = AudioLoader.load_mel_spectrogram(self.sample_wav_file, n_mels=128)
        n = 3
        augs = [
            nas.FrequencyMaskingAug(mask_factor=80),
            nas.TimeMaskingAug(mask_factor=80)
        ]

        for num_thread in [1, 3]:
            for aug in augs:
                augmented_data = aug.augment(mel_spectrogram, n=n, num_thread=num_thread)
                self.assertEqual(len(augmented_data), n)
    def test_substitute(self):
        time_mask_para = 80

        mel_spectrogram = AudioLoader.load_mel_spectrogram(
            self.sample_wav_file, n_mels=self.num_of_freq_channel)
        aug = TimeMaskingAug(mask_factor=time_mask_para)

        augmented_mel_spectrogram = aug.augment(mel_spectrogram)

        self.assertEqual(len(mel_spectrogram[:, aug.model.t0]),
                         np.count_nonzero(mel_spectrogram[:, aug.model.t0]))
        self.assertEqual(
            0, np.count_nonzero(augmented_mel_spectrogram[:, aug.model.t0]))
Exemple #7
0
    def test_substitute(self):
        freq_mask_para = 80

        mel_spectrogram = AudioLoader.load_mel_spectrogram(
            self.sample_wav_file, n_mels=128)
        aug = FrequencyMaskingAug(mask_factor=freq_mask_para)

        augmented_mel_spectrogram = aug.augment(mel_spectrogram)

        self.assertEqual(len(mel_spectrogram[aug.model.f0]),
                         np.count_nonzero(mel_spectrogram[aug.model.f0]))
        self.assertEqual(
            0, np.count_nonzero(augmented_mel_spectrogram[aug.model.f0]))
    def test_substitute(self):
        data = AudioLoader.load_mel_spectrogram(self.sample_wav_file,
                                                n_mels=128)
        aug = nas.FrequencyMaskingAug(stateless=False)

        aug_data = aug.augment(data)

        self.assertEqual(len(data[aug.f0]), np.count_nonzero(data[aug.f0]))
        self.assertEqual(
            0, np.count_nonzero(aug_data[aug.f0][aug.time_start:aug.time_end]))
        self.assertEqual(
            0, len(np.where(aug_data[aug.f0][:aug.time_start] == 0)[0]))
        self.assertEqual(
            0, len(np.where(aug_data[aug.f0][aug.time_end:] == 0)[0]))
Exemple #9
0
    def test_spectrogram(self):
        # https://freewavesamples.com/yamaha-v50-rock-beat-120-bpm
        sample_wav_file = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', '..', 'data',
                         'Yamaha-V50-Rock-Beat-120bpm.wav'))

        mel_spectrogram = AudioLoader.load_mel_spectrogram(sample_wav_file,
                                                           n_mels=128)

        flow = naf.Sequential([
            nas.FrequencyMaskingAug(mask_factor=50),
            nas.TimeMaskingAug(mask_factor=20),
            nas.TimeMaskingAug(mask_factor=30)
        ])

        augmented_mel_spectrogram = flow.augment(mel_spectrogram)

        for aug in flow:
            if aug.name == 'FrequencyMasking_Aug':
                self.assertEqual(
                    len(mel_spectrogram[aug.model.f0]),
                    np.count_nonzero(mel_spectrogram[aug.model.f0]))
                self.assertEqual(
                    0,
                    np.count_nonzero(augmented_mel_spectrogram[aug.model.f0]))
            elif aug.name == 'TimeMasking_Aug':
                self.assertEqual(
                    len(mel_spectrogram[:, aug.model.t0]),
                    np.count_nonzero(mel_spectrogram[:, aug.model.t0]))
                self.assertEqual(
                    0,
                    np.count_nonzero(augmented_mel_spectrogram[:,
                                                               aug.model.t0]))
            else:
                # Unexpected flow
                self.assertFalse(True)

        self.assertTrue(len(flow) > 0)