本文简要介绍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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。