naoto0804 / pytorch-AdaIN

Unofficial pytorch implementation of 'Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization' [Huang+, ICCV2017]
MIT License
1.08k stars 208 forks source link

About converting the models for Torch to the models for PyTorch #21

Closed SuhyeonHa closed 5 years ago

SuhyeonHa commented 5 years ago

When I type this command, python torch_to_pytorch.py --model models/vgg_normalised.t7

It produces errors as below.

Traceback (most recent call last):
  File "torch_to_pytorch.py", line 321, in <module>
    torch_to_pytorch(args.model, args.output)
  File "torch_to_pytorch.py", line 266, in torch_to_pytorch
    model = load_lua(t7_filename, unknown_classes=True)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 608, in load_lua
    return reader.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 593, in read
    return self.read_object()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 546, in read_object
    return reader_registry[cls_name](self, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 243, in read_nn_class
    attributes = reader.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 595, in read
    return self.read_table()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 571, in read_table
    k = self.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 595, in read
    return self.read_table()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 572, in read_table
    v = self.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 593, in read
    return self.read_object()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 546, in read_object
    return reader_registry[cls_name](self, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 318, in wrapper
    obj = build_fn(reader, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 318, in wrapper
    obj = build_fn(reader, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 243, in read_nn_class
    attributes = reader.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 595, in read
    return self.read_table()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 573, in read_table
    table[k] = v
TypeError: unhashable type: 'list'

Also If I type the next line, python torch_to_pytorch.py --model models/decoder.t7

It shows like this.

Traceback (most recent call last):
  File "torch_to_pytorch.py", line 321, in <module>
    torch_to_pytorch(args.model, args.output)
  File "torch_to_pytorch.py", line 266, in torch_to_pytorch
    model = load_lua(t7_filename, unknown_classes=True)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 608, in load_lua
    return reader.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 593, in read
    return self.read_object()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 546, in read_object
    return reader_registry[cls_name](self, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 243, in read_nn_class
    attributes = reader.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 595, in read
    return self.read_table()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 571, in read_table
    k = self.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 595, in read
    return self.read_table()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 572, in read_table
    v = self.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 593, in read
    return self.read_object()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 546, in read_object
    return reader_registry[cls_name](self, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 318, in wrapper
    obj = build_fn(reader, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 318, in wrapper
    obj = build_fn(reader, version)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 243, in read_nn_class
    attributes = reader.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 595, in read
    return self.read_table()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 523, in wrapper
    result = fn(self, *args, **kwargs)
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 572, in read_table
    v = self.read()
  File "C:\Users\a\Anaconda3\envs\AdaIN_env\lib\site-packages\torch\utils\serialization\read_lua_file.py", line 598, in read
    "corrupted.".format(typeidx))
torch.utils.serialization.read_lua_file.T7ReaderException: unknown type id -1050704824. The file may be corrupted.

It will be so thankful if you reply to the issue. :)

naoto0804 commented 5 years ago

I haven't seen such issue before. Just to make sure, which PyTorch version are you using? (c.f., #20 ) I recommend to use 0.4.1 for this repo.

SuhyeonHa commented 5 years ago

I used Windows10, WSL(Windows Subsystem for Linux) and PyTorch 0.4.1.

ArturoDeza commented 5 years ago

I've been having the same problem. Can someone upload a direct link to the converted models so that we can run the code with PyTorch 1.1?

Serbernari commented 5 years ago

And same problem again, still no solution?

naoto0804 commented 5 years ago

@SuhyeonHa I don't have windows environment, so I cannot test it, sorry.

For convenience, I share the converted version of the models (vgg_normalized.pth/decoder.pth). Please try it and let me know if something wrong happened. (There might need some modifications for exporting 0.4 to 1.0 or 1.1, but I don't have enough time to test it all)

sunyuxiu commented 2 years ago

@naoto0804 Hi, thanks for the excellent work! But could you please release the models ([vgg_normalised.pth, decoder.pth]) on OneDrive, too? I can't download the google or dropbox link in China... Thanks very much!

naoto0804 commented 2 years ago

@sunyuxiu OK, can you tell me the email address to send the link?

naoto0804 commented 2 years ago

Hmm, I'm using my company's OneDrive, and it does not allow me to share the link to addresses ended with qq.com; do you have another address?

naoto0804 commented 2 years ago

It does not work; wait a moment, I'll host a server temporarily

sunyuxiu commented 2 years ago

@naoto0804 OK.Thank you!

naoto0804 commented 2 years ago

https://www.hal.t.u-tokyo.ac.jp/~inoue/projects/tmp/decoder.pth https://www.hal.t.u-tokyo.ac.jp/~inoue/projects/tmp/vgg_normalized.pth

naoto0804 commented 2 years ago

@sunyuxiu Let me know when you finish downloading

sunyuxiu commented 2 years ago

@naoto0804 The decoder.pth model is OK to download.But the vgg pth is 404 Not Found.Sorry to reply too late.

naoto0804 commented 2 years ago

I fixed the weight. Could you try it again?

sunyuxiu commented 2 years ago

@naoto0804 It is still 404 Not Found.Not Found The requested URL /~inoue/projects/tmp/vgg_normalized.pth was not found on this server.

naoto0804 commented 2 years ago

I found there is a typo; https://www.hal.t.u-tokyo.ac.jp/~inoue/projects/tmp/vgg_normalised.pth

sunyuxiu commented 2 years ago

@naoto0804 Thank you.I finished.