When using a pretrained model ‘resnet18’ to train images with torch.optim.Adam, the system said:
Traceback (most recent call last):
File “”, line 1, in 
File “/root/anaconda2/lib/python2.7/site-packages/torch/optim/adam.py”, line 54, in step
beta1, beta2 = group[‘betas’]
TypeError: ‘float’ object is not iterable
The test codes were written as follows:
lr=0.9
momentum = 1e-4
weight_decay= 0.1
model = models.resnet18(pretrained=True)
optimizer = torch.optim.Adam(model.parameters(),lr,momentum,weight_decay)
output =model(torch.autograd.Variable(torch.ones(1,3,224,224)))
yt = torch.autograd.Variable((torch.ones(1)).long())
criterion = torch.nn.CrossEntropyLoss ()
loss = criterion(output, yt)
loss.backward()
optimizer.step()
If using torch.optim.SGD instead of Adam, the codes work. However, I guessed Adam would give better performance in some cases, and thus tried to use Adam algorithm.
I have read the original codes and searched some related webpages like https://github.com/pytorch/pytorch/blob/master/docs/source/notes/extending.rst 7. Unfortunately,
It is still confusing for me to correctly use the input parameter group of Adam optimizer in this situation.
Would you mind give an example of using the Adam optimizer? Thank you Adam O(∩_∩)O