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?

talonmies
  • 70,661
  • 34
  • 192
  • 269
ShivAA
  • 121
  • 1
  • 2
  • 8
  • Does this answer your question? [How do I get value of a tensor in PyTorch?](https://stackoverflow.com/questions/57727372/how-do-i-get-value-of-a-tensor-in-pytorch) – iacob Mar 30 '21 at 21:54

1 Answers1

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

where tensors is the list of tensors.

Mustafa Aydın
  • 17,645
  • 4
  • 15
  • 38