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