[英]How to convert torch tensor to float?
I am using flask to do inference and I am getting this result.我正在使用 flask 进行推理,我得到了这个结果。 Is their any way to convert this tensor into float because I want to use this result to display in a react app他们有什么方法可以将这个张量转换为浮点数,因为我想用这个结果在反应应用程序中显示
{
result: {
predictions: "tensor([[-3.4333]], grad_fn=<AddmmBackward>)"
}
}
From Torch.Tensor.item docs:来自Torch.Tensor.item文档:
x = torch.tensor([1.0])
print((x.item())
output:输出:
1.0
type check:类型检查:
print(type(x.item())
output:输出:
float
You can also use tensor.to(torch.float)你也可以使用 tensor.to(torch.float)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.