Home

Awesome

PyTorch Implementation of AnimeGANv2

Updates

Basic Usage

Inference

python test.py --input_dir [image_folder_path] --device [cpu/cuda]

Torch Hub Usage

You can load the model via torch.hub:

import torch
model = torch.hub.load("bryandlee/animegan2-pytorch", "generator").eval()
out = model(img_tensor)  # BCHW tensor

Currently, the following pretrained shorthands are available:

model = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="celeba_distill")
model = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v1")
model = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="face_paint_512_v2")
model = torch.hub.load("bryandlee/animegan2-pytorch:main", "generator", pretrained="paprika")

You can also load the face2paint util function:

from PIL import Image

face2paint = torch.hub.load("bryandlee/animegan2-pytorch:main", "face2paint", size=512)

img = Image.open(...).convert("RGB")
out = face2paint(model, img)

More details about torch.hub is in the torch docs

Weight Conversion from the Original Repo (Tensorflow)

  1. Install the original repo's dependencies: python 3.6, tensorflow 1.15.0-gpu
  2. Install torch >= 1.7.1
  3. Clone the original repo & run
git clone https://github.com/TachibanaYoshino/AnimeGANv2
python convert_weights.py
<details> <summary>samples</summary> <br> Results from converted `Paprika` style model (input image, original tensorflow result, pytorch result from left to right)

<img src="./samples/compare/1.jpg" width="960">   <img src="./samples/compare/2.jpg" width="960">   <img src="./samples/compare/3.jpg" width="960">  

</details>

Note: Results from converted weights slightly different due to the bilinear upsample issue

Additional Model Weights

Webtoon Face [ckpt]

<details> <summary>samples</summary>

Trained on <b>256x256</b> face images. Distilled from webtoon face model with L2 + VGG + GAN Loss and CelebA-HQ images.

face_results  

</details>

Face Portrait v1 [ckpt]

<details> <summary>samples</summary>

Trained on <b>512x512</b> face images.

Colab

samples

📺

sample

</details>

Face Portrait v2 [ckpt]

<details> <summary>samples</summary>

Trained on <b>512x512</b> face images. Compared to v1, 🔻beautify 🔺robustness

Colab

face_portrait_v2_0

face_portrait_v2_1

🦑 🎮 🔥

face_portrait_v2_squid_game

</details>