DataLoader problem with Cityscapes dataset

Hi,
I’m trying to load the Cityscapes dataset and format it in batches using DataLoader but I keep getting this error:

TypeError: default_collate: batch must contain tensors, numpy arrays, numbers, dicts or lists; found <class ‘PIL.PngImagePlugin.PngImageFile’>

my ode is this:

BATCH_SIZE = 128

train_ds = Cityscapes(DATA_DIR,
                      split='train',
                      mode='fine',
                      target_type='semantic',
                      transform=transforms.ToTensor()
                      )

train_dl = DataLoader(train_ds,
                      BATCH_SIZE,
                      shuffle=True,
                      num_workers=4,
                      pin_memory=True)


for batch_idx, (data, target) in enumerate(train_dl):
    print(batch_idx, batch_idx.shape)
    print(data, target)
    break

Can you try by setting the target_transform attribute as in

train_ds = Cityscapes(DATA_DIR,
                      split='train',
                      mode='fine',
                      target_type='semantic',
                      transform=transforms.ToTensor(),
                      target_transform=transforms.ToTensor()
                      )

Thank you @user_123454321, it worked.