I’m training a faster r-cnn object detector and have used the following to produce the loss for validation:
def evaluate_loss(model, data_loader, device):
val_loss = 0
with torch.no_grad():
for images, targets in data_loader:
images = list(image.to(device) for image in images)
targets = [{k: v.to(device) for k, v in t.items()} for t in targets]
losses_dict, detections = eval_forward(model, images, targets)
losses = sum(loss for loss in losses_dict.values())
val_loss += losses
validation_loss = val_loss/ len(data_loader)
return validation_loss
essentially, it sums up all types of losses output and divides this by the number of batches to give me a figure for the epoch.
However, I compared the output of a model that has the lowest validation loss, compared to another model that is output at a later epoch and found that although those models are less “sensitive”, they produce vastly less false positives.
As an FYI, I am using cross entropy loss and finding a few similar sized targets in a 512 x 512 pixel image (binary classification - object + background).
Is there any reason why this might be happening?