How to convert torch tensor to float?

Question:

I am using flask to do inference and I am getting this result. 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>)"
}
}
Asked By: harsh

||

Answers:

From Torch.Tensor.item docs:

x = torch.tensor([1.0])

print((x.item())

output:

1.0

type check:

print(type(x.item())

output:

float
Answered By: ImSo3K

You can also use tensor.to(torch.float)

Answered By: psmatter
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.