本文簡要介紹python語言中 torch.nn.functional.ctc_loss
的用法。
用法:
torch.nn.functional.ctc_loss(log_probs, targets, input_lengths, target_lengths, blank=0, reduction='mean', zero_infinity=False)
log_probs-
C = number of characters in alphabet including blank
、T = input length
和N = batch size
。輸出的對數概率(例如,使用torch.nn.functional.log_softmax()
獲得)。 其中targets-
(sum(target_lengths))
。目標不能為空。在第二種形式中,假設目標是串聯的。 或input_lengths- 。輸入的長度(每個都必須是 )
target_lengths- 。目標的長度
blank(int,可選的) -空白標簽。默認 。
reduction(string,可選的) -指定要應用於輸出的縮減:
'none'
|'mean'
|'sum'
。'none'
:不應用減少,'mean'
:輸出損失將除以目標長度,然後取批次的平均值,'sum'
:輸出將被求和。默認值:'mean'
zero_infinity(bool,可選的) -是否將無限損失和相關梯度歸零。默認值:
False
無限損失主要發生在輸入太短而無法與目標對齊時。
聯結主義時間分類損失。
有關詳細信息,請參閱
CTCLoss
。注意
在某些情況下,當在 CUDA 設備上給定張量並使用 CuDNN 時,此運算符可能會選擇非確定性算法來提高性能。如果這是不可取的,您可以嘗試通過設置
torch.backends.cudnn.deterministic = True
來使操作具有確定性(可能以性能為代價)。有關詳細信息,請參閱重現性。注意
當給定 CUDA 設備上的張量時,此操作可能會產生不確定的梯度。有關詳細信息,請參閱重現性。
例子:
>>> log_probs = torch.randn(50, 16, 20).log_softmax(2).detach().requires_grad_() >>> targets = torch.randint(1, 20, (16, 30), dtype=torch.long) >>> input_lengths = torch.full((16,), 50, dtype=torch.long) >>> target_lengths = torch.randint(10,30,(16,), dtype=torch.long) >>> loss = F.ctc_loss(log_probs, targets, input_lengths, target_lengths) >>> loss.backward()
參數:
相關用法
- Python PyTorch cholesky用法及代碼示例
- Python PyTorch column_stack用法及代碼示例
- Python PyTorch cumprod用法及代碼示例
- Python PyTorch calculate_gain用法及代碼示例
- Python PyTorch cov用法及代碼示例
- Python PyTorch cos用法及代碼示例
- Python PyTorch compute_deltas用法及代碼示例
- Python PyTorch conv_transpose3d用法及代碼示例
- Python PyTorch combinations用法及代碼示例
- Python PyTorch conv2d用法及代碼示例
- Python PyTorch cummax用法及代碼示例
- Python PyTorch custom_from_mask用法及代碼示例
- Python PyTorch collect_all用法及代碼示例
- Python PyTorch chunk用法及代碼示例
- Python PyTorch convert用法及代碼示例
- Python PyTorch conv1d用法及代碼示例
- Python PyTorch chain_matmul用法及代碼示例
- Python PyTorch cat用法及代碼示例
- Python PyTorch constant_用法及代碼示例
- Python PyTorch context用法及代碼示例
- Python PyTorch count_nonzero用法及代碼示例
- Python PyTorch cdist用法及代碼示例
- Python PyTorch ceil用法及代碼示例
- Python PyTorch cosh用法及代碼示例
- Python PyTorch criteo_terabyte用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.nn.functional.ctc_loss。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。