Sorry, I’ll try to explain my previous response:
You mentioned your error is

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

From what I see, the only place you have (possibly problematic) “to” is in
images = images.to(device)

Can you describe “images”?  it appears to be a list, so that gives 2 possible options:


Does this list represent a batch? aka a list of tensor samples? if so, you need to turn this list into a tensor before calling images.to(device)


Does this list represents multiple inputs to forward function?
a.k.a your forward function looks like: forward(self, x1, x2, x3) then you need to do


inputs = [x.to(device) for x in images]
outputs = AE(*inputs)

From the new code you posted, it seems like your model’s forward is forward(self, x) so no multiple inputs, then I guess “images” is a list of samples (a mini-batch), and all you need to do it to turn it to a tensor before calling to(device)
Side note 1:
The collate_fn is an argument to DataLoader class, in the doc 1 it says:

collate_fn  (callable ,  optional ) – merges a list of samples to form a mini-batch of Tensor(s). Used when using batched loading from a map-style dataset.

It is a function you provide to handle the list of samples and turn them into a Tensor batch that your model can get as an input
Side note 2:
The default collate_fn  expects all the images in a batch to have the same size because it uses torch.stack()  to pack the images. If the images provided by Dataset  have variable size, you have to provide your custom collate_fn