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 中做什么?
基础教程推荐
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 包装空间模型 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 求两个直方图的卷积 2022-01-01
