Giter VIP home page Giter VIP logo

anime_style_transfer_pytorch's Introduction

Anime Style Transfer

result

Thank you @AK

Anime Style Transfer with Pytorch

  • YOLOv5
  • Waifu2x
  • CLIP
  • StyleGAN2(Blending)
  • pix2pixHD

Web Demo

Integrated into Huggingface Spaces ๐Ÿค— using Gradio. Try out the Web Demo: Hugging Face Spaces

My Env

  • python 3.7
  • pytorch 1.8.1
  • cuda 11.1
  • cudnn 8.0.5

collect video and image
->
face detection
->
image filtering using clip (clear / blurred)
->
waifu upsampling
->
face alignment according to ffhq standard
->
train Anime StyleGAN (transfer learning!!)
->
FFHQ, Anime StyleGAN Blending
->
Make Dataset
->
Pix2PixHD Training
->
Result !!

1. Prepare custom data

# video

ffmpeg -i video.mp4 -filter:v fps=0.5 video%d.jpg
# folder
anime
  |- 1.png
  |- 2.png
  |- 3.png
  |- ...

2. Face Detection with YOLOv5

Custom Training with icartoonface dataset

  • iCartoon

  • icartoonface format -> yolov5 format

    • Reference : icartoonface_convert.ipynb
  • train yolov5

  • detect + crop

count = 0
for name in tqdm(os.listdir(folder)):
    img_path = os.path.join(folder, name)
    img = cv2.imread(img_path)
    img_h, img_w, _= img.shape
    
    results = model(img_path)
    
    for rst in results.crop():

        xmin, ymin, xmax, ymax = rst['box']

        xmin = int(xmin.cpu().numpy() * 0.92)
        xmax = int(xmax.cpu().numpy() * 1.08)
        ymin = int(ymin.cpu().numpy() * 0.92)
        ymax = int(ymax.cpu().numpy() * 1.08)

        if (xmax - xmin) > (ymax - ymin):
            ymax += (((xmax - xmin) - (ymax - ymin)) // 2)
            ymin -= (((xmax - xmin) - (ymax - ymin)) // 2)
        else:
            xmax += (((ymax - ymin) - (xmax - xmin)) // 2)
            xmin -= (((ymax - ymin) - (xmax - xmin)) // 2)

        xmax = min(xmax, img_w) 
        ymax = min(ymax, img_h) 
        xmin = max(xmin, 0) 
        ymin = max(ymin, 0) 

        cv2.imwrite(f'./result/{count}.png', img[ymin:ymax, xmin:xmax])
        count += 1

3. Remove Blurred Images with CLIP

["clear face", "blurred face"]

4. Image Super-Resoultion with Waifu2x

5. Face Alignment according to FFHQ standard

6. Train StyleGAN2

python dataset_tool.py --source=[YOUR DATASET PATH] --dest=./anime.zip --width 512 --height 512
python train.py --outdir=./training-runs --data=./anime.zip --cfg=paper512 --mirror=1 --gpus=4 --batch 8 --resume ffhq512

7. Blend Model

  • StyleGAN2

  • Reference : ./blending.ipynb

  • Number of Images : 10000

8. Pix2Pix Training

# train

python train.py --name anime --dataroot ./datasets/anime --loadSize 512 --label_nc 0 --no_instance


# test

python test.py --name anime --dataroot ./datasets/test --loadSize 512 --label_nc 0 --no_instance

Reference

anime_style_transfer_pytorch's People

Contributors

ak391 avatar jjeamin 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.