GithubHelp home page GithubHelp logo

peterzhousz / targetclip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hila-chefer/targetclip

0.0 0.0 0.0 33.36 MB

Official PyTorch implementation of the paper Image-Based CLIP-Guided Essence Transfer.

Python 1.84% Jupyter Notebook 98.16%

targetclip's Introduction

TargetCLIP- official pytorch implementation of the paper Image-Based CLIP-Guided Essence Transfer

This repository finds a global direction in StyleGAN's space to edit images according to a target image. We transfer the essence of a target image to any source image.

Pretrained directions notebooks:

Notebook for celebrity sources/ your own pre-inverted latents:

Open In Colab

The notebook allows to use the directions on the sources presented in the examples. In addition, there's an option to edit your own inverted images with the pretrained directions, by uploading your latent vector to the dirs folder. We use images inverted by e4e.

Notebook for e4e+TargetCLIP (inversion and manipulation in one notebook):

Open In Colab

Training new directions:

To train new directions for your own targets, use the find_dirs.py script under the optimization folder.

Our code supports both targets from images the were not inverted and targets for inverted images. For example, our Elsa, The Joker, Pocahontas, Keanu Reeves, and more examples were not inverted, while our Trump example was inverted. When possible, an inverted target usually gives better results.

We recommend to use inverted images for the training process. Our experiments use the inverted latents from the StyleCLIP repo.

Using targets that were not inverted

The code uses --num_directions differnet random initializations for the essence vector. After training, you can choose your favorite one (usually, all are very similar).

  1. Download the inverted latents from the StyleCLIP repo for training.
  2. Upload your target image to the dirs/tragets folder. Note that png images are not supported.
  3. Run the find_dirs.py script with your target:
PYTHONPATH=`pwd` python optimization/find_dirs.py --target_path dirs/targets/your_target.jpg --dir_name results_folder --weight_decay 3e-3 --lambda_consistency 0.6 --step 1000 --lr 0.2 --num_directions 8 --num_images 8 --data_path path_to_styleclip_latents

The intermediate best results for your training samples will appear under the path specified in --dir_name. In addition, the optimal essence vectors for all your initializations will be saved as direction{i}.npy, and you can use them on other images or upload them to the notebook to experiment with other sources.

Using inverted targets

We will initialize the essence vector to be the latent of your target.

  1. Download the inverted latents from the StyleCLIP repo for training.
  2. Upload your target's latent to the dirs/tragets folder. We use e4e to invert all our images.
  3. Run the find_dirs.py script with your target latnet:
PYTHONPATH=`pwd` python optimization/find_dirs.py  --dir_initialition dirs/tragets/your_target.pt --num_directions 8  --num_images 8 --dir_name results_folder --weight_decay 3e-3 --lambda_consistency 0.6 --step 1000 --lr 0.2 --data_path path_to_styleclip_latents

The intermediate best results for your training samples will appear under the path specified in --dir_name. In addition, the optimal essence vectors for all your initializations will be saved as direction0.npy, which is the essence vector derived from your input latent.

Examples:

NOTE: all the examples presented are available in our colab notebook. The recommended coefficient to use is between 0.5-1

Targets that were not inverted- The Joker and Keanu Reeves

The targets are plain images, that were not inverted, the direction optimization is initialized at random.

NOTE: for the joker, we use relatively large coefficients- 0.9-1.3

Out of domain targets- Elsa and Pocahontas

The targets are plain images that are out of the domain StyleGAN was trained on, the direction optimization is initialized at random.

Targets that were inverted- Trump

The targets are inverted images, and the latents are used as initialization for the optimization.

Updates:

10/27/21: Pretrained directions added for Doc Brown (Back to the Future), Morgan Freeman, Beyonce, and Ariel (The Little Mermaid)!

11/2/21: Pretrained directions added for Wolverine, Avatar, and Gargamel!

11/12/21: New pretrained directions added for Ed Sheeran, Dumbledore, Moana, Zendaya, Thanos, and more!

Citing our paper

If you make use of our work, please cite our paper:

@article{chefer2021targetclip,
  title={Image-Based CLIP-Guided Essence Transfer},
  author={Chefer, Hila and Benaim, Sagie and Paiss, Roni and Wolf, Lior},
  journal={arXiv preprint arXiv: 2110.12427},
  year={2021}
}

Credits

The code in this repo draws from the StyleCLIP code base.

targetclip's People

Contributors

hila-chefer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.