I am trying to implement a simple autoencoder using pytorch. My dataset consists of 256X256X3 images. I have built a data loader. When I run the autoencoder, I get a runtime error:
size mismatch, m1: [76800 x 256], m2: [784 x 128] at /Users/soumith/minicondabuild3/conda-bld/pytorch_1518371252923/work/torch/lib/TH/generic/THTensorMath.c:1434
These are my hyper-parameters:
batch_size=100
learning_rate = 1e-3
num_epochs = 100
Following is the architecture of my auto-encoder:
class autoencoder(nn.Module):
    def __init__(self):
        super(autoencoder, self).__init__()
        self.encoder = nn.Sequential(
            nn.Linear(3*256*256, 128),
            nn.ReLU(),
            nn.Linear(128, 64),
            nn.ReLU(True), nn.Linear(64, 12), nn.ReLU(True), nn.Linear(12, 3))
        self.decoder = nn.Sequential(
            nn.Linear(3, 12),
            nn.ReLU(True),
            nn.Linear(12, 64),
            nn.ReLU(True),
            nn.Linear(64, 128),
            nn.Linear(128, 3*256*256),
            nn.ReLU())

    def forward(self, x):
        x = self.encoder(x)
        #x = self.decoder(x)
        return x
This is the code I used to run my model :


for epoch in range(num_epochs):
for data in dataloader:
img = data[‘image’]
img = Variable(img)
# ===================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 = show_img(output.cpu().data)
save_image(pic, ‘./dc_img/image_{}.jpg’.format(epoch))
torch.save(model.state_dict(), ‘./conv_autoencoder.pth’)
Can someone help me in understanding what's the issue ?