TypeError: argument must be sequence

username: Joshua_Jenny_Sibbu
cooked: <p>img = Image.open("/content/drive/MyDrive//58125_000893_Sideline_frame298.jpg").convert(‘RGB’)</p>
<p>convert_tensor = torchvision.transforms.ToTensor()</p>
<p>img=convert_tensor(img)</p>
<p>left=1099</p>
<p>width=16</p>
<p>top=456</p>
<p>height=15</p>
<p>boxs=[top,left,width,height]</p>
<p>boxs=torch.tensor(boxs,dtype=torch.int)</p>
<p>n=tens.permute(0,1,2)</p>
<p>print(n.shape)</p>
<p>torchvision.utils.draw_bounding_boxes(image=tens.permute(0,1,2),boxes=boxs,width=2)</p>
<p>I have typeerror: argument must be the sequence. I try to draw a bounding box but I get an error. can anyone help to resolve this problem</p>

username: ptrblck
cooked: <p><code>boxes</code> should be a tensor in the shape <code>[N, 4]</code>, so you might need to use <code>boxes=boxs.unsqueeze(0)</code>.</p>

username: Joshua_Jenny_Sibbu
cooked: <p>I resolve that problem but I stuck with another problem.</p>
<pre><code class="lang-auto">img = Image.open("/content/drive/MyDrive/58125_000893_Sideline_frame298.jpg").convert('RGB')
convert_tensor = torchvision.transforms.ToTensor()

img=convert_tensor(img)
width=800
height=500
top=100
left=100
boxs=[left,top,width,height]
boxs=torch.tensor([boxs],dtype=torch.uint8)
a=torch.tensor(img,dtype=torch.uint8)

a=torchvision.utils.draw_bounding_boxes(image=a,boxes=boxs,width=5)
a=a.permute(2,1,0)
a=torch.tensor(a,dtype=torch.float64)

plt.imshow(a)
plt.show()
</code></pre>
<p>This is my code. But i get blacked image.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/6/1/61dcee79f2dde17ed3a99c0f6451b35b1afe091c.png" alt="downloadm" data-base62-sha1="dXJEOtAzIXWNDoWc1cuyW3MJR6s" width="168" height="252"></p>
<p>I have a bounding box values in left,top,height,and width. So can you tell me correct sequence to draw bounding box? and the actual image is in landscape mode. But I got portrait image. Bounding box does not occur when I use transform.rotate.</p>

username: ptrblck
cooked: <p>Check the min. and max. values of <code>a</code> and make sure <code>matplotlib</code> can properly visualize these values without clipping. If clipping is used, you should get a warning explaining why it’s done.</p>

username: Joshua_Jenny_Sibbu
cooked: <p>I didn’t clip the tensor.<br>
torchvision.utils.draw_bounding_boxes is not accept float32. This only accepts uint8.</p>
<pre><code class="lang-auto">Tensor uint8 expected, got torch.float32
</code></pre>
<p>I get this error If I  leave tensor type as empty.<br>
So i change the tensor type to unint8 so I am getting blacked image. How to resolve this.</p>

username: ptrblck
cooked: <p>You would have to transform the floating point image containing values in <code>[0, 1]</code> to <code>[0, 255]</code> e.g. by multiplying it with <code>255.</code> and then transform it to <code>uint8</code>.</p>

username: Joshua_Jenny_Sibbu
cooked: <p>Fixed thank You. But the Bounding box is not fit well. [left,top,width,height]. Is this order is correct.</p>

username: ptrblck
cooked: <p>No, from the <a href="https://pytorch.org/vision/master/utils.html#torchvision.utils.draw_bounding_boxes">docs</a>:</p>
<blockquote>
<p><strong>boxes</strong> (<em>Tensor</em>) – Tensor of size (N, 4) containing bounding boxes in (xmin, ymin, xmax, ymax) format. Note that the boxes are absolute coordinates with respect to the image. In other words: 0 &lt;= xmin &lt; xmax &lt; W and 0 &lt;= ymin &lt; ymax &lt; H.</p>
</blockquote>

username: Joshua_Jenny_Sibbu
cooked: <pre><code class="lang-auto">img = Image.open("/content/drive/MyDrive/58125_000893_Sideline_frame298.jpg").convert('RGB')
convert_tensor = torchvision.transforms.ToTensor()

img=convert_tensor(img)
width=16
left=1099
height=15
top=456
img=img*255
boxs=[top,left,top+width,left+height]
boxs=torch.tensor(boxs,dtype=torch.int)
print(boxs)
a=torch.tensor(img,dtype=torch.uint8)
a=torchvision.utils.draw_bounding_boxes(image=a,boxes=boxs.unsqueeze(0),width=2,colors=(0,0,255))
a=a.permute(1,2,0)
plt.imshow(a)
plt.show()
</code></pre>
<p>The bounding box is not shown. Even i try with the black image but the bounding box is not shown.</p>

username: ptrblck
cooked: <p>It works for me:</p>
<pre><code class="lang-python">img = torchvision.transforms.ToPILImage()(torch.randn(3, 2000, 2000))
convert_tensor = torchvision.transforms.ToTensor()
img = convert_tensor(img)

width = 16
left = 1099
height = 15
top = 456
img = img*255
boxs = [top,left,top+width,left+height]
boxs = torch.tensor(boxs,dtype=torch.int)
print(boxs)
a = img.to(torch.uint8)
a = torchvision.utils.draw_bounding_boxes(image=a,boxes=boxs.unsqueeze(0),width=10)
a = a.permute(1,2,0)
plt.imshow(a)
</code></pre>
<p>Maybe increase the <code>width</code> or the bounding box itself, since it’s tiny (16x15 pixels) compared to the expected image shape.</p>

username: Joshua_Jenny_Sibbu
cooked: <p>the bounding box is not drawn correctly what I expect. Can you explain how to use?</p>
<pre><code class="lang-auto">width=15
top=456
height=16
left=1099
img=img*255
boxs=[left,top,top+width,left+height]
</code></pre>
<p>Box values are correct, I get from the CSV file.<br>
<img src="https://discuss.pytorch.org/uploads/default/original/3X/d/3/d3537233a9b4832e92254cde7c3753a02bf8c15c.png" alt="torchp" data-base62-sha1="u9twMmGrydbgjGbw7Iv4RwG1h9i" width="375" height="223"></p>
<p>i expect a drawn bounding box in player’s helmet.</p>

username: ptrblck
cooked: <p>I don’t think the drawn bounding box is created using the code snippet, is it? In your code the box would be <code>15x16</code> pixels, while the currently shown one is <code>~600x300</code>?</p>

username: Joshua_Jenny_Sibbu
cooked: <p>No that bounding box argument return that bounding box. Here is my code and output.</p>
<pre><code class="lang-auto">img = Image.open("/content/drive/MyDrive/58125_000893_Sideline_frame298.jpg").convert('RGB')
convert_tensor = torchvision.transforms.ToTensor()

img=convert_tensor(img)
width=15
top=456
height=16
left=1099
img=img*255
boxs=[left,top,top+width,left+height]
boxs=torch.tensor(boxs,dtype=torch.int)
a=torch.tensor(img,dtype=torch.uint8)
a=torchvision.utils.draw_bounding_boxes(image=a,boxes=boxs.unsqueeze(0),width=2,colors=(0,0,255))
a=a.permute(1,2,0)
plt.imshow(a)
plt.show()
</code></pre>
<p><img src="https://discuss.pytorch.org/uploads/default/original/3X/3/a/3ad37380fe958e5686f6967ecd6390fb8552e2e2.jpeg" alt="origi" data-base62-sha1="8ooIYiM1RhA1I5gdIlURCCSuz2G" width="375" height="223"></p>