lxztju / pytorch_classification

利用pytorch实现图像分类的一个完整的代码,训练,预测,TTA,模型融合,模型部署,cnn提取特征,svm或者随机森林等进行分类,模型蒸馏,一个完整的代码
MIT License
1.38k stars 338 forks source link

ValueError: optimizer got an empty parameter list #29

Open kk701710 opened 3 years ago

kk701710 commented 3 years ago

...... Initialize the network done!!! ....... Traceback (most recent call last): File "/home/jiannan/project/pytorch_classification-master/train.py", line 76, in optimizer = optim.Adam(filter(lambda p: p.requires_grad, model.parameters()), lr=cfg.LR) File "/home/jiannan/anaconda3/envs/pt-gpu/lib/python3.6/site-packages/torch/optim/adam.py", line 42, in init super(Adam, self).init(params, defaults) File "/home/jiannan/anaconda3/envs/pt-gpu/lib/python3.6/site-packages/torch/optim/optimizer.py", line 46, in init raise ValueError("optimizer got an empty parameter list") ValueError: optimizer got an empty parameter list 这个问题要怎么解决???

WhyFear commented 3 years ago

你好,请问你解决了吗?我是在用densenet的时候出现了和你一样的问题。


我弄好了,把优化器改成SGD,然后在loss = criterion(out, labels.long())这一行的下面添加: loss.requiresgrad(True) 就能正常跑起来了。