Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Does model.eval() placement matter in the code?

Might be a bit silly but I need to make sure this is correct. Does it matter if I place my code like this?:

model.eval()
with torch.no_grad():

Or can I get the same behaviour like this:

with torch.no_grad():
    model.eval()

I’m just wondering because I have a function that has model.eval() inside of it which goes inside of a loop where with torch.no_grad(): is before it …

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

both of them are correct, you just need to use the model. eval() Before you explore,

you should put the model in eval mode, both in general and so that batch norm
doesn’t cause you issues and is using its eval statistics

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading