函数详解:
torch.round(input, out=None)
说明:返回一个新张量,将输入input张量的每个元素舍入到最近的整数。
参数:
- input(Tensor):输入张量
- out(Tensor,可选):输出张量
import torch
a = torch.randn(4)
print(a) ## tensor([-0.8229, -0.6338, -1.3387, -0.0584])
print(torch.round(a)) ## tensor([-1., -1., -1., -0.])
应用:
可以用到某些回归或分类问题上。如语音合成模型Fastspeech2中的duration predictor就是采用的该方法,为每一个音素预测一个值,然后把它舍入到最近的整数,作为每个音素对应的帧数。
参考:https://blog.csdn.net/gyt15663668337/article/details/91414352