# What does "model.training" in the transfer learning tutorial mean?

**URL:** <https://discuss.pytorch.org/t/what-does-model-training-in-the-transfer-learning-tutorial-mean/82182>\
**Category:** vision\
**Created:** [May 20, 2020, 1:45pm UTC](https://discuss.pytorch.org/t/what-does-model-training-in-the-transfer-learning-tutorial-mean/82182 "2020-05-20T13:45:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zy\_D](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zy_d/32/24521_2.png) [@zy\_D](https://discuss.pytorch.org/u/zy_D)\
**Post date:** [May 20, 2020, 1:45pm UTC](https://discuss.pytorch.org/t/what-does-model-training-in-the-transfer-learning-tutorial-mean/82182/1 "2020-05-20T13:45:04Z")

</div>

Hi everyone,

I’m a beginner of Pytorch and I’m reading the transfer learning for computer vision tutorial on the pytorch website. (Link below) I failed to understand the code in the visualization part “was\_training = model.training”. Is it defined in the ResNet init function? Where can I check it? Thank you in advance!

Tutorial link: [Transfer Learning for Computer Vision Tutorial — PyTorch Tutorials 2.2.0+cu121 documentation](https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html)

 ![)C@IC(CFT@3U0)EPFEERPWE](https://discuss.pytorch.org/uploads/default/original/3X/3/1/31be892b601c4bb8ad4af76355d376b0fa7dc347.png)

---

<div class="post-metadata">

**Author:** ![zy\_D](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zy_d/32/24521_2.png) [@zy\_D](https://discuss.pytorch.org/u/zy_D)\
**Post date:** [May 20, 2020, 2:50pm UTC](https://discuss.pytorch.org/t/what-does-model-training-in-the-transfer-learning-tutorial-mean/82182/2 "2020-05-20T14:50:32Z")

</div>

Can someone help me?

---

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [May 21, 2020, 9:04am UTC](https://discuss.pytorch.org/t/what-does-model-training-in-the-transfer-learning-tutorial-mean/82182/3 "2020-05-21T09:04:59Z")

</div>

All `nn.Module`s have an internal `training` attribute, which is changed by calling `model.train()` and `model.eval()` to switch the behavior of the model, if necessary.  
E.g. it is used in dropout layers to disable them during evaluation.

The `was_training` variable stores the current training state of the model, calls `model.eval()`, and resets the state at the end using `model.train(training=was_training)`.

---

<div class="post-metadata">

**Author:** ![zy\_D](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zy_d/32/24521_2.png) [@zy\_D](https://discuss.pytorch.org/u/zy_D)\
**Post date:** [May 21, 2020, 9:29am UTC](https://discuss.pytorch.org/t/what-does-model-training-in-the-transfer-learning-tutorial-mean/82182/4 "2020-05-21T09:29:06Z")

</div>

Thank you so much for the excellent explanation!
