eladrich / pixel2style2pixel

Official Implementation for "Encoding in Style: a StyleGAN Encoder for Image-to-Image Translation" (CVPR 2021) presenting the pixel2style2pixel (pSp) framework
https://eladrich.github.io/pixel2style2pixel/
MIT License
3.19k stars 570 forks source link

loading pretrained weights, STACK_GLOBAL requires str #314

Closed aminullah6264 closed 1 year ago

aminullah6264 commented 1 year ago

I am getting the following error while loading the pre-trained weights, any idea how to solve this, I am running on a custom dataset. the training setup is the same as the default repo. I just changed data paths.

python scripts/train.py --dataset_type=svo_encode --exp_dir=./experiments/svo_exp10 --workers=8 --batch_size=8 --test_batch_size=8 --test_workers=8 --val_interval=2500 --save_interval=5000 --encoder_type=GradualStyleEncoder --start_from_latent_avg --lpips_lambda=0.8 --l2_lambda=1 --id_lambda=0.1 {'batch_size': 8, 'board_interval': 50, 'checkpoint_path': None, 'dataset_type': 'svo_encode', 'encoder_type': 'GradualStyleEncoder', 'exp_dir': './experiments/svo_exp10', 'id_lambda': 0.1, 'image_interval': 100, 'input_nc': 3, 'l2_lambda': 1.0, 'l2_lambda_crop': 0, 'label_nc': 0, 'learn_in_w': False, 'learning_rate': 0.0001, 'lpips_lambda': 0.8, 'lpips_lambda_crop': 0, 'max_steps': 500000, 'moco_lambda': 0, 'optim_name': 'ranger', 'output_size': 1024, 'resize_factors': None, 'save_interval': 5000, 'start_from_latent_avg': True, 'stylegan_weights': 'pretrained_models/mtcnn/pnet.npy', 'test_batch_size': 8, 'test_workers': 8, 'train_decoder': False, 'use_wandb': False, 'val_interval': 2500, 'w_norm_lambda': 0, 'workers': 8} Loading encoders weights from irse50! Loading decoder weights from pretrained! Traceback (most recent call last): File "scripts/train.py", line 32, in main() File "scripts/train.py", line 27, in main coach = Coach(opts) File "/nfs/hpc/share/ullaham/SailON/phase3/GAN/pixel2style2pixel/training/coach.py", line 36, in init self.net = pSp(self.opts).to(self.device) File "/nfs/hpc/share/ullaham/SailON/phase3/GAN/pixel2style2pixel/models/psp.py", line 34, in init self.load_weights() File "/nfs/hpc/share/ullaham/SailON/phase3/GAN/pixel2style2pixel/models/psp.py", line 63, in load_weights ckpt = torch.load(self.opts.stylegan_weights) File "/nfs/stak/users/ullaham/hpc-share/anaconda3/envs/psp_env/lib/python3.6/site-packages/torch/serialization.py", line 585, in load return _legacy_load(opened_file, map_location, pickle_module, pickle_load_args) File "/nfs/stak/users/ullaham/hpc-share/anaconda3/envs/psp_env/lib/python3.6/site-packages/torch/serialization.py", line 755, in _legacy_load magic_number = pickle_module.load(f, pickle_load_args) _pickle.UnpicklingError: STACK_GLOBAL requires str

yuval-alaluf commented 1 year ago

It seems like the path to your StyleGAN weights is pointing to the MTCNN model weights which is an npy file. The code assumes the StyleGAN is saved as a pickle. Notice from what you sent above:

'stylegan_weights': 'pretrained_models/mtcnn/pnet.npy',

You should place the path to the StyleGAN model here.