Optimizing an Autoencoder NN in pytorch , dimension problem

Hi all
I am trying to optimize a 1D auto-encoder neural network. My batch size is 65536, and length of my signal is 94.
I used this code to optimizing my parameters:
/////////////////////////////////////////////////////////////////////////////////////////////
for epoch in range(num_epochs):
for data in y:
img, _ = data
img = Variable(img).cpu()
# ===================forward=====================
output = model(img)
loss = criterion(output, img)
# ===================backward====================
optimizer.zero_grad()
loss.backward()
optimizer.step()
# ===================log========================
print(‘epoch [{}/{}], loss:{:.4f}’
.format(epoch+1, num_epochs, loss.data[0]))
if epoch % 10 == 0:
pic = to_img(output.cpu().data)
save_image(pic, ‘./dc_img/image_{}.png’.format(epoch))

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

above y is my data set which is a tensor with dimension of [65536,1,94]. as I mentioned before, 65536 is my batch size, 1 is number of channel and 94 is length of my signal,
when I run the code, this error appeared:

ValueError: not enough values to unpack (expected 2, got 1)

has anyone any idea?

Thanks a lot

It seems your data is not a tuple you could unpack:

img, _ = data

Could you check the size and type of data?

1 Like

Hi
Thank you for your answer. Actually my data set is a 1d signal that has 65536 sample (batch number). Its one channel.
I edited my codes to the below, how ever I still get error.
#training loop
for epoch in range(num_epochs):
for data in (data_pixel2.shape[0]):
img = data
img = Variable(img).cpu()
# ===================forward=====================
output = model(img)
loss = criterion(output, img)
# ===================backward====================
optimizer.zero_grad()
loss.backward()
optimizer.step()
# ===================log========================
print(‘epoch [{}/{}], loss:{:.4f}’
.format(epoch+1, num_epochs, loss.data[0]))
if epoch % 10 == 0:
pic = to_img(output.cpu().data)
save_image(pic, ‘./dc_img/image_{}.png’.format(epoch))

/////////////////////////////////////////////////////////////////////////////////

data_pixel2 is a tensor size of [65536,1,94], that the first number indicates batch number and 1 means channel, and 94 means length of my signal.
Main reason of writing these codes was building an 1d autoencoder. However even I can’t run training loop :frowning: