From 2a9cee6bd76398bce2d5c7ec3679e669c5c5149c Mon Sep 17 00:00:00 2001 From: Suhas-G Date: Wed, 31 May 2023 23:21:23 +0200 Subject: [PATCH] Add model.eval() in neural_style_tutorial.py --- advanced_source/neural_style_tutorial.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/advanced_source/neural_style_tutorial.py b/advanced_source/neural_style_tutorial.py index 3d84fc508bc..54085fb1e98 100644 --- a/advanced_source/neural_style_tutorial.py +++ b/advanced_source/neural_style_tutorial.py @@ -423,6 +423,9 @@ def run_style_transfer(cnn, normalization_mean, normalization_std, # We want to optimize the input and not the model parameters so we # update all the requires_grad fields accordingly input_img.requires_grad_(True) + # We also put the model in evaluation mode, so that specific layers + # such as dropout or batch normalization layers behave correctly. + model.eval() model.requires_grad_(False) optimizer = get_input_optimizer(input_img)