how to get val loss CNN Pytorch Output 1 (Sigmoid) Output Layer Criterion = BCELoss()
I don’t quite understand the question, so could you provide more information, please?
The loss would be generally given as the output of a criterion (nn.BCELoss
in this case).
def loss(self, model, criterion, X_batch, y_batch):
preds = model(X_batch.view(-1, 3, 84, 84).float().to(device))
loss = criterion(
preds.view(-1, 1).float().to(“cpu”).float(),
y_batch.view(-1, 1).float().to(“cpu”).float(),
)
loss = loss.item()
return loss
I am getting my loss like above is this way correct if not what is the correct way thank you.
loss.item()
will return a Python scalar value, which is detached from the computation graph.
If you want to use this loss for training, you should remove this line of code.
Also, I’m unsure why you need to push the preds
and y_batch
, to the CPU, but I’m also not familiar with your use case, so you should double check if this is needed.
OK thank you so much