我正在使用此代码,并且model.eval()在某些情况下看到了。
我知道它应该允许我“评估我的模型”,但我不明白什么时候应该和不应该使用它,或者如果关闭如何关闭。
我想运行上面的代码来训练网络,并且还能够在每个时期运行验证。我还是做不到。
此训练代码基于此处找到的run_glue.py脚本:
# Set the seed value all over the place to make this reproducible.
seed_val = 42
random.seed(seed_val)
np.random.seed(seed_val)
torch.manual_seed(seed_val)
torch.cuda.manual_seed_all(seed_val)
# Store the average loss after each epoch so we can plot them.
loss_values = []
# For each epoch...
for epoch_i in range(0, epochs):
# ========================================
# Training
# ========================================
# Perform one full pass over the training set.
print("")
print('======== Epoch {:} / {:} ========'.format(epoch_i + 1, epochs))
print('Training...')
# Measure how long the …Run Code Online (Sandbox Code Playgroud) 该model.eval()方法修改了某些在训练和推理过程中需要表现不同的模块(层)。文档中列出了一些示例:
这仅对某些模块有影响。请参阅特定模块的文档,了解其在培训/评估模式下的行为详细信息(如果它们受到影响),例如
Dropout、BatchNorm等。
是否有受影响模块的详尽列表?
我想知道我可以从running_mean和处running_var拨打电话nn.BatchNorm2d。
示例代码在这里,其中 bn 表示nn.BatchNorm2d。
vector = torch.cat([
torch.mean(self.conv3.bn.running_mean).view(1), torch.std(self.conv3.bn.running_mean).view(1),
torch.mean(self.conv3.bn.running_var).view(1), torch.std(self.conv3.bn.running_var).view(1),
torch.mean(self.conv5.bn.running_mean).view(1), torch.std(self.conv5.bn.running_mean).view(1),
torch.mean(self.conv5.bn.running_var).view(1), torch.std(self.conv5.bn.running_var).view(1)
])
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚Pytorch 官方文档和用户社区中的running_mean和是什么意思。running_var
nn.BatchNorm2.running_mean和是什么nn.BatchNorm2.running_var意思?