torch.nn 没有名为 upsample 的属性

torch.nn has no attribute named upsample

学习本教程:https://www.digitalocean.com/community/tutorials/how-to-perform-neural-style-transfer-with-python-3-and-pytorch#step-2-%E2%80%94-running-your-first-style-transfer-experiment

当我运行 Jupyter notebook 中的示例时,我得到以下信息:

所以,我尝试了故障排除,最终让我按照 github 示例 (https://github.com/zhanghang1989/PyTorch-Multi-Style-Transfer) 对它进行了 运行 调试:[=16] =]

python main.py eval --content-image images/content/venice-boat.jpg --style-image images/21styles/candy.jpg --model models/21styles.model --content-size 1024 --cuda=0

但是,这会产生以下错误:

Traceback (most recent call last):
File "main.py", line 287, in <module>
main()
File "main.py", line 44, in main
evaluate(args)
File "main.py", line 242, in evaluate
stylemodel = Net(ngf=args.ngf)
File "/root/styletransfer/PyTorch-Style-Transfer/experiments/net.py", line 284, in init
model += [upblock(ngf*expansion, 32, 2, normlayer),
File "/root/styletransfer/PyTorch-Style-Transfer/experiments/net.py", line 127, in init
kernelsize=1, stride=1, upsample=stride)
File "/root/styletransfer/PyTorch-Style-Transfer/experiments/net.py", line 167, in init
self.upsamplelayer = torch.nn.Upsample(scalefactor=upsample)
AttributeError: module 'torch.nn' has no attribute 'Upsample'

我不知道如何克服这个问题?

我认为原因可能是您的系统上安装了旧版本的 PyTorch。在我的系统上,pytorch 版本是 0.2.0,torch.nn 有一个名为 Upsample 的模块。

您可以卸载当前版本的pytorch和reinstall it