AssertionError: target labels must of int64 type

Hi there,

I am just a newbie in Pytorch. I cloned prajjwal1’s repository from here https://github.com/prajjwal1/autonomous-object-detection and was trying to run it for bdd100k dataset. However, I keep getting this below error. It might be a simple error but I could not fix it. It is appreciated if you could help me.

Training started
0%| | 0/25 [00:00<?, ?it/s]
Traceback (most recent call last):
File “train_baseline.py”, line 81, in
train_one_epoch(model, optimizer, dl, device, epoch, print_freq=200)
File “C:\Users\Burak\autonomous-object-detection\engine.py”, line 42, in train_one_epoch
loss_dict = model(images, targets)
File “C:\Users\Burak\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 532, in call
result = self.forward(*input, **kwargs)
File “C:\Users\Burak\AppData\Local\Continuum\anaconda3\lib\site-packages\torchvision\models\detection\generalized_rcnn.py”, line 71, in forward
detections, detector_losses = self.roi_heads(features, proposals, images.image_sizes, targets)
File “C:\Users\Burak\AppData\Local\Continuum\anaconda3\lib\site-packages\torch\nn\modules\module.py”, line 532, in call
result = self.forward(*input, **kwargs)
File “C:\Users\Burak\AppData\Local\Continuum\anaconda3\lib\site-packages\torchvision\models\detection\roi_heads.py”, line 745, in forward
assert t[“labels”].dtype == torch.int64, ‘target labels must of int64 type’
AssertionError: target labels must of int64 type

Check your targets data type using targets.dtype.
If not int64, then convert it to int64 using targets = targets.long()

Or even, when you create the tensor, you do it like this:
targets = torch.tensor([[1,0,0,0,0],[0,1,0,0,0]], dtype=torch.long)