DragGAN icon indicating copy to clipboard operation
DragGAN copied to clipboard

Using custom images, creating a custom PTI results in loading error

Open FrancescoSaverioZuppichini opened this issue 2 years ago • 15 comments

Hi There 👋

Thanks a lot for the code. I've created a PTI using both the pti code inside this repo and the PTI repo you linked. The resulting checkpoints is smaller and in .pt file. If I try to load it into the ui by changing .pt -> pkl I got this error

  File "/home/zuppif/miniconda3/envs/stylegan3/lib/python3.9/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/home/zuppif/miniconda3/envs/stylegan3/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/home/zuppif/miniconda3/envs/stylegan3/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/home/zuppif/Documents/DragGAN/visualizer_drag_gradio.py", line 353, in on_change_pretrained_dropdown
    init_images(global_state)
  File "/home/zuppif/Documents/DragGAN/visualizer_drag_gradio.py", line 70, in init_images
    state['renderer'].init_network(
  File "/home/zuppif/Documents/DragGAN/viz/renderer.py", line 221, in init_network
    G = self.get_network(pkl, 'G_ema')
  File "/home/zuppif/Documents/DragGAN/viz/renderer.py", line 146, in get_network
    raise data
viz.renderer.CapturedException: Traceback (most recent call last):
  File "/home/zuppif/Documents/DragGAN/viz/renderer.py", line 138, in get_network
    data = legacy.load_network_pkl(f)
  File "/home/zuppif/Documents/DragGAN/legacy.py", line 23, in load_network_pkl
    data = _LegacyUnpickler(f).load()
_pickle.UnpicklingError: A load persistent id instruction was encountered,
but no persistent_load function was specified.

For refence, the checkpoint dim is 127M while all yours are 348. My config for PTI is

## Pretrained models paths
e4e = '../pit/e4e_ffhq_encode.pt'
stylegan2_ada_ffhq = '../pti/ffhq.pkl'
style_clip_pretrained_mappers = ''
ir_se50 = '../pti/model_ir_se50.pth'
dlib = '../pti/shape_predictor_68_face_landmarks.dat'

## Dirs for output files
checkpoints_dir = './checkpoints'
embedding_base_dir = './embeddings'
styleclip_output_dir = './StyleCLIP_results'
experiments_output_dir = './output'

## Input info
### Input dir, where the images reside
input_data_path = '/home/zuppif/Documents/DragGAN/aligned_image/'
### Inversion identifier, used to keeping track of the inversion results. Both the latent code and the generator
input_data_id = 'barcelona'

## Keywords
pti_results_keyword = 'PTI'
e4e_results_keyword = 'e4e'
sg2_results_keyword = 'SG2'
sg2_plus_results_keyword = 'SG2_plus'
multi_id_model_type = 'multi_id'

## Edit directions
interfacegan_age = 'editings/interfacegan_directions/age.pt'
interfacegan_smile = 'editings/interfacegan_directions/smile.pt'
interfacegan_rotation = 'editings/interfacegan_directions/rotation.pt'
ffhq_pca = 'editings/ganspace_pca/ffhq_pca.pt'

Basically, the default. May I ask you how you created the checkpoints?

Thanks

Fra

I got it working, got the custom model, in pkl file but it is not generating the custom image from which this model was generated instead it is generating random human faces. do you have any idea?

Pawandeep-prog avatar Jun 27 '23 04:06 Pawandeep-prog

okay, DONE 👍

I have successfully created custom pickle model and loaded w_pivot as well. I will soon share full step by step process.

damn, it is working like a charm.

Edit: uploaded a related step by step solution- https://youtu.be/viWiOC1Mikw

Pawandeep-prog avatar Jun 27 '23 06:06 Pawandeep-prog

@Pawandeep-prog sweet! Cannot wait for it

the .pkl model to choose in GUI is 'stylegan2_ada_ffhq = '../pti/ffhq.pkl' rename the 'ffhq.pkl' to 'stylegan2_ffhq.pkl' using the PTI will got the feature file under 'PTI/embedding/ .pt', load this .pt file as latent in GUI but the picture showed in GUI is not the same as what I sent into PTI not sure it is correct or not

Antelope111 avatar Jun 27 '23 08:06 Antelope111

the .pkl model to choose in GUI is 'stylegan2_ada_ffhq = '../pti/ffhq.pkl' rename the 'ffhq.pkl' to 'stylegan2_ffhq.pkl' using the PTI will got the feature file under 'PTI/embedding/ .pt', load this .pt file as latent in GUI but the picture showed in GUI is not the same as what I sent into PTI not sure it is correct or not

replace the ffhq.pkl['G_ema'] with the PTI output .pt file, the picture in GUI seems better, but still not the same

Antelope111 avatar Jun 27 '23 08:06 Antelope111

@FrancescoSaverioZuppichini @Antelope111

Hi I have created video step by step along with colab notebook https://youtu.be/viWiOC1Mikw

I will add instructions over here as well after some time. Any question most welcome 🤗

Pawandeep-prog avatar Jun 27 '23 09:06 Pawandeep-prog

@FrancescoSaverioZuppichini @Antelope111

Hi I have created video step by step along with colab notebook https://youtu.be/viWiOC1Mikw

I will add instructions over here as well after some time. Any question most welcome hugs

I love you!

@Pawandeep-prog

How do I do this on Windows?

I was already able to install PTI and generate a .pt model, but how do I make a .pkl?

Sipovec avatar Jun 28 '23 09:06 Sipovec

@Sipovec Use this colab notebook

You will get a function export_updated_pickle at the end of the notebook.just use it to convert to pickle.

Pawandeep-prog avatar Jun 28 '23 10:06 Pawandeep-prog

Actually, I tried to embed the PTI into the DragGAN code, so that it doesn't need to be done separately. It kind of works, if you are interested, maybe you can have a look at my code (https://github.com/tianhaoxie/DragGAN_PTI). Any suggestions will be appreciated!

tianhaoxie avatar Jun 28 '23 14:06 tianhaoxie

Reference

I initially used the pti inside the repo but I think there is a missing step to somehow convert that weights to the ones drag gan accepts. Would be curious to know how you did it

Actually, I tried to embed the PTI into the DragGAN code, so that it doesn't need to be done separately. It kind of works, if you are interested or are experienced in Gradio, maybe you can have a look at my code (https://github.com/tianhaoxie/DragGAN_PTI). Any suggestions will be appreciated!

thanks a lot for the other repo, I'll test it out. Would it make sense to have the whole code here as a separate branch. I think this would make it easier for people to help out given the more visibility of this repo

Yeah, that makes sense but I'm not sure how to do that correctly. If u can help, it will be appreciated. :)

tianhaoxie avatar Jun 29 '23 12:06 tianhaoxie

its giving me a 'File Not Found' message when I try to run the second cell in "Save Latent space and Model Weights". im really new to coding so its probably a minor mistake but I can't seem to figure out how to fix Image 6-30-23 at 2 52 PM

isawtheuniverse avatar Jun 30 '23 18:06 isawtheuniverse

the .pkl model to choose in GUI is 'stylegan2_ada_ffhq = '../pti/ffhq.pkl' rename the 'ffhq.pkl' to 'stylegan2_ffhq.pkl' using the PTI will got the feature file under 'PTI/embedding/ .pt', load this .pt file as latent in GUI but the picture showed in GUI is not the same as what I sent into PTI not sure it is correct or not

replace the ffhq.pkl['G_ema'] with the PTI output .pt file, the picture in GUI seems better, but still not the same

I have the same problem, did you solve it?

zhaoxiong123 avatar Jul 10 '23 08:07 zhaoxiong123