Xzzit / neural-style-transfer

modified version of crowsonkb/style-transfer-pytorch
MIT License
1 stars 0 forks source link

Run the code without downloading pre-trained VGG-19 #2

Open usernamexiaoma opened 1 year ago

usernamexiaoma commented 1 year ago

Run the code without downloading pre-trained VGG-19?

Xzzit commented 1 year ago

Could you please provide the error message, if there is any? I am able to run this code without any problems on my machine.

usernamexiaoma commented 1 year ago

您好!我在运行代码时出现的问题是,运行代码时没有自动下载预训练的VGG19_Weights.DEFAULT模型,所以我无法运行代码,您可以提供VGG19模型下载链接吗?下载后应该把它放到那个文件夹下,非常感谢

Xzzit commented 1 year ago

请问您现在的操作系统和pytorch版本是什么呢?这个问题也许是由于国内的防火墙导致的? 另外,如果运行代码有任何报错,能麻烦您把详细的报错内容告诉我吗?

usernamexiaoma commented 1 year ago

您好呀!运行环境为win 10; python 3.8.13; pytorch 1.8.1; 使用魔法后仍然是不行,我认为可能是因为缺少VGG19的预训练权重,可以提供VGG19的百度网盘或者其他网盘下载链接吗?非常感谢!详细的错误信息: sing devices: cpu CPU threads: 2 Loading model... Traceback (most recent call last): File "F:/neural-style-transfer-master/stylize.py", line 193, in main() File "F:/neural-style-transfer-master/stylize.py", line 178, in main st = StyleTransfer(devices=devices, pooling=args.pooling) File "F:/-neural-style-transfer-master\style_transfer.py", line 271, in init self.model = VGGFeatures(self.style_layers + self.content_layers, pooling=pooling) File "F:/-neural-style-transfer-master\style_transfer.py", line 32, in init self.model = models.vgg19(weights='VGG19_Weights.DEFAULT').features[:self.layers[-1] + 1] File "C:.conda\envs\My_PyTorch\lib\site-packages\torchvision\models\vgg.py", line 179, in vgg19 return _vgg('vgg19', 'E', False, pretrained, progress, kwargs) File "C:.conda\envs\My_PyTorch\lib\site-packages\torchvision\models\vgg.py", line 97, in _vgg model = VGG(make_layers(cfgs[cfg], batch_norm=batch_norm), kwargs) TypeError: init() got an unexpected keyword argument 'weights'

Xzzit commented 1 year ago

同学您好! 这个报错看起来像是vgg19的定义和加载的模型定义不一样,我觉得大概率是pytorch版本的问题导致的,您可以尝试一下使用pytorch1.13版本

VGG19的下载链接在这里:https://pan.baidu.com/s/1-AyHuTESjwveboW1u6n2pQ?pwd=yx8b,提取码为:yx8b 然后,在windows下,模型默认是放在:C:\Users\User_Name\.cache\torch\hub\checkpoints\vgg19-dcbb9e9d.pth 进行以上错做后,代码应该可以正常运行

如果代码还是出现错误,您可以用以下这个代码调用该模型:

model = models.vgg19(pretrained=False)
model.load_state_dict(torch.load('path/to/vgg_19_model'))

如果有什么问题,请让我知道~

usernamexiaoma commented 1 year ago

您好!代码调试运行成功了,使用examples示例里面的内容图和梵高星空风格进行测试,但生成的结果图很不理想,请问这是什么原因呢?

Xzzit commented 1 year ago

可以把生成结果发着这里吗?我看看是什么样子的。

usernamexiaoma commented 1 year ago

out2