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


https://blog.csdn.net/Answer3664/article/details/99460175

  • 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():
	...


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM