def runNoiseTests(self, params):
    """
    Test the model with different noise values and return test metrics.
    """
    if self.use_preprocessed_dataset:
      raise NotImplementedError("Noise tests requires raw data")

    ret = {}
    testDataDir = os.path.join(self.dataDir, "test")
    n_mels = 32

    # Test with noise
    total_correct = 0

    for noise in [0.0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5]:

      # Create noise dataset with noise transform
      noiseTransform = transforms.Compose([
        FixAudioLength(),
        AddNoise(noise),
        ToSTFT(),
        ToMelSpectrogramFromSTFT(n_mels=n_mels),
        DeleteSTFT(),
        ToTensor('mel_spectrogram', 'input')
      ])

      noiseDataset = SpeechCommandsDataset(
        testDataDir,
        noiseTransform,
        silence_percentage=0,
      )

      noise_loader = DataLoader(noiseDataset,
                                 batch_size=params["batch_size"],
                                 sampler=None,
                                 shuffle=False,
                                 pin_memory=self.use_cuda,
                                 )

      testResult = self.test(params, noise_loader)
      total_correct += testResult["num_correct"]
      ret[noise]= testResult

    ret["totalCorrect"] = total_correct
    ret["testerror"] = ret[0.0]["testerror"]
    ret["entropy"] = ret[0.0]["entropy"]

    if "nonzeros" in ret[0.0]:
      ret["nonzeros"] = ret[0.0]["nonzeros"]

    return ret
def runNoiseTests ( self , params ) : if self . use_preprocessed_dataset : raise NotImplementedError ( "Noise tests requires raw data" ) ret = { } testDataDir = os . path . join ( self . dataDir , "test" ) n_mels = 32 total_correct = 0 for noise in [ 0.0 , 0.05 , 0.1 , 0.15 , 0.2 , 0.25 , 0.3 , 0.35 , 0.4 , 0.45 , 0.5 ] : noiseTransform = transforms . Compose ( [ FixAudioLength ( ) , AddNoise ( noise ) , ToSTFT ( ) , ToMelSpectrogramFromSTFT ( n_mels = n_mels ) , DeleteSTFT ( ) , ToTensor ( 'mel_spectrogram' , 'input' ) ] ) noiseDataset = SpeechCommandsDataset ( testDataDir , noiseTransform , silence_percentage = 0 , ) noise_loader = DataLoader ( noiseDataset , batch_size = params [ "batch_size" ] , sampler = None , shuffle = False , pin_memory = self . use_cuda , ) testResult = self . test ( params , noise_loader ) total_correct += testResult [ "num_correct" ] ret [ noise ] = testResult ret [ "totalCorrect" ] = total_correct ret [ "testerror" ] = ret [ 0.0 ] [ "testerror" ] ret [ "entropy" ] = ret [ 0.0 ] [ "entropy" ] if "nonzeros" in ret [ 0.0 ] : ret [ "nonzeros" ] = ret [ 0.0 ] [ "nonzeros" ] return ret
Test the model with different noise values and return test metrics.