Hello Ali!
There are several things that are inconsistent in your post.  Let
me propose a question that might be useful for you to ask, and
then try to answer it.
“How do I use BCELoss to perform a binary classification task?”
You say “BCE” in the title of your post, but use
criterion = nn.CrossEntropyLoss() in your code.
Let’s go with BCELoss.



 Aliman:

class Net(nn.Module):
    def __init__(self, n_x, n_h, n_y):
        super(Net, self).__init__()
        self.fc1 = nn.Linear(n_x, n_h)
        self.fc2 = nn.Linear(n_h, n_y)



Further down, you have n_y = 1, so this becomes
        self.fc2 = nn.Linear(n_h, 1)

This is good.  For a binary classification problem, you want your
network to output a single value (per sample in your batch).


        self.sigmoid = nn.Sigmoid()



This is fine.  Your network will output the predicted probability of
your sample being in class “1”.
(But, as an aside, you will be better off, for reasons of numerical
stability, getting rid of the Sigmoid and using BCEWithLogitsLoss
instead of BCELoss.)


        x = torch.transpose(self.sigmoid(x), 0, 1)



This torch.transpose() is asking for trouble.  Get rid of it.


criterion = nn.CrossEntropyLoss()



For a binary classification problem, you should use BCELoss,
not CrossEntropyLoss.  (Or, better, BCEWithLogitsLoss.)


    preds = outputs > 0.5
    nb_correct = (preds == labels).sum()



This makes sense provided labels are binary class labels, that
is a single value of 0 or 1 (per sample in your batch).
What values do your labels take on?


---> 14     loss = criterion(outputs,labels)
...
ValueError: Expected input batch_size (1) to match target batch_size (2).



Well, torch.transpose() would be expected to swap your batch
dimension with some other dimension, so it’s to be expected that
your batch_sizes don’t match.
What do you expect your batch_size to be?
In this code:
    outputs = net(inputs)
...
    loss = criterion(outputs,labels)

please print out .shape for inputs, outputs, and labels.  Are the
shapes what you were expecting?  Do they match what net and
criterion require for their arguments?
Good luck.
K. Frank