Torchvision - Faster RCNN - Empty Training Images


I am using the Torchvision Faster RCNN model for Object detection.
I am trying to train the model with my own dataset and followed the tutorial on:

Now I am face a problem how to deal training images without an object to detect.
At the moment I am using

    boxes = torch.as_tensor(boxes, dtype=torch.float32)
    labels = torch.as_tensor(labels, dtype=torch.int64)
    image_id = torch.tensor([idx])
    if num_objs==0:
        area = torch.tensor([0]) #also tried torch.tensor([]) 
        area = (boxes[:, 3] - boxes[:, 1]) * (boxes[:, 2] - boxes[:, 0])
    iscrowd = torch.zeros((num_objs,), dtype=torch.int64)
    target = {}
    target["boxes"] = boxes
    target["labels"] = labels
    target["image_id"] = image_id
    target["area"] = area
    target["iscrowd"] = iscrowd
    if self.transforms is not None:
        img, target = self.transforms(img, target)

    return img, target

in combination with the engine in references/detection/
Now if, a empty image is selected I get the following error message:
Traceback (most recent call last):

File “/home/user/Detection_Experiments/”, line 155, in
model, optimizer, loss, lr_scheduler=main()
File “/home/user/Detection_Experiments/”, line 146, in main
loss=train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
File “/home/user/Detection_Experiments/references/detection/”, line 30, in train_one_epoch
loss_dict = model(images, targets)
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torch/nn/modules/”, line 493, in call
result = self.forward(*input, **kwargs)
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torchvision-0.3.0-py3.6-linux-x86_64.egg/torchvision/models/detection/”, line 47, in forward
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torch/nn/modules/”, line 493, in call
result = self.forward(*input, **kwargs)
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torchvision-0.3.0-py3.6-linux-x86_64.egg/torchvision/models/detection/”, line 40, in forward
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torchvision-0.3.0-py3.6-linux-x86_64.egg/torchvision/models/detection/”, line 74, in resize
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torchvision-0.3.0-py3.6-linux-x86_64.egg/torchvision/models/detection/”, line 135, in resize_boxes
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Can anyone tell my how my tensors should look I want to use an empty image, using the standart Torchvision Faster RCNN?

Thank you in advance :slight_smile:

I am also trying to implement the mask RCNN following this tutorial. May i ask, where did you download the references/detection/ i just can’t find it anywhere.


its in the torchvision github repo:

Having exactly the same question…did you find a solution yet? Does it even make sense to train on images with no object at all?

Does anyone have a working training script with the torchvision faster rcnn implementation?
I am trying to train from scratch with coco but I keep getting issues with tensor sizes in the roi code.