/animegan2-pytorch

PyTorch implementation of AnimeGANv2

Primary LanguageJupyter NotebookMIT LicenseMIT

PyTorch Implementation of AnimeGANv2

Updates

Basic Usage

Weight Conversion from the Original Repo (Requires TensorFlow 1.x)

git clone https://github.com/TachibanaYoshino/AnimeGANv2
python convert_weights.py

Inference

python test.py --input_dir [image_folder_path] --device [cpu/cuda]
samples
Results from converted `Paprika` style model (input image, original tensorflow result, pytorch result from left to right)

     

Note: Training code not included / Results from converted weights slightly different due to the bilinear upsample issue

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

Additional Model Weights

Webtoon Face [ckpt]

samples

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

 

Face Portrait v1 [ckpt]

samples

Trained on 512x512 face images.

Colab

samples

📺

sample

Face Portrait v2 [ckpt]

samples

Trained on 512x512 face images. Compared to v1, 🔻beautify 🔺robustness

Colab

face_portrait_v2_0

face_portrait_v2_1

🦑 🎮 🔥

face_portrait_v2_squid_game