1 minute read


λ”₯λŸ¬λ‹ λͺ¨λΈμ˜ μ½”λ“œλ₯Ό μ‚΄νŽ΄λ³΄λ‹€ 보면 Evaluation λΆ€λΆ„μ—μ„œ κΌ­ 이런 μ½”λ“œκ°€ λ“±μž₯ν•œλ‹€.

def evaluation(model, criterion, ...):
    model.eval()
    criterion.eval()
    ...

무슨 μ˜λ―ΈμΈμ§€ κΆκΈˆν•΄μ„œ μ°Ύμ•„λ³΄λ‹ˆ, nn.Moduleμ—μ„œ train timeκ³Ό eval timeμ—μ„œ μˆ˜ν–‰ν•˜λŠ” λ‹€λ₯Έ μž‘μ—…μ„ μˆ˜ν–‰ν•  수 μžˆλ„λ‘ switching ν•˜λŠ” ν•¨μˆ˜λΌκ³  ν•œλ‹€. stackoverflow

train timeκ³Ό eval timeμ—μ„œ λ‹€λ₯΄κ²Œ λ™μž‘ν•΄μ•Ό ν•˜λŠ” λŒ€ν‘œμ μΈ μ˜ˆλ“€μ€

  • Dropout Layer
  • BatchNorm Layer

등등이 μžˆλ‹€κ³  ν•œλ‹€.

.eval() ν•¨μˆ˜λŠ” evaluation κ³Όμ •μ—μ„œ μ‚¬μš©ν•˜μ§€ μ•Šμ•„μ•Ό ν•˜λŠ” layer듀을 μ•Œμ•„μ„œ off μ‹œν‚€λ„λ‘ ν•˜λŠ” ν•¨μˆ˜μΈ μ…ˆμ΄λ‹€.

evaluation/validation 과정에선 보톡 model.eval()κ³Ό torch.no_grad()λ₯Ό ν•¨κ»˜ μ‚¬μš©ν•œλ‹€κ³  ν•œλ‹€.

# evaluate model:
model.eval()

with torch.no_grad():
    ...
    out_data = model(data)
    ...

eval/val μž‘μ—…μ΄ λλ‚œ ν›„μ—λŠ” μžŠμ§€λ§κ³  train mode둜 λͺ¨λΈμ„ λ³€κ²½ν•΄μ€˜μ•Ό ν•œλ‹€. 이것은 .train() ν•¨μˆ˜λ₯Ό μ‹€ν–‰μ‹œν‚€λ©΄ λœλ‹€.

# after eval/val, and in training step
model.train()


PyTorch 곡식 λ¬Έμ„œμ—μ„œ .eval()에 λŒ€ν•œ μžμ„Έν•œ λ‚΄μš©μ„ 확인할 수 μžˆλ‹€. nn.Module.eval()

Categories:

Updated: