Now it looks like this:
class Net(nn.Module):
    def __init__(self):
        super(Net, self).__init__()
        self.conv1 = nn.Conv2d(1, 30, 5, 2)
        self.conv2 = nn.Conv2d(30, 50, 5, 1)
        # self.conv3 = nn.Conv2d(30, 50, 5, 1)
        self.dropout = nn.Dropout2d()
        self.fc1 = nn.Linear(5*5*50, 100)
        self.fc2 = nn.Linear(100, 2)
        self.sm = nn.LogSoftmax()

    def forward(self, x):
        x = F.relu(self.conv1(x))
        
        x = F.max_pool2d(x, 2, 2)
        x = F.relu(self.conv2(x))
        x = F.max_pool2d(x, 2, 2)
        #print(x.shape)
        #x = F.relu(self.conv3(x))
        #x = F.max_pool2d(x, 2, 2)
        # print(x.shape)
        x = x.view(-1, 5*5*50)
        x = F.relu(self.fc1(x))
        # x = F.dropout(x, training=self.training)
        x = self.fc2(x)
        #print(x.data.max(), x.data.min() )
        return F.log_softmax(x, dim=1)

class PillDataset(Dataset):
    def __init__(self):
        self.X = []
        self.y = []
        self.transform = transforms.Compose([transforms.RandomAffine(degrees=[-40,40],
                                                                    translate = [0.1,0.1]),
                                            
                                            transforms.RandomHorizontalFlip(p=0.6),
                                             transforms.RandomVerticalFlip(p=0.5),
                                             transforms.Scale(64),
                                             transforms.ToTensor()])

        filenames = os.listdir('./correct/')
        filenames = np.random.choice(filenames, 1000)
        for fn in filenames:
            self.X.append('./correct/'+fn)
            self.y.append([1, 0])
            # self.y.append(1)
        filenames = os.listdir('./defect/')
        for fn in filenames:
            self.X.append('./defect/'+fn)
            self.y.append([0, 1])
            #self.y.append(-1)
    def __getitem__(self, index):
        image = Image.open(self.X[index])
        # image = cv2.Laplacian(image,cv2.CV_64F)
        image = self.transform(image)
        label = torch.tensor(self.y[index])
        return image, label

    def __len__(self):
        return len(self.X)

def train(epoch):
    running_loss = 0.0
    net.train()
    
    for batch_idx, (data, target) in enumerate(train_loader):
        data, target = data.cuda(async=True), target.cuda(async=True)
        data, target = Variable(data), Variable(target)
        optimizer.zero_grad()
        output = net(data)

        loss = F.nll_loss(output, target)
        loss.backward()
        optimizer.step()
        running_loss += loss.item()
        if batch_idx == 0:
            print('Train Epoch: {} [{}]'.format(epoch, running_loss))
            running_loss = 0.0

And shows
RuntimeError: multi-target not supported at c:\programdata\miniconda3\conda-bld\pytorch_1524543037166\work\aten\src\thcunn\generic/ClassNLLCriterion.cu:16