在validation阶段为什么不使用model.eval()
Ponytai1j opened this issue · 1 comments
Ponytai1j commented
大大好看见您最近上线了想问下这个问题。实在没搞明白,既然模型使用了dropout,BN,为什么只在推理阶段使用model.eval(),在validation阶段为什么不开model.eval()
def val(net, data_loader, device='cpu', supervision='full'):
accuracy, total = 0., 0.
ignored_labels = data_loader.dataset.ignored_labels
for batch_idx, (data, target) in enumerate(data_loader):
with torch.no_grad():
# Load the data into the GPU if required
data, target = data.to(device), target.to(device)
if supervision == 'full':
output = net(data)
elif supervision == 'semi':
outs = net(data)
output, rec = outs
_, output = torch.max(output, dim=1)
#target = target - 1
for pred, out in zip(output.view(-1), target.view(-1)):
if out.item() in ignored_labels:
continue
else:
accuracy += out.item() == pred.item()
total += 1
return accuracy / total`
eecn commented
是需要加上的^_^.