Zero Division Error When Using Pytorch Faster-RCNN

I’m following the tutorial shown here but I’m also adapting it to work with FasterR-CNN using the pretrained model.
When the output = model(images, targets) gets executed, I receive this error:

Traceback (most recent call last):
File “C:/Users/werti/PycharmProjects/testtorch/myFRCNN/”, line 53, in
output = model(images, targets)
File “C:\Users\werti\anaconda3\envs\testtorch\lib\site-packages\torch\nn\modules\”, line 550, in call
result = self.forward(*input, **kwargs)
File “C:\Users\werti\anaconda3\envs\testtorch\lib\site-packages\torchvision\models\detection\”, line 66, in forward
images, targets = self.transform(images, targets)
File “C:\Users\werti\anaconda3\envs\testtorch\lib\site-packages\torch\nn\modules\”, line 550, in call
result = self.forward(*input, **kwargs)
File “C:\Users\werti\anaconda3\envs\testtorch\lib\site-packages\torchvision\models\detection\”, line 44, in forward
image = self.normalize(image)
File “C:\Users\werti\anaconda3\envs\testtorch\lib\site-packages\torchvision\models\detection\”, line 64, in normalize
return (image - mean[:, None, None]) / std[:, None, None]
RuntimeError: ZeroDivisionError

As far as I understand the std equals zero but i can’t see how that is up to me :[
Anyone got advices?
My images are 512x512 before being rescaled to 240x240. each image has only one bounding box and one class label

My code (which is very basic) if it can help:

model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
data = dld.DLDataset(csv_file, folder_path, transforms=get_transform(train=True))
data_loader =, batch_size=2)

images,targets = next(iter(data_loader))
images = list(image for image in images)
targets=toListofDict(targets) #This function turns the dict of list in a list of dicts as this particular model wants
output = model(images, targets)

Could you upload a sample image please, so that we could try to reproduce it?

This error seems to be related to this post.

CC @fmassa: it seems some custom images are creating this zero division. Have you seen this issue before?

I was able to see this through in the end.
There was an error in my ToTensor() transform. I guess that the final image not being normalized between 0 and 1 but between 0 and 255 was causing issue.

Thanks for the reply!