Skip to content

Commit

Permalink
Update 1-1,结构化数据建模流程范例.md
Browse files Browse the repository at this point in the history
val/test阶段,添加with torch.no_grad(),关闭梯度计算。
  • Loading branch information
JunnYu authored Jul 5, 2020
1 parent 027aab7 commit 073f9a7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions 1-1,结构化数据建模流程范例.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,11 @@ for epoch in range(1,epochs+1):
val_step = 1

for val_step, (features,labels) in enumerate(dl_valid, 1):

predictions = net(features)
val_loss = loss_func(predictions,labels)
# 关闭梯度计算
with torch.no_grad():
predictions = net(features)
val_loss = loss_func(predictions,labels)

val_metric = metric_func(predictions,labels)

val_loss_sum += val_loss.item()
Expand Down

0 comments on commit 073f9a7

Please sign in to comment.