0
点赞
收藏
分享

微信扫一扫

Pytorch中with torch.no_grad()或@torch.no_grad() 用法

MaxWen 2022-03-19 阅读 106

参考Pytorch中with torch.no_grad()或@torch.no_grad() 用法 - 云+社区 - 腾讯云

  • requires_grad=True 要求计算梯度

  • requires_grad=False 不要求计算梯度

  • with torch.no_grad()或者@torch.no_grad()中的数据不需要计算梯度,也不会进行反向传播

model.eval()                                # 测试模式
with torch.no_grad():
   pass
@torch.no_grad()
def eval():
	...

举报

相关推荐

0 条评论