ValueError: All bounding boxes should have positive height and width. Found invaid box [264.0, 632.0, 264.0, 633.3333740234375] for target at index 2

username: Bisma_Akram
cooked: <h2>Hey I am getting the error<br>
ValueError: All bounding boxes should have positive height and width. Found invaid box [264.0, 632.0, 264.0, 633.3333740234375] for target at index 2.<br>
Epoch 1/1<br>
Mini-batch: 1/1220 Loss: 0.1509<br>
Mini-batch: 101/1220 Loss: 0.1201<br>
Mini-batch: 201/1220 Loss: 0.1103<br>
Mini-batch: 301/1220 Loss: 0.1098<br>
Mini-batch: 401/1220 Loss: 0.1076<br>
Mini-batch: 501/1220 Loss: 0.1056<br>
Mini-batch: 601/1220 Loss: 0.1044<br>
Mini-batch: 701/1220 Loss: 0.1035</h2>
<p>ValueError                                Traceback (most recent call last)<br>
 in ()<br>
13<br>
14         # Calculate losses<br>
—&gt; 15         loss_dict = model(images, targets)<br>
16         batch_loss = sum(loss for loss in loss_dict.values()) / len(loss_dict)<br>
17</p>
<p>1 frames<br>
/usr/local/lib/python3.6/dist-packages/torchvision/models/detection/generalized_rcnn.py in forward(self, images, targets)<br>
91                     raise ValueError(“All bounding boxes should have positive height and width.”<br>
92                                      " Found invaid box {} for target at index {}."<br>
—&gt; 93                                      .format(degen_bb, target_idx))<br>
94<br>
95         features = self.backbone(images.tensors)</p>
<p>ValueError: All bounding boxes should have positive height and width. Found invaid box [264.0, 632.0, 264.0, 633.3333740234375] for target at index 2.</p>
<p>I cant find a bounding box that has these coordinates in label csv file. Can anybody please help me out with this.<br>
here is my dataset class<br>
from torch.utils.data import Dataset, DataLoader</p>
<h1>Inherit from pytorch Dataset for convenience</h1>
<p>class DamageDataset(Dataset):</p>
<pre><code>def __init__(self, dataframe):

    super().__init__()

    self.filename = dataframe['filename'].unique()

    self.df = dataframe

def __len__(self) -&gt; int:

    return len(self.filename)



def __getitem__(self, index: int):

    filename = self.filename[index]

    image = read_image_from_train_folder(filename).astype(np.float32)

    # Scale to [0,1] range expected by the pre-trained model

    image /= 255.0

    # Convert the shape from [h,w,c] to [c,h,w] as expected by pytorch

    image = torch.from_numpy(image).permute(2,0,1)

    

    records = self.df[self.df['filename'] == filename]

    

    boxes = records[['xmin', 'ymin', 'xmax', 'ymax']].values

    classes= records['class'].values

    damage_labels=[]

    damage_dict={

        'D00': 1,

        'D10': 2,

        'D20': 3,

        'D40': 4,

                                                                    

    }

    for label in classes:

      damage_labels.append(damage_dict[label])

   

    boxes = torch.as_tensor(boxes, dtype=torch.float32)

    n_boxes = boxes.shape[0]

    

    # there is only one foreground class, WHEAT

    labels = torch.as_tensor(damage_labels, dtype=torch.float32)

            

    target = {}

    target['boxes'] = boxes

    target['labels'] = labels

    

    return image, target
</code></pre>
<p>and here is my train code:</p>
<p>num_epochs = 1</p>
<h1>Prepare the model for training</h1>
<p>model = model.to(device)</p>
<p>model.train()</p>
<p>for epoch in range(num_epochs):</p>
<pre><code>print("Epoch %i/%i " % (epoch + 1, num_epochs) )

average_loss = 0

for batch_id, (images, targets) in enumerate(train_data_loader):

    # Prepare the batch data

    images, targets = move_batch_to_device(images, targets)

    # Calculate losses

    loss_dict = model(images, targets)

    batch_loss = sum(loss for loss in loss_dict.values()) / len(loss_dict)

    

    # Refresh accumulated optimiser state and minimise losses

    optimizer.zero_grad()

    batch_loss.backward()

    optimizer.step()

    

    # Record stats

    loss_value = batch_loss.item()

    average_loss = average_loss + (loss_value - average_loss) / (batch_id + 1)

    print("Mini-batch: %i/%i Loss: %.4f" % ( batch_id + 1, len(train_data_loader), average_loss), end='\r')

    if batch_id % 100 == 0:

        print("Mini-batch: %i/%i Loss: %.4f" % ( batch_id + 1, len(train_data_loader), average_loss))
</code></pre>
<p>can someone help me find out the index of this bounding box so that I can delete it, I have iterated through my dataframe using the code:<br>
for idx, row in merge_labels.iterrows():</p>
<p>if(row[‘xmin’]==264 and row[‘ymin’]== 632 and row[‘xmax’]== 264 and row[‘ymax’]== 633.3333740234375 ):</p>
<pre><code>print(idx)
</code></pre>
<p>but it doesnt print any index.<br>
thank you</p>

username: mia
cooked: <p>[264.0, 632.0, 264.0, 633.3333740234375] is not a valid box, you should check your data</p>

username: Bisma_Akram
cooked: <p>yes, I have used<br>
for idx, row in merge_labels.iterrows():</p>
<p>if(row[‘xmin’]==264 and row[‘ymin’]== 632 and row[‘xmax’]== 264 and row[‘ymax’]== 633.3333740234375 ):</p>
<p>print(idx)</p>
<p>to find index of this bounding box but it is not printing anything</p>

username: Rmemr
cooked: <p>Hi, I have had the same problem. In my case the boxes were claimed to be out of range even if the data fed to the network was not.</p>
<p>However, the problem seemed to be that some of the boxes were degenerate. With this I mean that their area was zero (x1 == x2 or y1 == y2). After I filtered out those boxes the problem didn’t show up anymore.</p>
<p>I hope this solves your problem too.</p>

username: Tupakula_Mallikarjun
cooked: <p>Hi <a class="mention" href="/u/bisma_akram">@Bisma_Akram</a> I am also getting similar error. Have you solved the issue. If you’d solved it. Please let mw know how can I solve.</p>

username: PaulOmo
cooked: <p>Did you Solve this issues?</p>

username: Tupakula_Mallikarjun
cooked: <p><a class="mention" href="/u/paulomo">@PaulOmo</a> Yes, I had solved the issue.</p>

username: PaulOmo
cooked: <p>Can you share how you solved it. I am having similar issues. Any help will be appreciated. Thanks.</p>

username: PaulOmo
cooked: <aside class="quote quote-modified" data-post="1" data-topic="110971">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/p/a698b9/48.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/valueerror-all-bounding-boxes-should-have-positive-height-and-width-found-invalid-box-790-0323486328125-359-0328369140625-790-0323486328125-359-0328369140625-for-target-at-index-0/110971">ValueError: All bounding boxes should have positive height and width. Found invalid box [790.0323486328125, 359.0328369140625, 790.0323486328125, 359.0328369140625] for target at index 0</a> 
  </div>
  <blockquote>
    Can any one help with this issues. Searched the internet to see if I could resolve but not yet. Will appreciate any advice. 
I am following the transfer learning fine turning tutorial which can be found here on pytorch site: <a href="https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html" rel="noopener nofollow ugc">https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html</a> 
I am how ever training with 39 classes. 
Here is my code for the dataset: 
class Dataset(torch.utils.data.Dataset):
    def __init__(self, root, transforms=None):
        self.root = root
        self.tr…
  </blockquote>
</aside>


username: paschalis_m
cooked: <p>At first you have to check the GT boxes you are feeding to the network,<br>
Considering that the data format is [x1,y1,x2,y2] which actually indicates the [left,top…] and the […,right,bottom] edge of the ground truth box, in your case :</p>
<p>[264.0, 632.0, 264.0, 633.3333740234375]</p>
<p>x1 and x2, are actually overlapping which means that you don t actually provide a box but a straight line.</p>
<p>As others claimed <a class="mention" href="/u/rmemr">@Rmemr</a> and <a class="mention" href="/u/mia">@mia</a> , you have to check your ground truth first and reassure that any zero_area boxes are discarded …</p>