admin管理员组

文章数量:1287523

I am new to pytorch and torchvision.

Apparently, the __call__ method of a model returns different things if they are on train mode or not. The first case returns the loss, the second returns the outputs.

This is quite bothersome for two reasons:

  1. I need to do very strange things to compute the validation loss to plot the history as one will do with TF,
    • either I have a big error if I have layers like dropout or batch norm
    • or using a function of 100 lines of code.

source: .

  1. Also, if I want to use torchmetrics with the train data, I need to change to eval and send again the train_dataloader. Seems like a waste of computation time.

Is this indeed the case? Otherwise, how can I do this two things using best practices? My code looks quite messy with all this.

I am new to pytorch and torchvision.

Apparently, the __call__ method of a model returns different things if they are on train mode or not. The first case returns the loss, the second returns the outputs.

This is quite bothersome for two reasons:

  1. I need to do very strange things to compute the validation loss to plot the history as one will do with TF,
    • either I have a big error if I have layers like dropout or batch norm
    • or using a function of 100 lines of code.

source: https://stackoverflow/a/71315672/5931672.

  1. Also, if I want to use torchmetrics with the train data, I need to change to eval and send again the train_dataloader. Seems like a waste of computation time.

Is this indeed the case? Otherwise, how can I do this two things using best practices? My code looks quite messy with all this.

Share Improve this question asked Feb 24 at 10:17 J Agustin BarrachinaJ Agustin Barrachina 4,1003 gold badges42 silver badges67 bronze badges 1
  • What version of torchvision are you using? Looking at the code for rcnn for example it seems to return losses so long as targets are passed – Karl Commented Feb 24 at 19:23
Add a comment  | 

1 Answer 1

Reset to default 0

Ok, apparently I'm not the only one to think this is not good, and many others had the same issue:

  • Add an option for Dection Models to return cost in eval mode as well (validation, test loss) · Issue #1574
  • [models] Suggestion of GeneralizedRCNN forward output · Issue #1775
  • Calculate Training Accuracy on resnet152 · Issue #2578

本文标签: pytorchtrain and validation metrics and loss using torchvisionStack Overflow