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