簡體   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