Varationale autoencoder

Hi. I’m implementing a varational autoencoder and I used the following code for the training part:

train_loss = 0
for epoch in range(1, NUM_EPOCHS + 1):
for batch_idx, data in enumerate(train_loader):
#data = np.asarray(data)
#data = torch.from_numpy(data.astype(‘long’))
#data = data.detach().numpy()
#data = data.numpy()
#data = torch.FloatTensor(data)
data =
recon_batch, mu, logvar = model(data)

I get the error: ‘list’ object has no attribute ‘to’. How can I fix it? Thank you for your help.

data seems to be a list instead of a tensor so you might need to index it first and call .to() on the tensor(s).

So, I replaced the 4th line with:

for batch_idx, (data, _) in enumerate(train_loader):

and now it doesn’t give me error. Does it make sense?

Yes, this could work as you are not unwrapping the return value from the train_loader.