How to handle batches that contain objects

Hello,

I have a problem with the dataloader since one of my inputs is an object. Does anyone know a way to specify that instead of trying to stack it return a list?

I get this error: TypeError: batch must contain tensors, numbers, dicts or lists;

example of my data:

data = {   'sequence1': torch.Tensor([1,2,3,4,5]),
           'sequence2': torch.Tensor([1,2]),
           'sequence3': torch.Tensor([6,7,8,9,0]), 
           'incompatible_object': Object()} 

all_data = [data for _ in range(100)]

DataLoader(dataset=all_data, batch_size=20)

edit: ok, this is not a problem anymore, I just had to write collate_fn and pass it to the data loader

1 Like