I am trying to use the torch vision.detection.keypointrcnn model in Pytorch Lightning.
The model returns a dictionary of losses in training mode,
loss_dict = model(images, targets).
I would like the model to return the validation loss in the validation step, but I am getting predictions instead of the losses. Should I implement the loss myself?
yes, you have to or you can check how it’s been done inside vision.detection.keypointrcnn code . I’d suggest calculating loss yourself in training_step too to make it more explainable.
the reason is in validation_step the model is set to eval mode and self.training becomes False, so it doesn’t return losses in validation_step. There is no way around for that, you need to change the code. Either update the model as suggested in the link you shared or copy the code to calculate the loss under validation_step to get losses.