sgrvinod / a-PyTorch-Tutorial-to-Object-Detection

SSD: Single Shot MultiBox Detector | a PyTorch Tutorial to Object Detection
MIT License
3.04k stars 718 forks source link

IndexError: too many indices for tensor of dimension 1 #16

Open indamutsa opened 5 years ago

indamutsa commented 5 years ago

File "/home/arsene/Project/mini-project2/Projekt/utils.py", line 350, in find_intersection lower_bounds = torch.max(set_1[:, :2].unsqueeze(1), set_2[:, :2].unsqueeze(0)) # (n1, n2, 2) IndexError: too many indices for tensor of dimension 1.

This happens when I try to load my own but with the same data sets format

YoongiKim commented 5 years ago

Me too. I need help!

lilyhappily commented 5 years ago

I recently study the tutorial, I have the problem too. I don't know whether you solve or not. when you encounter the problem, you print the tensor 1 and tensor 2, and then you will find the tensor 1 is tensor([0]). It is that some pictures have no gound_truth boxes. You should filter them out in the function of create_data_lists in utils.py. I changed the the author's code len(object) == 0 to len(object["boxes"] == 0 and it works. Hope, this can help.

fansac commented 4 years ago

I recently study the tutorial, I have the problem too. I don't know whether you solve or not. when you encounter the problem, you print the tensor 1 and tensor 2, and then you will find the tensor 1 is tensor([0]). It is that some pictures have no gound_truth boxes. You should filter them out in the function of create_data_lists in utils.py. I changed the the author's code len(object) == 0 to len(object["boxes"] == 0 and it works. Hope, this can help.

THX

Tathagatd96 commented 4 years ago

@Indamutsa @YoongiKim , I had faced the same issue. The criterion() expects a 2D tensor as input i.e a list of all bounding boxes which themselves are lists, so either change the shape of the boxes and labels in the train() in train.py or change the shape of boxes and labels in the forward() of class MultiBoxLoss(). You can use unsqueeze() to resize the tensors. Hope this helps.