I changed code, but I still have only 49%
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from torchvision.datasets import ImageFolder
from collections import namedtuple
from torch.utils.data import DataLoader
import torch
from torch.autograd import Variable
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torchvision import datasets, transforms


Params = namedtuple('Params', ['batch_size', 'test_batch_size', 'epochs', 'lr', 'momentum', 'seed', 'cuda', 'log_interval'])
args = Params(batch_size=64, test_batch_size=1000, epochs=10, lr=0.01, momentum=0.5, seed=1, cuda=False, log_interval=200)



data = ImageFolder(root='img-train', transform= transforms.ToTensor())
data2 = ImageFolder(root='img-valid', transform= transforms.ToTensor())
train_loader = DataLoader(data)
test_loader = DataLoader(data2)
classes = ('before', 'after')


class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(3, 10, kernel_size=5)
        self.conv2 = nn.Conv2d(10, 20, kernel_size=5)
        self.conv2_drop = nn.Dropout2d()
        self.fc1 = nn.Linear(7920, 50)
        self.fc2 = nn.Linear(50, 2)

    def forward(self, x):
        x = F.relu(F.max_pool2d(self.conv1(x), 2))
        x = F.relu(F.max_pool2d(self.conv2_drop(self.conv2(x)), 2))
        x = x.view(-1, 7920)
        x = F.relu(self.fc1(x))
        x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        return F.log_softmax(x)
      
model = Net()
model.share_memory() # gradients are allocated lazily, so they are not shared here
def train_epoch(epoch, args, model, data_loader, optimizer):
    model.train()
    for batch_idx, (data, target) in enumerate(data_loader):
        if args.cuda:
            data, target = data.cuda(), target.cuda()      
        data, target = Variable(data), Variable(target)
        optimizer.zero_grad()
        output = model(data)
        loss = F.nll_loss(output, target)
        loss.backward()
        optimizer.step()
        if batch_idx % args.log_interval == 0:
            print('Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}'.format(
                epoch, batch_idx * len(data), len(data_loader.dataset),
                100. * batch_idx / len(data_loader), loss.data[0]))


def test_epoch(model, data_loader):
    model.eval()
    test_loss = 0
    correct = 0
    for data, target in data_loader:
        if args.cuda:
            data, target = data.cuda(), target.cuda()      
        data, target = Variable(data, volatile=True), Variable(target)
        output = model(data)
        test_loss += F.nll_loss(output, target, size_average=False).data[0] # sum up batch loss
        pred = output.data.max(1)[1] # get the index of the max log-probability
        correct += pred.eq(target.data).cpu().sum()

    test_loss /= len(data_loader.dataset)
    print('\nTest set: Average loss: {:.4f}, Accuracy: {}/{} ({:.0f}%)\n'.format(
        test_loss, correct, len(data_loader.dataset),
        100. * correct / len(data_loader.dataset)))


# Run the training loop over the epochs (evaluate after each)
if args.cuda:
    model = model.cuda()
optimizer = optim.SGD(model.parameters(), lr=args.lr, momentum=args.momentum)
for epoch in range(1, args.epochs + 1):
    train_epoch(epoch, args, model, train_loader, optimizer)
    test_epoch(model, test_loader)    

and output:
Train Epoch: 1 [0/2510 (0%)]    Loss: 0.730912
Train Epoch: 1 [200/2510 (8%)]  Loss: 0.000000
Train Epoch: 1 [400/2510 (16%)] Loss: 0.393666
Train Epoch: 1 [600/2510 (24%)] Loss: 0.000000
Train Epoch: 1 [800/2510 (32%)] Loss: 0.000000
Train Epoch: 1 [1000/2510 (40%)]        Loss: 0.000000
Train Epoch: 1 [1200/2510 (48%)]        Loss: 0.000000
Train Epoch: 1 [1400/2510 (56%)]        Loss: 0.000161
Train Epoch: 1 [1600/2510 (64%)]        Loss: 0.000000
Train Epoch: 1 [1800/2510 (72%)]        Loss: 0.000000
Train Epoch: 1 [2000/2510 (80%)]        Loss: 0.000028
Train Epoch: 1 [2200/2510 (88%)]        Loss: 0.002456
Train Epoch: 1 [2400/2510 (96%)]        Loss: 0.000000

Test set: Average loss: 13.5654, Accuracy: 128/259 (49%)