PyTorch-Multi-Style-Transfer icon indicating copy to clipboard operation
PyTorch-Multi-Style-Transfer copied to clipboard

vgg16.t7 unhashable type: 'numpy.ndarray

Open Gavin-Evans opened this issue 5 years ago • 13 comments

hi

I have put the vgg16.t7 into models folder, it's been detected correctly. However, the following problem happened.

Traceback (most recent call last): File "main.py", line 295, in main() File "main.py", line 41, in main train(args) File "main.py", line 135, in train utils.init_vgg16(args.vgg_model_dir) File "C:\Users\user\Prepwork\Cap Project\PyTorch-Multi-Style-Transfer\experiments\utils.py", line 100, in init_vgg16 vgglua = load_lua(os.path.join(model_folder, 'vgg16.t7')) File "C:\Users\user\anaconda3\envs\FTDS\lib\site-packages\torchfile.py", line 424, in load return reader.read_obj() File "C:\Users\user\anaconda3\envs\FTDS\lib\site-packages\torchfile.py", line 370, in read_obj obj._obj = self.read_obj() File "C:\Users\user\anaconda3\envs\FTDS\lib\site-packages\torchfile.py", line 385, in read_obj k = self.read_obj() File "C:\Users\user\anaconda3\envs\FTDS\lib\site-packages\torchfile.py", line 386, in read_obj v = self.read_obj() File "C:\Users\user\anaconda3\envs\FTDS\lib\site-packages\torchfile.py", line 370, in read_obj obj._obj = self.read_obj() File "C:\Users\user\anaconda3\envs\FTDS\lib\site-packages\torchfile.py", line 387, in read_obj obj[k] = v TypeError: unhashable type: 'numpy.ndarray'

It does't work for pytorch-1.0.0 and 1.4.0, and giving the same error, how to deal with it? thanks !

Gavin-Evans avatar Aug 05 '20 09:08 Gavin-Evans

The VGG model is no longer compatible with recent PyTorch version, but you can still use the pretrained MSG-Net.

zhanghang1989 avatar Aug 05 '20 17:08 zhanghang1989

hello, I deal with above problem by loading vgg16.pth that convert the pretrained caffe model of vgg16 to pytorch vgg16.pth,

however, geting the following problem.

Traceback (most recent call last): File "main.py", line 299, in main() File "main.py", line 44, in main train(args) File "main.py", line 165, in train style_v = utils.subtract_imagenet_mean_batch(style_v) File "/home/alg/CNN_Style_Transfers/PyTorch-Multi-Style-Transfer/experiments/utils.py", line 68, in subtract_imagenet_mean_batch return batch - Variable(mean) RuntimeError: expected device cuda:0 but got device cpu

how to deal with? thanks.

Gavin-Evans avatar Aug 07 '20 09:08 Gavin-Evans

Looks like just cpu and gpu mismatch.

You may fix that easily, similar to x = x.gpu()

zhanghang1989 avatar Aug 07 '20 18:08 zhanghang1989

thank you for your ideal!

I solve the problem. check the device's type of mean and batch by printing , I found that mean'data is caculated on CPU and batch'data on GPU. so, It works by modifying batch - Variable(mean) to batch - Variable(mean).cuda(0)

Gavin-Evans avatar Aug 11 '20 08:08 Gavin-Evans

Thanks for the feedback! Could you send a PR to fix it?

zhanghang1989 avatar Aug 11 '20 16:08 zhanghang1989

of course

However, the speed is very slow when I run the modified code, as follow:

Wed Aug 12 16:04:44 2020 Epoch 1: [2000/123287] content: 1.976768 style: 13.847776 total: 15.824544: 0%|
Wed Aug 12 16:08:23 2020 Epoch 1: [4000/123287] content: 1.926269 style: 10.780033 total: 12.706302: 0%|

Don't understand why,What is your speed during training?

Gavin-Evans avatar Aug 12 '20 08:08 Gavin-Evans

Shouldn't be that slow. Something may be wrong.

zhanghang1989 avatar Aug 12 '20 15:08 zhanghang1989

The VGG model is no longer compatible with recent PyTorch version, but you can still use the pretrained MSG-Net.

How do you "Train Your Own MSG-Net Model" then? When i follow instructions, the VGG model is needed. How can I train my own MSG-Net Model without VGG model? Using .pth instead isn't working with the provided code. Throws T7ReaderException.

Can you give some advices? I'm new to this topic and appreciate your help!

sprony avatar Sep 26 '20 15:09 sprony

This code was written in early stage of PyTorch. Now you may use the official VGG-Net at https://pytorch.org/hub/pytorch_vision_vgg/

zhanghang1989 avatar Sep 26 '20 15:09 zhanghang1989

This code was written in early stage of PyTorch. Now you may use the official VGG-Net at https://pytorch.org/hub/pytorch_vision_vgg/

thank you, I rewrote the method of loading the VGG pre-trained model, now I am optimizing training speed and improving image generation quality

Gavin-Evans avatar Oct 10 '20 07:10 Gavin-Evans

The VGG model is no longer compatible with recent PyTorch version, but you can still use the pretrained MSG-Net.

I can't find pretrained MSG-Net model. How to download this model??

ppjh8263 avatar Dec 21 '20 18:12 ppjh8263

https://github.com/zhanghang1989/PyTorch-Multi-Style-Transfer/blob/master/experiments/models/download_model.sh#L2

zhanghang1989 avatar Dec 21 '20 18:12 zhanghang1989

Run it on GPU. I meet this problem when I run the code on CPU.

JudyCodes321 avatar May 07 '21 08:05 JudyCodes321