NVlabs / stylegan2-ada-pytorch

StyleGAN2-ADA - Official PyTorch implementation
https://arxiv.org/abs/2006.06676
Other
4.1k stars 1.16k forks source link

Does legacy.py support weight transfer from custom models? #65

Closed junikkoma closed 3 years ago

junikkoma commented 3 years ago

Describe the bug

I tried to transfer weights from custom model, which i trained using STYLEGAN2_ADA tf repo. However, after I convert weight, and try to load weight with torch.load, I get RuntimeError: Invalid magic number; corrupt file?

To Reproduce Steps to reproduce the behavior: Disclaimer : I am on docker enviornment

!python legacy.py \
    --source='/workspace/STYLEGAN_ADA/results/my_custom_weight.pkl' \
    --dest='haha.pkl'

Then with transferred pkl, I tried to load weight

aa = torch.load('/workspace/Pytorch_STYLEGAN_ADA/haha.pkl')

Then, I got error below

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-13-2902cfd094c1> in <module>
----> 1 torch.load('/workspace/Pytorch_STYLEGAN_ADA/haha.pkl').keys()

~/.local/lib/python3.8/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    591                     return torch.jit.load(opened_file)
    592                 return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
--> 593         return _legacy_load(opened_file, map_location, pickle_module, **pickle_load_args)
    594 
    595 

~/.local/lib/python3.8/site-packages/torch/serialization.py in _legacy_load(f, map_location, pickle_module, **pickle_load_args)
    762     magic_number = pickle_module.load(f, **pickle_load_args)
    763     if magic_number != MAGIC_NUMBER:
--> 764         raise RuntimeError("Invalid magic number; corrupt file?")
    765     protocol_version = pickle_module.load(f, **pickle_load_args)
    766     if protocol_version != PROTOCOL_VERSION:

RuntimeError: Invalid magic number; corrupt file?

Expected behavior I understand loading should be done, so i am guessing whether custom weights cannot be transferred. I have done other manipulation(ex. projecting query image using projector.py in TF repo), so weight itself works on TF enviornment Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

junikkoma commented 3 years ago

Inspecting legacy.py showed it was written to convert weights downloaded from URL. I'm searching my ways to convert existing weight, but at least the original code is meant to not convert custom weights