audio_zen/model/base_model.py
def unfold(input, num_neighbors):
        """
        Along the frequency axis, this function is used for splitting overlapped sub-band units.

        Args:
            input: four-dimension input.
            num_neighbors: number of neighbors in each side.

        Returns:
            Overlapped sub-band units.

        Shapes:
            input: [B, C, F, T]
            return: [B, N, C, F_s, T]. F_s represents the frequency axis of the sub-band unit, e.g. [2, 161, 1, 19, 200]
        """
        assert input.dim() == 4, f"The dim of the input is {input.dim()}. It should be four dim."
        batch_size, num_channels, num_freqs, num_frames = input.size()

        if num_neighbors < 1:  # No change on the input
            return input.permute(0, 2, 1, 3).reshape(batch_size, num_freqs, num_channels, 1, num_frames)

        output = input.reshape(batch_size * num_channels, 1, num_freqs, num_frames)
        sub_band_unit_size = num_neighbors * 2 + 1

        # Pad the top and bottom of the original spectrogram
        output = functional.pad(output, [0, 0, num_neighbors, num_neighbors], mode="reflect")  # [B * C, 1, F, T]

        output = functional.unfold(output, (sub_band_unit_size, num_frames))  # move on the F and T axes.
        assert output.shape[-1] == num_freqs, f"n_freqs != N (sub_band), {num_freqs} != {output.shape[-1]}"

        # Split the dim of the unfolded feature
        output = output.reshape(batch_size, num_channels, sub_band_unit_size, num_frames, num_freqs)
        output = output.permute(0, 4, 1, 2, 3).contiguous()  # [B, N, C, F_s, T]

        return output

        Along the frequency axis, this function is used for splitting overlapped sub-band units.

        Args:
            input: four-dimension input.
            num_neighbors: number of neighbors in each side.

        Returns:
            Overlapped sub-band units.

        Shapes:
            input: [B, C, F, T]
            return: [B, N, C, F_s, T]. F_s represents the frequency axis of the sub-band unit, e.g. [2, 161, 1, 19, 200]
        
Along the frequency axis, this function is used for splitting overlapped sub-band units.
Along the frequency axis this function is used for splitting overlapped sub - band units .
def unfold(input, num_neighbors):
        assert input.dim() == 4, f"The dim of the input is {input.dim()}. It should be four dim."
        batch_size, num_channels, num_freqs, num_frames = input.size()
        if num_neighbors < 1:  
            return input.permute(0, 2, 1, 3).reshape(batch_size, num_freqs, num_channels, 1, num_frames)
        output = input.reshape(batch_size * num_channels, 1, num_freqs, num_frames)
        sub_band_unit_size = num_neighbors * 2 + 1
        output = functional.pad(output, [0, 0, num_neighbors, num_neighbors], mode="reflect")  
        output = functional.unfold(output, (sub_band_unit_size, num_frames))  
        assert output.shape[-1] == num_freqs, f"n_freqs != N (sub_band), {num_freqs} != {output.shape[-1]}"
        output = output.reshape(batch_size, num_channels, sub_band_unit_size, num_frames, num_freqs)
        output = output.permute(0, 4, 1, 2, 3).contiguous()  
        return output
def unfold ( input , num_neighbors ) : assert input . dim ( ) == 4 , f"The dim of the input is {input.dim()}. It should be four dim." batch_size , num_channels , num_freqs , num_frames = input . size ( ) if num_neighbors < 1 : return input . permute ( 0 , 2 , 1 , 3 ) . reshape ( batch_size , num_freqs , num_channels , 1 , num_frames ) output = input . reshape ( batch_size * num_channels , 1 , num_freqs , num_frames ) sub_band_unit_size = num_neighbors * 2 + 1 output = functional . pad ( output , [ 0 , 0 , num_neighbors , num_neighbors ] , mode = "reflect" ) output = functional . unfold ( output , ( sub_band_unit_size , num_frames ) ) assert output . shape [ - 1 ] == num_freqs , f"n_freqs != N (sub_band), {num_freqs} != {output.shape[-1]}" output = output . reshape ( batch_size , num_channels , sub_band_unit_size , num_frames , num_freqs ) output = output . permute ( 0 , 4 , 1 , 2 , 3 ) . contiguous ( ) return output
Along the frequency axis, this function is used for splitting overlapped sub-band units.
Along the frequency axis this function is used for splitting overlapped sub - band units .
"""
        Along the frequency axis, this function is used for splitting overlapped sub-band units.

        Args:
            input: four-dimension input.
            num_neighbors: number of neighbors in each side.

        Returns:
            Overlapped sub-band units.

        Shapes:
            input: [B, C, F, T]
            return: [B, N, C, F_s, T]. F_s represents the frequency axis of the sub-band unit, e.g. [2, 161, 1, 19, 200]
        """ # No change on the input # Pad the top and bottom of the original spectrogram # [B * C, 1, F, T] # move on the F and T axes. # Split the dim of the unfolded feature # [B, N, C, F_s, T]
Overlapped sub-band units.
Overlapped sub - band units .
input
None
num_neighbors
number of neighbors in each side.
number of neighbors in each side .