Solved by LHFO94 in post #2 
              
              
                The error was in the following line of code: 
 labels_array = np.array(self.dataframe.loc[self.dataframe['image_id'] == img_id, ['label']])
        labels = torch.tensor(labels_array, dtype=torch.int64)
        target['labels'] = labels

This resulted in an embedded list of targets. Changing it to 
 …