yuval-alaluf / stylegan3-editing

Official Implementation of "Third Time's the Charm? Image and Video Editing with StyleGAN3" (AIM ECCVW 2022) https://arxiv.org/abs/2201.13433
https://yuval-alaluf.github.io/stylegan3-editing/
MIT License
654 stars 73 forks source link

Training our Own InterFaceGAN Boundaries #28

Closed rut00 closed 2 years ago

rut00 commented 2 years ago

Our objective is to edit original images without glasses with sample images with glasses.

I have trained the network using face images with glasses using the StyleGan3 repo. And now to edit an image I am using instructions given by you to train boundary with my dataset in Kaggle from your repo. But facing the following error while generating latent and attribute scores from the generate_latents_and_attribute_scores.py script.

Loading generator from "/kaggle/input/pkl-file/network-snapshot-000010.pkl"...
Downloading: "https://hanlab.mit.edu/projects/anycost-gan/files/attribute_predictor.pt" to /root/.cache/torch/hub/checkpoints/attribute_predictor.pt
100%|██████████████████████████████████████| 90.6M/90.6M [00:02<00:00, 35.0MB/s]
Traceback (most recent call last):
  File "interfacegan/generate_latents_and_attribute_scores.py", line 112, in <module>
    run()
  File "/opt/conda/lib/python3.7/site-packages/pyrallis/argparsing.py", line 158, in wrapper_inner
    response = fn(cfg, args, *kwargs)
  File "interfacegan/generate_latents_and_attribute_scores.py", line 40, in run
    save_interval=opts.save_interval)
  File "interfacegan/generate_latents_and_attribute_scores.py", line 57, in generate_images
    age_estimator = AgeEstimator()
  File "../editing/interfacegan/helpers/age_estimator.py", line 18, in _init_
    ckpt = torch.load(model_paths["age_estimator"], map_location="cpu")['state_dict']
  File "/opt/conda/lib/python3.7/site-packages/torch/serialization.py", line 699, in load
    with _open_file_like(f, 'rb') as opened_file:
  File "/opt/conda/lib/python3.7/site-packages/torch/serialization.py", line 231, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "/opt/conda/lib/python3.7/site-packages/torch/serialization.py", line 212, in _init_
    super(_open_file, self).__init__(open(name, mode))
FileNotFoundError: [Errno 2] No such file or directory: 'pretrained_models/dex_age_classifier.pth'

If you can share the correct steps to train my custom boundaries to edit images it will be really helpful.

Thank You

woctezuma commented 2 years ago

The code does not find:

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/configs/paths_config.py#L26-L27

Hence the error at:

https://github.com/yuval-alaluf/stylegan3-editing/blob/e2a63fc7f072c4f8b8a7ba1dac8c7f87a8eb1647/editing/interfacegan/helpers/age_estimator.py#L18

I think you would need a "person with/without glasses" classifier rather than an age estimator, no?

yuval-alaluf commented 2 years ago

Please take a look at this part of the README: https://github.com/yuval-alaluf/stylegan3-editing#training-your-own-interfacegan-boundaries There you will find a link for downloading the age classifier. Place the downloading pth file in the directory pretrained_models and you should be able to load the model. (Similarly for the pose estimation model)