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

is it possible to fine tune? #80

Open juanluisrosaramos opened 2 years ago

juanluisrosaramos commented 2 years ago

Is it possible to fine tune your e4e_ffhq_encode.pt model and change it to another different domain? I have a dataset of babies with a stylegan2 trained. Can I resume a train from your provided weights? i can start a training from scratch but if I add the option to resume from checkpoint it returns the error

Loading decoder weights from pretrained! Traceback (most recent call last): File "scripts/train.py", line 87, in main() File "scripts/train.py", line 27, in main coach = Coach(opts, previous_train_ckpt) File "./training/coach.py", line 38, in init self.net = pSp(self.opts).to(self.device) File "./models/psp.py", line 28, in init self.load_weights() File "./models/psp.py", line 53, in load_weights ckpt = torch.load(self.opts.stylegan_weights) File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 594, in load with _open_file_like(f, 'rb') as opened_file: File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 230, in _open_file_like return _open_file(name_or_buffer, mode) File "/usr/local/lib/python3.7/dist-packages/torch/serialization.py", line 211, in init super(_open_file, self).init(open(name, mode)) FileNotFoundError: [Errno 2] No such file or directory: ''

My training config is

python scripts/train.py \ --dataset_type babies_encode \ --exp_dir new/experiment2/directory \ --start_from_latent_avg \ --use_w_pool \ --w_discriminator_lambda 0.1 \ --progressive_start 20000 \ --id_lambda 0.1 \ --val_interval 10000 \ --max_steps 200000 \ --stylegan_size 512 \ --stylegan_weights ../stylegan2-ada-pytorch_2/network-snapshot-000320.pt \ --workers 8 \ --batch_size 8 \ --test_batch_size 2 \ --test_workers 2 \ --save_interval 2000 \ --resume_training_from_ckpt pretrained_models/e4e_ffhq_encode.pt

LLLPS666 commented 2 years ago

hello, have you solved this promble? I can ues it to fine tune. But the model would be worse after training. My training config is

python scripts/train.py \ --dataset_type my_data_encode \ --exp_dir my_model/mye4e \ --use_w_pool \ --w_discriminator_lambda 0.1 \ --progressive_start 20000 \ --id_lambda 0.5 \ --val_interval 10000 \ --max_steps 200 \ --stylegan_size 512 \ --stylegan_weights pretrained_models/stylegan2-ffhq-config-f.pt \ --workers 8 \ --batch_size 16 \ --test_batch_size 4 \ --test_workers 4 \ --checkpoint_path pretrained_models/e4e_ffhq_encode.pt

omertov commented 2 years ago

Hi @juanluisrosaramos, Sorry for the long response time,

In case it is still relevant, it seems like the file_path you provide for the stylegan_weights leads to a non-existing file, perhaps providing the absolute path to the weights file would help. Also, just making sure that the StyleGAN checkpoint is compatible with rosinality's stylegan2-pytorch implementation, and not the nvidia's pytorch implementation. Last, I believe that the resume_training_from_ckpt would not yield the desired effect (there is no training information stored in the checkpoints I provided if thats what stored in pretrained_models/e4e_ffhq_encode.pt), you could use the --checkpoint_path flag to initialize the encoder from the pretrained weights.

As for @LLLPS666 's question - Is the error caused by the wrong stylegan_size specified? (512 instead of 1024)?

Best, Omer