繁体   English   中英

如何将pytorch的预测转换成普通文本

[英]How to convert the prediction of pytorch into normal text

我有一个 PyTorch 模型,我正在对它进行预测。 做预测后,我得到的输出为

tensor([[-3.4333]], grad_fn=<AddmmBackward>)

但我需要它作为普通整数-3.4333 我该怎么做。

在张量上调用.item以将其转换为标准的 Python 数字。

要获取张量调用中的值: tensor.item()

前任:

>>> x = torch.tensor([1.0])
>>> x.item()
1.0

https://pytorch.org/docs/stable/generated/torch.Tensor.item.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM