Git Product home page Git Product logo

azmarie / caricature-your-face Goto Github PK

View Code? Open in Web Editor NEW
37.0 3.0 5.0 91.87 MB

๐Ÿง‘๐Ÿปโ€๐ŸŽค Generate geometry-aware face caricatures using Style Transfer

Home Page: https://azmariewang.medium.com/geometry-aware-style-transfer-implementation-and-analysis-3a9034dfca2d

License: MIT License

Python 97.94% Shell 2.06%
style-transfer caricatures facial-landmarks neural-style-transfer

caricature-your-face's Introduction

Caricature Your Face

๐Ÿ’ก Using The Face of Arts and DST to generate geometry-aware face caricatures.

๐Ÿ“– This project in details with analysis on Medium: Geometry-Aware Style Transfer: Implementation and Analysis

Requirements

  • Python 3
  • pytorch, torchvision, cudatoolkit, numpy, PIL, matplotlib, sklearn, cv2, imutils, scikit-image

Set up the virtual environment:

python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt

after setup, you can just run source venv/bin/activate to activate the venv later on.

How To Run

preprocessing.sh is used to convert all Face of Art style images' correspondence points into .txt, this only need to be run once if you don't already have data/style/pts containing all Face of Art style images.

run.sh is a script automating the two steps for geometry style transfer.

Currently, run.sh serve as a demo with Barack Obama as the content image and Vincent van Gogh's self-portrait with the style image.

1. Obtain Facial Landmark

This step will obtain the facial landmarks for the content image with dlib.

python face_landmark_detection.py ${content_path} ${style_path} ${content_pts_path} ${style_pts_path_dlib}

2. Run Style Transfer

Now, run deformable style transfer, this step will take ~1.5 minutes on a single GPU.

Please check parameter adjustment in DST repo [code].

python main.py ${content_path} ${style_path} ${content_pts_path} ${style_pts_path} \
  ${output_dir} ${output_prefix} ${im_size} ${max_iter} \
  ${checkpoint_iter} ${content_weight} ${warp_weight} ${reg_weight} ${optim} \
  ${lr} ${verbose} ${save_intermediate} ${save_extra} ${device}

Results

Demo

Result from run.sh with Barack Obama as the content image and Vincent van Gogh's self-portrait with the style image. Images from left to right are: input content image, input style image, a standard style transfer output, demo output.

More Results

Acknowledgment

  • Dilb facial landmark
  • Deformable Style Transfer (DST) [code] [paper]
  • The Face of Art: Landmark Detection and Geometric Style in Portraits [website] [paper]
  • Style Transfer by Relaxed Optimal Transport and Self-Similarity. Nicholas Kolkin, Jason Salavon and Gregory Shakhnarovich. CVPR 2019. [paper] [code] [David Futschik's implementation]
  • WarpGAN: Automatic Caricature Generation. Yichun Shi, Debayan Deb and Anil K. Jain. CVPR 2019. [paper] [code]
  • Neural Best-Buddies: Sparse Cross-Domain Correspondence. Kfir Aberman, Jing Liao, Mingyi Shi, Dani Lischinski, Baoquan Chen and Daniel Cohen-Or. SIGGRAPH 2018. [paper] [code]

caricature-your-face's People

Contributors

azmarie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

caricature-your-face's Issues

RuntimeError: solve_cuda: U(4,4) is zero, singular U.

Hi,
Just trying to test this, but I get the following issue:

./run.sh


Started Deformable Style Transfer

Settings
content_path: data/content/barack_obama.jpg
style_path: data/style/Vincent_van_Gogh/151.png
content_pts_path: data/content/pts/barack_obama.txt
style_pts_path: data/style/pts/151.txt
output_dir: data/output/Vincent_van_Gogh
output_prefix: barack_obama-151
im_size: 256
max_iter: 150
checkpoint_iter: 50
content_weight: 8.0
warp_weight: 0.5
reg_weight: 50.0
optim: sgd
lr: 0.3
verbose: True
save_intermediate: True
save_extra: True

Optimizing at scale 1, image size (64, 64)
STEP 000: Loss 7.949
= alphaLcontent 0.434
+ Lstyle 4.580
+ beta
Lwarp 2.935
+ gamma*TV 0.000
Traceback (most recent call last):
File "main.py", line 101, in
output = DST(initial_im, content_im_orig, style_im_orig, extractor,
File "/home/nerdy/github/Caricature-Your-Face/styletransfer.py", line 143, in DST
new_im, content_im_warp, warp_field = apply_warp(new_im, [src_Kpts_aug], [dst_Kpts_aug], device, sharp=sharp_warp, im2=content_im_warp)
File "/home/nerdy/github/Caricature-Your-Face/warp.py", line 432, in apply_warp
new_im, new_im2, warp_field = image_warp(new_im, dst, dst-src, device, sharp=sharp, img2=new_im2)
File "/home/nerdy/github/Caricature-Your-Face/warp.py", line 86, in image_warp
w, v = solve_interpolation(dst_pts, flow_pts, device)
File "/home/nerdy/github/Caricature-Your-Face/warp.py", line 226, in solve_interpolation
w_v, _ = torch.solve(rhs, lhs)
RuntimeError: solve_cuda: U(4,4) is zero, singular U.

The last line changes. For example it could also be:

RuntimeError: solve_cuda: U(29,29) is zero, singular U.

How to add new style images?

Dear Azmarie,

I want to add new style images. so I want to know how to create *.ljson files for new style face images? thanks!

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.