'train_one_epoch gives error' while using COCO annotations

I am using the COCO dataset for training with annotations available at the COCO website.
While using the code from: https://github.com/pytorch/vision/blob/master/references/detection/engine.py, I get an error:

AttributeError: ‘list’ object has no attribute ‘items’

for the code snippet:
targets = [{k: v.to(device) for k, v in t.items()} for t in targets]

Further digging into the issue, I find that the ‘targets’ I receive from the ‘for loop’:
for images, targets in metric_logger.log_every(data_loader, print_freq, header):

are in tuple format, with length equal to the batch_size.
Moreover, each item in this tuple is a list, and each list consists of seven dictionaries containing the annotation information.
When I apply this code to an individual object, it works fine:

target = targets[0]
obj_1 = target[0]
dict_1 = [{k: v for k, v in obj_1.items()}]

So I suppose the code might be written as follows:
targets = [[{k: v for k, v in obj.items()} for obj in target] for target in targets]

Can anyone please confirm this and provide help in this regard?

1 Like