Thank you so so much, I did tried that  but now I am getting below error
RuntimeError: size mismatch, m1: [36480 x 154], m2: [70224 x 20000] at /Users/distiller/project/conda/conda-bld/pytorch_1579022061893/work/aten/src/TH/generic/THTensorMath.cpp:136
Code:
class autoencoder(nn.Module):
def __init__(self):
    
    super(autoencoder, self).__init__()
    self.encoder = nn.Sequential(
        nn.Conv2d(1, 6,stride = 1,kernel_size=5),  
        nn.ReLU(True),
        nn.MaxPool2d(2,2),  
        nn.Conv2d(6, 16,stride = 1,kernel_size=5),
        nn.ReLU(True),
        nn.Linear(16 *57*77, 20000),
        nn.Linear(20000, 14000),
        nn.Linear(14000,2000),
    )
    self.decoder = nn.Sequential(
        nn.Flatten(),
        nn.Linear(2000,14000),
        nn.Linear(14000,20000),
        
    )

def forward(self, x):
   
    x = self.encoder(x)
   # x = x.unsqueeze(1)
   # print(x.size())
    x = self.decoder(x)
   # print(x.size())
    return x

model = autoencoder()
criterion = nn.CrossEntropyLoss()
optimizer = torch.optim.Adam(model.parameters(), lr=0.005,
weight_decay=1e-5)
for epoch in range(2):
for i, data in enumerate(traindataloader,0):
    img, labels = data
    optimizer.zero_grad()
    print(img.size())
    img = Variable(img)
    # ===================forward=====================
    output = model(img)
    loss = criterion(output, img)
    # ===================backward====================
    
    loss.backward()
    optimizer.step()
   #===================log========================
    running_loss += loss.item()

    if i % 10 == 0:  
        # print every 2000 mini-batches
        print('[%d, %5d] loss: %.3f' %
              (epoch + 1, i + 1, running_loss / 10))
        running_loss = 0.0

print(‘Finished Training’)