Reputation: 561
My code is below which I thought would do what I want but the output shows require_grad didn't change to false.
import torch
import torch.nn as nn
encoder = nn.Sequential( nn.Conv2d(1, 4, 1), nn.Sigmoid())
for params in encoder.parameters():
params.require_grad = False
print(params.requires_grad) # prints two True statements?
What am I doing wrong?
Upvotes: 1
Views: 1870
Reputation: 471
You just have a typo :) Simply add an s at the end of grad in params.require_grad = False
Change this to params.requires_grad = False
(note the added s)
Typos can be hard to catch sometimes ;)
Upvotes: 3