PyTorch的ain()有什么⽤?
如有翻译问题欢迎评论指出,谢谢。
马如游龙
wellcome>diecasting⽬录
asked:
它是在 nn.Module ⾥调⽤ forward()?调⽤模型的时候不是会使⽤ forward ⽅法吗,为什么还需要指定⽤ train()?
Answers:
竞选体育委员演讲稿
– vote: 192
更多细节:设置模式以训练(见)。调⽤ model.eval() 或 ain(mode=Fal) 启⽤测试。train 不只⽤来训练,还⽤来测试,区别在于 mode 的不同设置。
译者注:最后⼀句有点看不懂,我按我理解的来,有误请留⾔:It is somewhat intuitive to expect train function to train model but it does not do that. It just ts the mode.
– vote: 75
的源码:
def train(lf, mode=True):
r""“Sets the module in training mode.”""
for module in lf.children():
return lf
的源码:
def eval(lf):
r"""Sets the module in evaluation mode."""
ain(Fal)b c
train 与 eval 是 module 中对⽴的两种模式。
⽬前只有 和 关⼼ lf.training 标志。
bleacher标志默认为 True。斑痕
– vote: 14
设置模型为训练模式,即
· BatchNorm 层利⽤每个 batch 来统计· Dropout 层激活,。
设置模型为评估/推理模式,即
· BatchNorm layers u running statistics
·
step by step观澜英语培训Dropout 层取消。
等效于 ain(Fal)。
注意:每个⽅法都不调⽤前向与后向传递,它们只⽤来告诉模型如何运⾏以及何时运⾏。
这很重要, 在训练与推理时的设计不同,如果运⾏在错误的模式下,会产⽣意料之外的结果。
asked:
Does it call forward() in nn.Module? I thought when we call the model, forward method is being ud. Why do we need to specify train()?
它是在 nn.Module ⾥调⽤ forward()?调⽤模型的时候不是会使⽤ forward ⽅法吗,为什么还需要指定⽤ train()?Answers:
– vote: 192
which behave different on the train and test procedures know what is going on and hence can behave
accordingly.
More details: It ts the mode to train (e ). You can call either model.eval() ain(mode=Fal) 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 ts the mode.
更多细节:设置模式以训练(见)。调⽤ model.eval() 或 ain(mode=Fal) 启⽤测试。train 不只⽤来训练,还⽤来测试,区别在于 mode 的不同设置。
译者注:最后⼀句有点看不懂,我按我理解的来,有误请留⾔:It is somewhat intuitive to expect train function to train model but it does not do that. It just ts the mode.
– vote: 75
Here is the code of :
的源码:
def train(lf, mode=True):
r"""Sets the module in training mode."""
for module in lf.children():
return lf
And here is the .
的源码:
def eval(lf):
r"""Sets the module in evaluation mode."""
ain(Fal)
Modes train and eval are the only two modes we can t the module in, and they are exactly opposite.
train 与 eval 是 module 中对⽴的两种模式。
That\’s just aining flag and currently only and care about that flag.
⽬前只有 和 关⼼ lf.training 标志。
By default, this flag is t to True.
标志默认为 True。
– vote: 14
Sets your model in training
设置模型为训练模式,即
· BatchNorm layers u per-batch statistics · BatchNorm 层利⽤每个 batch 来统计
· Dropout layers activated
· Dropout 层激活,。Sets your model in evaluation (inference)
设置模型为评估/推理模式,即
· BatchNorm layers u running statistics · Dropout layers de-activated etc.
· Dropout 层取消。
Equivalent ain(Fal).
等效于 ain(Fal)。
Note: neither of the function calls run forward / backward pass. They tell the model how to act when run.注意:每个⽅法都不调⽤前向与后向传递,它们只⽤来告诉模型如何运⾏以及何时运⾏。
This is important as (e.g. Dropout, BatchNorm) are designed to behave differently during training vs inference, and hence the model will produce unexpected results if run in the wrong mode.
这很重要, 在训练与推理时的设计不同,如果运⾏在错误的模式下,会产⽣意料之外的结果。