I'm trying to fine-tune Pytorch model using their own tutorial from their page. I try it on dataset StaVer from Kaggle: rtatman/stamp-verification-staver-dataset.
The only change to their code is the paths to the dataset. The error occured in the training model section:
# let's train it for 10 epochs
from torch.optim.lr_scheduler import StepLR
num_epochs = 20
for epoch in range(num_epochs):
# train for one epoch, printing every 10 iterations
train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=1)
# update the learning rate
lr_scheduler.step()
# evaluate on the test dataset
evaluate(model, data_loader_test, device=device)
.
The same error can be replicated just by running this piece of code:
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
dataset = StaverDataset("", get_transform(train=True))
data_loader = torch.utils.data.DataLoader(
dataset, batch_size=2, shuffle=False, num_workers=0, collate_fn=utils.collate_fn
)
a = iter(data_loader)
for i in range(len(a)):
images, targets = next(a)
images = list(image for image in images)
targets = [{k: v for k, v in t.items()} for t in targets]
output = model(images, targets)
The wierd part is that it worked ok until image_382. And if I delete all previous images and run the model on last approx. 50 images it will work as well. Seems the problem is not related to the image but the number of images. The number of images run through the model().
This is the error:
scans/scans/stampDS-00380.png
scans/scans/stampDS-00381.png
scans/scans/stampDS-00382.png
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-40-6ccb0398c1aa> in <module>()
4 images = list(image for image in images)
5 targets = [{k: v for k, v in t.items()} for t in targets]
----> 6 output = model(images, targets)
7 model.eval()
6 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/functional.py in interpolate(input, size, scale_factor, mode, align_corners, recompute_scale_factor)
3710 return torch._C._nn.upsample_nearest1d(input, output_size, scale_factors)
3711 if input.dim() == 4 and mode == "nearest":
-> 3712 return torch._C._nn.upsample_nearest2d(input, output_size, scale_factors)
3713 if input.dim() == 5 and mode == "nearest":
3714 return torch._C._nn.upsample_nearest3d(input, output_size, scale_factors)
RuntimeError: Input and output sizes should be greater than 0, but got input (H: 1605, W: 2) output (H: 799, W: 0)
Does anyone know what is the error related to? Thank you in advance. Michael