PyTorch Implementation of AnimeGANv2
Updates
-
2021-10-17
Add weights for FacePortraitV2 -
2021-11-07
Thanks to ak92501, a web demo is integrated to Huggingface Spaces with Gradio. -
2021-11-07
Thanks to xhlulu, thetorch.hub
model is now available. See Torch Hub Usage. -
2021-11-07
Add FacePortraitV2 style demo to a telegram bot. See @face2stickerbot by sxela
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]
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
Webtoon Face [ckpt]
samples
Trained on 256x256 face images. Distilled from webtoon face model with L2 + VGG + GAN Loss and CelebA-HQ images. See test_faces.ipynb
for details.
Face Portrait v1 [ckpt]
Face Portrait v2 [ckpt]
You can load Animegan v2 via torch.hub
:
import torch
model = torch.hub.load('bryandlee/animegan2-pytorch', 'generator').eval()
# convert your image into tensor here
out = model(img_tensor)
You can load with various configs (more details in the torch docs):
model = torch.hub.load(
"bryandlee/animegan2-pytorch:main",
"generator",
pretrained=True, # or give URL to a pretrained model
device="cuda", # or "cpu" if you don't have a GPU
progress=True, # show progress
)
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. First, install dependencies:
pip install torchvision Pillow numpy
Then, import the function using torch.hub
:
face2paint = torch.hub.load(
'bryandlee/animegan2-pytorch:main', 'face2paint',
size=512, device="cpu"
)
img = Image.open(...).convert("RGB")
out = face2paint(model, img)