A context where the model is temporarily changed to eval mode, and restored to previous mode afterwards. Args: model: a torch Module
(model)
| 183 | |
| 184 | @contextmanager |
| 185 | def inference_context(model): |
| 186 | """ |
| 187 | A context where the model is temporarily changed to eval mode, |
| 188 | and restored to previous mode afterwards. |
| 189 | |
| 190 | Args: |
| 191 | model: a torch Module |
| 192 | """ |
| 193 | training_mode = model.training |
| 194 | model.eval() |
| 195 | yield |
| 196 | model.train(training_mode) |
no test coverage detected