1

I have my output of my torch tensor which looks like below

(coordinate of a bounding box in object detection)

[tensor(299., device='cuda:0'), tensor(272., device='cuda:0'), tensor(327., device='cuda:0'), tensor(350., device='cuda:0')]

I wanted to extract each of the tensor value as an int in the form of minx,miny,maxx,maxy
so that I can pass it to a shapely function in the below form

from shapely.geometry import box
minx,miny,maxx,maxy=1,2,3,4
b = box(minx,miny,maxx,maxy)

What's the best way to do it? by avoiding, Cuda enabled or not or other exceptions?

1

1 Answer 1

2
minx, miny, maxx, maxy = [int(t.item()) for t in tensors]

where tensors is the list of tensors.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.