audio_zen/model/base_model.py
def forgetting_norm(input, sample_length=192):
        """
        Using the mean value of the near frames to normalization

        Args:
            input: feature
            sample_length: length of the training sample, used for calculating smooth factor

        Returns:
            normed feature

        Shapes:
            input: [B, C, F, T]
            sample_length_in_training: 192
        """
        assert input.ndim == 4
        batch_size, num_channels, num_freqs, num_frames = input.size()
        input = input.reshape(batch_size, num_channels * num_freqs, num_frames)

        eps = 1e-10
        mu = 0
        alpha = (sample_length - 1) / (sample_length + 1)

        mu_list = []
        # TODO bugs
        # TODO 是否需要修改为包含F的计算方法？
        for frame_idx in range(num_frames):
            if frame_idx < sample_length:
                alp = torch.min(torch.tensor([(frame_idx - 1) / (frame_idx + 1), alpha]))
                mu = alp * mu + (1 - alp) * torch.mean(input[:, :, frame_idx], dim=1).reshape(batch_size, 1)  # [B, 1]
            else:
                current_frame_mu = torch.mean(input[:, :, frame_idx], dim=1).reshape(batch_size, 1)  # [B, 1]
                mu = alpha * mu + (1 - alpha) * current_frame_mu

            mu_list.append(mu)

            # print("input", input[:, :, idx].min(), input[:, :, idx].max(), input[:, :, idx].mean())
            # print(f"alp {idx}: ", alp)
            # print(f"mu {idx}: {mu[128, 0]}")

        mu = torch.stack(mu_list, dim=-1)  # [B, 1, T]
        output = input / (mu + eps)

        output = output.reshape(batch_size, num_channels, num_freqs, num_frames)
        return output

        Using the mean value of the near frames to normalization

        Args:
            input: feature
            sample_length: length of the training sample, used for calculating smooth factor

        Returns:
            normed feature

        Shapes:
            input: [B, C, F, T]
            sample_length_in_training: 192
        
Using the mean value of the near frames to normalization
Using the mean value of the near frames to normalization
def forgetting_norm(input, sample_length=192):
        assert input.ndim == 4
        batch_size, num_channels, num_freqs, num_frames = input.size()
        input = input.reshape(batch_size, num_channels * num_freqs, num_frames)
        eps = 1e-10
        mu = 0
        alpha = (sample_length - 1) / (sample_length + 1)
        mu_list = []
        for frame_idx in range(num_frames):
            if frame_idx < sample_length:
                alp = torch.min(torch.tensor([(frame_idx - 1) / (frame_idx + 1), alpha]))
                mu = alp * mu + (1 - alp) * torch.mean(input[:, :, frame_idx], dim=1).reshape(batch_size, 1)  
            else:
                current_frame_mu = torch.mean(input[:, :, frame_idx], dim=1).reshape(batch_size, 1)  
                mu = alpha * mu + (1 - alpha) * current_frame_mu
            mu_list.append(mu)
        mu = torch.stack(mu_list, dim=-1)  
        output = input / (mu + eps)
        output = output.reshape(batch_size, num_channels, num_freqs, num_frames)
        return output
def forgetting_norm ( input , sample_length = 192 ) : assert input . ndim == 4 batch_size , num_channels , num_freqs , num_frames = input . size ( ) input = input . reshape ( batch_size , num_channels * num_freqs , num_frames ) eps = 1e-10 mu = 0 alpha = ( sample_length - 1 ) / ( sample_length + 1 ) mu_list = [ ] for frame_idx in range ( num_frames ) : if frame_idx < sample_length : alp = torch . min ( torch . tensor ( [ ( frame_idx - 1 ) / ( frame_idx + 1 ) , alpha ] ) ) mu = alp * mu + ( 1 - alp ) * torch . mean ( input [ : , : , frame_idx ] , dim = 1 ) . reshape ( batch_size , 1 ) else : current_frame_mu = torch . mean ( input [ : , : , frame_idx ] , dim = 1 ) . reshape ( batch_size , 1 ) mu = alpha * mu + ( 1 - alpha ) * current_frame_mu mu_list . append ( mu ) mu = torch . stack ( mu_list , dim = - 1 ) output = input / ( mu + eps ) output = output . reshape ( batch_size , num_channels , num_freqs , num_frames ) return output
Using the mean value of the near frames to normalization
Using the mean value of the near frames to normalization
"""
        Using the mean value of the near frames to normalization

        Args:
            input: feature
            sample_length: length of the training sample, used for calculating smooth factor

        Returns:
            normed feature

        Shapes:
            input: [B, C, F, T]
            sample_length_in_training: 192
        """ # TODO bugs # TODO 是否需要修改为包含F的计算方法？ # [B, 1] # [B, 1] # print("input", input[:, :, idx].min(), input[:, :, idx].max(), input[:, :, idx].mean()) # print(f"alp {idx}: ", alp) # print(f"mu {idx}: {mu[128, 0]}") # [B, 1, T]
None
input
None
sample_length
length of the training sample, used for calculating smooth factor
length of the training sample used for calculating smooth factor