What does model.train() do in PyTorch?(model.train() 在 PyTorch 中做什么?)
问题描述
它是否在nn.Module
中调用了forward()
?我想当我们调用模型时,正在使用 forward
方法.为什么需要指定train()?
Does it call forward()
in nn.Module
? I thought when we call the model, forward
method is being used.
Why do we need to specify train()?
推荐答案
model.train()
告诉您的模型您正在训练模型.如此有效的层,如 dropout、batchnorm 等,在训练和测试过程中表现不同,知道发生了什么,因此可以相应地表现.
model.train()
tells your model that you are training the model. So effectively layers like dropout, batchnorm etc. which behave different on the train and test procedures know what is going on and hence can behave accordingly.
更多详情:它设置了训练模式(参见源代码).您可以调用 model.eval()
或 model.train(mode=False)
来告诉您正在测试.期望 train
函数来训练模型有点直观,但它并没有这样做.它只是设置模式.
More details:
It sets the mode to train
(see source code). You can call either model.eval()
or model.train(mode=False)
to tell that you are testing.
It is somewhat intuitive to expect train
function to train model but it does not do that. It just sets the mode.
这篇关于model.train() 在 PyTorch 中做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:model.train() 在 PyTorch 中做什么?


- 我如何卸载 PyTorch? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- 计算测试数量的Python单元测试 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01