1. 报错
在安装pytorch后跑代码,遇到报错:
AttributeError: module ‘torch.nn’ has no attribute ‘ModuleDict’
2. 查找原因
按照提示查看 torch.nn接口文档,发现原来版本的pytorch中的确没有这个模块,二0.4.0版本的pytorch中的torch.nn接口有ModuleDict模块
0.4.0文档链接:https://pytorch.org/docs/0.4.0/nn.html
3. 问题解决
解决方法:卸载并重装pytorch
pip unstall pytorch ## 卸载
conda install pytorch torchvision -c soumith ## 自动安装最新版本的pytorch和torchvision