Hi,
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: https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html
Now I am face a problem how to deal training images without an object to detect.
At the moment I am using
__getitem__():
boxes = torch.as_tensor(boxes, dtype=torch.float32)
labels = torch.as_tensor(labels, dtype=torch.int64)
labels+=1
image_id = torch.tensor([idx])
if num_objs==0:
area = torch.tensor([0]) #also tried torch.tensor([])
else:
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/engine.py
.
Now if, a empty image is selected I get the following error message:
Traceback (most recent call last):
File “/home/user/Detection_Experiments/Model_Base.py”, line 155, in
model, optimizer, loss, lr_scheduler=main()
File “/home/user/Detection_Experiments/Model_Base.py”, line 146, in main
loss=train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
File “/home/user/Detection_Experiments/references/detection/engine.py”, 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/module.py”, 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/generalized_rcnn.py”, line 47, in forward
File “/home/user/.virtualenvs/test_p3/lib/python3.6/site-packages/torch/nn/modules/module.py”, 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/transform.py”, 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/transform.py”, 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/transform.py”, 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