Why is my classifier not giving me binary results?
I created a linear ReLu network that is supposed to over-fit to my data. I use BCEWithLogisticLoss as the loss function. I was using it to classify 3d points. Since the data were small enough I didn't care to make into batches. And it worked fine. However now that I've implemented batches into it it seems that the predicted values aren't what I expect (i.e 0 or 1) instead it give me numbers like -25.4562 I didn't change anything else from the network only the batches.   

I tried the binary loss function BSELoss however it seems to be a bug in the version of pytorch, so I can't use it. You can take a look at my code below: 


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# We load the training data 
Samples, Ocupancy = common.load_samples()
for i in range(0,Ocupancy.shape[0]):
    if Ocupancy[i] &gt; 1 or Ocupancy[i] &lt; 0:
        print("upsie")

max = np.amax(Samples)
min = np.amin(Samples)

x_test = torch.from_numpy(Samples.astype(np.float32)).to(device)
y_test = torch.from_numpy(Ocupancy.astype(np.float32)).to(device)

train_data = CustomDataset(x_test, y_test)

train_loader = DataLoader(dataset=train_data, batch_size= 22500, shuffle=False) # Batches_size equal to the number of points in each slice 


phi = common.MLP(3, 1).to(device)
criterion = torch.nn.BCEWithLogitsLoss()
optimizer = torch.optim.Adam(phi.parameters(), lr = 0.01)
epoch = 10

fit_start_time = time.time()

for epoch in range(epoch):
    for x_batch, y_batch in train_loader:
        #optimizer.zero_grad()

        x_train = x_batch.to(device)

        y_train = y_batch.to(device)

        y_pred = phi(x_batch)
        print(y_pred)

        # Compute Loss
        loss = criterion(y_pred.squeeze(), y_batch.squeeze())

        print('Epoch {}: train loss: {}'.format(epoch, loss.item()))    # Backward pass

        loss.backward()
        optimizer.step()

fit_end_time = time.time()

print("Total time = %f" % (fit_end_time - fit_start_time))
min = -2
max = 2
resolution = 0.05
X,Y,Z  = np.mgrid[min:max:resolution,min:max:resolution,min:max:resolution] # sample way more

xyz = torch.from_numpy(np.vstack([X.ravel(), Y.ravel(),Z.ravel()]).transpose().astype(np.float32)).to(device)

eval = LabelData(xyz)

eval_loader = DataLoader(dataset=eval, batch_size= 22500, shuffle=False) # Make bigger batches

# feed the network bit by bit?
i = 0
for x_batch in eval_loader:
    phi.eval()
    labels =  phi(x_batch).to(device)
print(labels)

visualization_iso(X,Y,Z,labels)


I expect to the predicted values be 0 or 1, or at least be a probability however it gives me big numbers that I don't understand. Like :19.5953
Please take a look at my code and if you spot any big mistakes please tell me so. I'm really confused since it work quite well before I expanded the size of the data I was using. 

Regards

I might be wrong but I am trying to answer based on your code in the question.

You are using BCEwithlogitsloss which means that the model is expected to output logits. logits are the output just before using the sigmoid activation. Recall, sigmoid activation is used to convert outputs to probability (essentially to be between 0 and 1). Logits can be any real number. 

Based on this, I think you should pass the output of the model through a sigmoid activation i.e. F.sigmoid(phi(x_batch)). Or you can also just check if your model's output is greater than 0 or less than 0. If greater than 0, the label should be 1. 
