omertov / encoder4editing

Official implementation of "Designing an Encoder for StyleGAN Image Manipulation" (SIGGRAPH 2021) https://arxiv.org/abs/2102.02766
MIT License
945 stars 154 forks source link

An approach to solve "UnpicklingError" #67

Closed mistake0316 closed 2 years ago

mistake0316 commented 2 years ago

I run colab today, and found the error showing at bottom. To solve this problem, my approach is following

  1. download *.pth manully
  2. upload it to google drive
  3. change it permisson to anyone can view and copy the id
  4. !gdown --id ${id} -O path/to/store.pth # in colab
  5. model_path = path/to/store.pth # replace the line before load ckpt in colab
---------------------------------------------------------------------------
UnpicklingError                           Traceback (most recent call last)
<ipython-input-9-698ee78d7482> in <module>()
      1 model_path = EXPERIMENT_ARGS['model_path']
----> 2 ckpt = torch.load(model_path, map_location='cpu')
      3 opts = ckpt['opts']
      4 # pprint.pprint(opts)  # Display full options used
      5 # update the training options

1 frames
/usr/local/lib/python3.7/dist-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    424         if sys.version_info >= (3, 0) and 'encoding' not in pickle_load_args.keys():
    425             pickle_load_args['encoding'] = 'utf-8'
--> 426         return _load(f, map_location, pickle_module, **pickle_load_args)
    427     finally:
    428         if new_fd:

/usr/local/lib/python3.7/dist-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    601             f.seek(0)
    602 
--> 603     magic_number = pickle_module.load(f, **pickle_load_args)
    604     if magic_number != MAGIC_NUMBER:
    605         raise RuntimeError("Invalid magic number; corrupt file?")

UnpicklingError: invalid load key, '<'.
omertov commented 2 years ago

Hi @mistake0316! Sorry for being MIA for so long, I have updated the notebook to use pydrive which should work fine now (at least it does in my tests).

Please reopen the issue if there are still problems.

Best, Omer