Cant use pin_memory in custom dataset

Hi, the custom dataset is a dictionary and I use a custom collate_fn for Dataloader. when the pin_memory =False, the code was run correct, but when I set pin_memory=True, I faced with this error:

attributeerror: ‘dict’ object has no attribute ‘to’

this error was occurred when data was transferred to device

for i, data in enumerate(loader, 1):
if self.move_data_to_gpu:
data = data.to(self.device)

How can I resolve this error?