当前位置: 首页>>代码示例>>Python>>正文


Python torch.hann_window方法代码示例

本文整理汇总了Python中torch.hann_window方法的典型用法代码示例。如果您正苦于以下问题:Python torch.hann_window方法的具体用法?Python torch.hann_window怎么用?Python torch.hann_window使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torch的用法示例。


在下文中一共展示了torch.hann_window方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _feature_window_function

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def _feature_window_function(window_type: str,
                             window_size: int,
                             blackman_coeff: float,
                             device: torch.device,
                             dtype: int,
                             ) -> Tensor:
    r"""Returns a window function with the given type and size
    """
    if window_type == HANNING:
        return torch.hann_window(window_size, periodic=False, device=device, dtype=dtype)
    elif window_type == HAMMING:
        return torch.hamming_window(window_size, periodic=False, alpha=0.54, beta=0.46, device=device, dtype=dtype)
    elif window_type == POVEY:
        # like hanning but goes to zero at edges
        return torch.hann_window(window_size, periodic=False, device=device, dtype=dtype).pow(0.85)
    elif window_type == RECTANGULAR:
        return torch.ones(window_size, device=device, dtype=dtype)
    elif window_type == BLACKMAN:
        a = 2 * math.pi / (window_size - 1)
        window_function = torch.arange(window_size, device=device, dtype=dtype)
        # can't use torch.blackman_window as they use different coefficients
        return (blackman_coeff - 0.5 * torch.cos(a * window_function) +
                (0.5 - blackman_coeff) * torch.cos(2 * a * window_function)).to(device=device, dtype=dtype)
    else:
        raise Exception('Invalid window type ' + window_type) 
开发者ID:pytorch,项目名称:audio,代码行数:27,代码来源:kaldi.py

示例2: __init__

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def __init__(self,
                 n_fft: int = 400,
                 win_length: Optional[int] = None,
                 hop_length: Optional[int] = None,
                 pad: int = 0,
                 window_fn: Callable[..., Tensor] = torch.hann_window,
                 power: Optional[float] = 2.,
                 normalized: bool = False,
                 wkwargs: Optional[dict] = None) -> None:
        super(Spectrogram, self).__init__()
        self.n_fft = n_fft
        # number of FFT bins. the returned STFT result will have n_fft // 2 + 1
        # number of frequecies due to onesided=True in torch.stft
        self.win_length = win_length if win_length is not None else n_fft
        self.hop_length = hop_length if hop_length is not None else self.win_length // 2
        window = window_fn(self.win_length) if wkwargs is None else window_fn(self.win_length, **wkwargs)
        self.register_buffer('window', window)
        self.pad = pad
        self.power = power
        self.normalized = normalized 
开发者ID:pytorch,项目名称:audio,代码行数:22,代码来源:transforms.py

示例3: test_griffinlim

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_griffinlim(self):
        # NOTE: This test is flaky without a fixed random seed
        # See https://github.com/pytorch/audio/issues/382
        torch.random.manual_seed(42)
        tensor = torch.rand((1, 1000))

        n_fft = 400
        ws = 400
        hop = 100
        window = torch.hann_window(ws)
        normalize = False
        momentum = 0.99
        n_iter = 8
        length = 1000
        rand_init = False
        init = 'random' if rand_init else None

        specgram = F.spectrogram(tensor, 0, window, n_fft, hop, ws, 2, normalize).sqrt()
        ta_out = F.griffinlim(specgram, window, n_fft, hop, ws, 1, normalize,
                              n_iter, momentum, length, rand_init)
        lr_out = librosa.griffinlim(specgram.squeeze(0).numpy(), n_iter=n_iter, hop_length=hop,
                                    momentum=momentum, init=init, length=length)
        lr_out = torch.from_numpy(lr_out).unsqueeze(0)

        self.assertEqual(ta_out, lr_out, atol=5e-5, rtol=1e-5) 
开发者ID:pytorch,项目名称:audio,代码行数:27,代码来源:test_librosa_compatibility.py

示例4: test_griffinlim

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_griffinlim(self):
        def func(tensor):
            n_fft = 400
            ws = 400
            hop = 200
            window = torch.hann_window(ws, device=tensor.device, dtype=tensor.dtype)
            power = 2.
            normalize = False
            momentum = 0.99
            n_iter = 32
            length = 1000
            rand_int = False
            return F.griffinlim(tensor, window, n_fft, hop, ws, power, normalize, n_iter, momentum, length, rand_int)

        tensor = torch.rand((1, 201, 6))
        self._assert_consistency(func, tensor) 
开发者ID:pytorch,项目名称:audio,代码行数:18,代码来源:torchscript_consistency_impl.py

示例5: compute_torch_stft

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def compute_torch_stft(audio, descriptor):

    name, *args = descriptor.split("_")

    n_fft, hop_size, *rest = args
    n_fft = int(n_fft)
    hop_size = int(hop_size)

    stft = torch.stft(
        audio,
        n_fft=n_fft,
        hop_length=hop_size,
        window=torch.hann_window(n_fft, device=audio.device)
    )

    stft = torch.sqrt((stft ** 2).sum(-1))

    return stft 
开发者ID:ex4sperans,项目名称:freesound-classification,代码行数:20,代码来源:utils.py

示例6: get_window

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def get_window(name, window_length, squared=False):
    """
    Returns a windowing function.
    
    Arguments:
    ----------
        window (str)                : name of the window, currently only 'hann' is available
        window_length (int)         : length of the window
        squared (bool)              : if true, square the window
        
    Returns:
    ----------
        torch.FloatTensor           : window of size `window_length`
    """
    if name == "hann":
        window = torch.hann_window(window_length)
    elif name == "hamming":
        window = torch.hamming_window(window_length)
    elif name == "blackman":
        window = torch.blackman_window(window_length)
    else:
        raise ValueError("Invalid window name {}".format(name))
    if squared:
        window *= window
    return window 
开发者ID:acids-ircam,项目名称:ddsp_pytorch,代码行数:27,代码来源:modules.py

示例7: __init__

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def __init__(self, win_length=1024, hop_length=256, n_fft=2048, n_mels=80, preemp=True):
        super(MelSpectrogram, self).__init__()
        if preemp:
            self.preemp = nn.Conv1d(1, 1, 2, bias=False, padding=1)
            self.preemp.weight.data[0][0][0] = -0.97
            self.preemp.weight.data[0][0][1] = 1.0
            self.preemp.weight.requires_grad = False
        else:
            self.preemp = None

        self.register_buffer('mel_basis', _build_mel_basis(n_fft, n_mels))

        win = torch.hann_window(win_length)
        self.register_buffer('win', win)

        self.win_length = win_length
        self.hop_length = hop_length
        self.n_fft = n_fft 
开发者ID:tuan3w,项目名称:cnn_vocoder,代码行数:20,代码来源:stft.py

示例8: __init__

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def __init__(self, win_length, hop_length):
        super().__init__()

        self.win_length = win_length
        self.hop_length = hop_length

        self.disable_casts = self._opt_level == Optimization.mxprO1

        self.torch_windows = {
            'hann': torch.hann_window,
            'hamming': torch.hamming_window,
            'blackman': torch.blackman_window,
            'bartlett': torch.bartlett_window,
            'ones': torch.ones,
            None: torch.ones,
        } 
开发者ID:NVIDIA,项目名称:NeMo,代码行数:18,代码来源:audio_preprocessing.py

示例9: test_griffinlim

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_griffinlim(self):
        n_fft = 400
        ws = 400
        hop = 200
        window = torch.hann_window(ws)
        power = 2
        normalize = False
        momentum = 0.99
        n_iter = 32
        length = 1000
        tensor = torch.rand((1, 201, 6))
        self.assert_batch_consistencies(
            F.griffinlim, tensor, window, n_fft, hop, ws, power, normalize, n_iter, momentum, length, 0, atol=5e-5
        ) 
开发者ID:pytorch,项目名称:audio,代码行数:16,代码来源:test_batch_consistency.py

示例10: test_istft_is_inverse_of_stft1

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_istft_is_inverse_of_stft1(self):
        # hann_window, centered, normalized, onesided
        kwargs1 = {
            'n_fft': 12,
            'hop_length': 4,
            'win_length': 12,
            'window': torch.hann_window(12),
            'center': True,
            'pad_mode': 'reflect',
            'normalized': True,
            'onesided': True,
        }
        _test_istft_is_inverse_of_stft(kwargs1) 
开发者ID:pytorch,项目名称:audio,代码行数:15,代码来源:functional_cpu_test.py

示例11: test_istft_is_inverse_of_stft2

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_istft_is_inverse_of_stft2(self):
        # hann_window, centered, not normalized, not onesided
        kwargs2 = {
            'n_fft': 12,
            'hop_length': 2,
            'win_length': 8,
            'window': torch.hann_window(8),
            'center': True,
            'pad_mode': 'reflect',
            'normalized': False,
            'onesided': False,
        }
        _test_istft_is_inverse_of_stft(kwargs2) 
开发者ID:pytorch,项目名称:audio,代码行数:15,代码来源:functional_cpu_test.py

示例12: test_linearity_of_istft1

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_linearity_of_istft1(self):
        # hann_window, centered, normalized, onesided
        kwargs1 = {
            'n_fft': 12,
            'window': torch.hann_window(12),
            'center': True,
            'pad_mode': 'reflect',
            'normalized': True,
            'onesided': True,
        }
        data_size = (2, 7, 7, 2)
        self._test_linearity_of_istft(data_size, kwargs1) 
开发者ID:pytorch,项目名称:audio,代码行数:14,代码来源:functional_cpu_test.py

示例13: test_linearity_of_istft2

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_linearity_of_istft2(self):
        # hann_window, centered, not normalized, not onesided
        kwargs2 = {
            'n_fft': 12,
            'window': torch.hann_window(12),
            'center': True,
            'pad_mode': 'reflect',
            'normalized': False,
            'onesided': False,
        }
        data_size = (2, 12, 7, 2)
        self._test_linearity_of_istft(data_size, kwargs2) 
开发者ID:pytorch,项目名称:audio,代码行数:14,代码来源:functional_cpu_test.py

示例14: test_spectrogram

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def test_spectrogram(self):
        def func(tensor):
            n_fft = 400
            ws = 400
            hop = 200
            pad = 0
            window = torch.hann_window(ws, device=tensor.device, dtype=tensor.dtype)
            power = 2.
            normalize = False
            return F.spectrogram(tensor, pad, window, n_fft, hop, ws, power, normalize)

        tensor = common_utils.get_whitenoise()
        self._assert_consistency(func, tensor) 
开发者ID:pytorch,项目名称:audio,代码行数:15,代码来源:torchscript_consistency_impl.py

示例15: __init__

# 需要导入模块: import torch [as 别名]
# 或者: from torch import hann_window [as 别名]
def __init__(self, hp):
        self.hp = hp
        self.window = torch.hann_window(window_length=hp.audio.win_length).cuda()
        self.mel_basis = librosa.filters.mel(
            sr=hp.audio.sr,
            n_fft=hp.audio.n_fft,
            n_mels=hp.audio.n_mels
        )
        self.mel_basis = torch.from_numpy(self.mel_basis).cuda() # [n_mels, n_fft//2+1]
        self.criterion = torch.nn.MSELoss() 
开发者ID:Deepest-Project,项目名称:MelNet,代码行数:12,代码来源:reconstruct.py


注:本文中的torch.hann_window方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。