PyTorch Implementation of AnimeGANv2

Overview

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]

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

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. See test_faces.ipynb for details.

 

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

Torch Hub Usage

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)
Comments
  • Training Anime like ARCANE (Netflix)

    Training Anime like ARCANE (Netflix)

    Quick question: Is it possible to train with new style like from Netflix style animation "ARCANE" I really love their rendering of face.

    If possible, is it hard, does it take a long time using M1?

    opened by enzyme69 29
  • how to train another model like

    how to train another model like "Face Portrait v1 "

    Could you let us know who to train another model like "Face Portrait v1 "?

    as I know, Animegan2 is not for facial style transfer.. so I really want to know the detail steps to train facial model by using Animegan2.

    Thanks very much!

    opened by ruanjiyang 13
  • Add torch hub support

    Add torch hub support

    I added some details in the readme:


    Torch Hub Usage

    You can load Animegan v2 via torch.hub:

    import torch
    model = torch.hub.load('xhlulu/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(
        "xhlulu/animegan2-pytorch",
        "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("xhlulu/animegan2-pytorch", "generator", pretrained="celeba_distill")
    model = torch.hub.load("xhlulu/animegan2-pytorch", "generator", pretrained="face_paint_512_v1")
    model = torch.hub.load("xhlulu/animegan2-pytorch", "generator", pretrained="face_paint_512_v2")
    model = torch.hub.load("xhlulu/animegan2-pytorch", "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(
        'xhlulu/animegan2-pytorch', 'face2paint', 
        size=512, device="cpu"
    )
    
    img = Image.open(...).convert("RGB")
    out = face2paint(model, img)
    

    Would probably need to update the download links to bryandlee/animegan2-pytorch before merging

    opened by xhluca 7
  • How to Convert Full Body Photo

    How to Convert Full Body Photo

    Hello, when I use the [face_paint_512_v2.pt] model to convert the full body photo, it is very ugly, but the photo containing only the face is good, how can I combine the face only and the full body photo together? Does the model need to be retrained?

    like this anime

    photo1 use other app,i think its use animegan2. photo2 convert full body photo.its ugly width face photo3 only convert face, its nice.and face like photo 1

    opened by zhouqihao 5
  • Add Google Colab Demo

    Add Google Colab Demo

    The demo on HG Spaces is amazing! I used it for a few photos and really like it.

    Unfortunately it seems it's getting quite crowded and takes over 20min to process due to the queue. Also it runs on a CPU.

    I added a colab notebook that lets you upload a photo and run the model. It works on both CPU and GPUs. You can see what it looks like here: https://colab.research.google.com/github/xhlulu/animegan2-pytorch/blob/main/colab_demo.ipynb

    opened by xhluca 4
  • Running this on Mac M1 gives error...

    Running this on Mac M1 gives error...

    Hi Bryan, I wanted to make this to work locally on my machine, so I don't need to queue, but I kept getting error when running: python convert_weights.py:

    Traceback (most recent call last):
      File "/Users/jimmygunawan/animegan2-pytorch-main-2/convert_weights.py", line 7, in <module>
        from AnimeGANv2.net import generator as tf_generator
      File "/Users/jimmygunawan/animegan2-pytorch-main-2/AnimeGANv2/net/generator.py", line 1, in <module>
        import tensorflow.contrib as tf_contrib
    ModuleNotFoundError: No module named 'tensorflow.contrib'
    

    I am not programmer, so far I did try to install tensorflow via miniforge on this Mac machine, I think I also have conda stuff and tensorflow installed, but issue above persist.

    Any idea how to fix this? Thanks!

    opened by enzyme69 4
  • Concern about version of Tensorflow and python

    Concern about version of Tensorflow and python

    In the basic usage, you say that Weight Conversion from the Original Repo (Requires TensorFlow 1.x) TensorFlow 1.x can only installed for python2. However the code in test.py is using python3 syntax. How did you manage to make it work?

    opened by ngockimhoang 3
  • How can run PyTorch Implementation of AnimeGANv2 on Google colab notebook?

    How can run PyTorch Implementation of AnimeGANv2 on Google colab notebook?

    I'm interested in experimenting your Paprika style model, using [GitHub] repo for converting images. Usually, people use this interface, which takes so long time. img

    I want to train the offered available pre-trained models on Google Colab Notebook and experiment Additional Model Weights, but not only I couldn't manage to run Torch Hub Usage according to instructions but also I couldn't run the face2paint option due to the following error:

    ---------------------------------------------------------------------------
    HTTPError                                 Traceback (most recent call last)
    <ipython-input-13-35ffb2517470> in <module>()
    ----> 1 face2paint = torch.hub.load('bryandlee/animegan2-pytorch:main', 'face2paint', size=512, device="cpu")
          2 
          3 img = Image.open(...).convert("RGB")
          4 out = face2paint(model, img)
    
    8 frames
    /usr/lib/python3.7/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
        647 class HTTPDefaultErrorHandler(BaseHandler):
        648     def http_error_default(self, req, fp, code, msg, hdrs):
    --> 649         raise HTTPError(req.full_url, code, msg, hdrs, fp)
        650 
        651 class HTTPRedirectHandler(BaseHandler):
    
    HTTPError: HTTP Error 403: rate limit exceeded 
    

    I can't figure out to resolve this issue to run the model on the Colab notebook. Please feel free to edit or comment on Google Colab Notebook I shared.

    opened by clevilll 3
  • What is the Torch version?

    What is the Torch version?

    my torch.version is 1.2.0 and have problem about torch.load() . What version do you use?

    RuntimeError: ./face_paint_512_v2.pt is a zip archive (did you mean to use torch.jit.load()?)

    opened by binglebai 2
  • Can face_paint_512_v2 be converted to torch mobile?

    Can face_paint_512_v2 be converted to torch mobile?

    Great work! I'd like to convert your pretrained model, face_paint_512_v2, to pytorch mobile.

    from torch.utils.mobile_optimizer import optimize_for_mobile

    Do you know the model specifics that will allow a conversion to the lite interpreter for mobile?

    opened by spinoza1791 1
  • training methods

    training methods

    Hello, I want to implement the training code for this project.

    • Did you learn the same as the original animeganv2?

    • Did you have any other additions for training code implementation?

    opened by jjeamin 1
  • Missing file or folder : wine

    Missing file or folder : wine

    When I try the project passing an image I get this error : I have version 1.13.0 for torch and 0.14.0 for torchvision

    env: « wine »: No file or folder of this type

    opened by DarkRedman 0
  • Can celeba_distill be converted to torch mobile ?

    Can celeba_distill be converted to torch mobile ?

    Great work! I'd like to convert your pretrained model, celeba_distill, to pytorch mobile. from torch.utils.mobile_optimizer import optimize_for_mobile Do you know the model specifics that will allow a conversion to the lite interpreter for mobile?

    opened by davidjdseo 0
  • Would it be possible to position of the head back to it's place?

    Would it be possible to position of the head back to it's place?

    I was wondering ıf it would be possible to re use the data that is generated (probably) while tracking the head it one place to put it in it's original place.

    use case: after processing a video with animegan2 the head would be in its own place so the original head can be replaced with the animegan version easliy.

    right now I can do it by tracking the original head and using the tracking data to put the processed head in place but it is too jumpy...

    opened by carbendi 3
  • output face with anime outline

    output face with anime outline

    some outputs that your model Face Portrait v2 generated have a very good anime outline : image image and image image

    How to do it ? I tried to redo training it but failed !

    opened by onefish51 1
  • Some pictures are ‘dirty’ when apply to full body photo, is there a way to improve it?

    Some pictures are ‘dirty’ when apply to full body photo, is there a way to improve it?

    Hello, your work is really great. I try to apply the filter to some full-body photos. But in some pictures, they look dirty in some parts. I find another app that may use your work, their results look much better, and the pictures are 'clean'. Do you have any ideas to improve the results? I uploaded the results and the original picture I used. image original picture

    opened by Folkfive 0
Owner
null
An essential implementation of BYOL in PyTorch + PyTorch Lightning

Essential BYOL A simple and complete implementation of Bootstrap your own latent: A new approach to self-supervised Learning in PyTorch + PyTorch Ligh

Enrico Fini 48 Sep 27, 2022
RealFormer-Pytorch Implementation of RealFormer using pytorch

RealFormer-Pytorch Implementation of RealFormer using pytorch. Includes comparison with classical Transformer on image classification task (ViT) wrt C

Simo Ryu 90 Dec 8, 2022
A PyTorch implementation of the paper Mixup: Beyond Empirical Risk Minimization in PyTorch

Mixup: Beyond Empirical Risk Minimization in PyTorch This is an unofficial PyTorch implementation of mixup: Beyond Empirical Risk Minimization. The co

Harry Yang 121 Dec 17, 2022
A pytorch implementation of Pytorch-Sketch-RNN

Pytorch-Sketch-RNN A pytorch implementation of https://arxiv.org/abs/1704.03477 In order to draw other things than cats, you will find more drawing da

Alexis David Jacq 172 Dec 12, 2022
PyTorch implementation of Advantage async actor-critic Algorithms (A3C) in PyTorch

Advantage async actor-critic Algorithms (A3C) in PyTorch @inproceedings{mnih2016asynchronous, title={Asynchronous methods for deep reinforcement lea

LEI TAI 111 Dec 8, 2022
Pytorch-diffusion - A basic PyTorch implementation of 'Denoising Diffusion Probabilistic Models'

PyTorch implementation of 'Denoising Diffusion Probabilistic Models' This reposi

Arthur Juliani 76 Jan 7, 2023
Fang Zhonghao 13 Nov 19, 2022
RETRO-pytorch - Implementation of RETRO, Deepmind's Retrieval based Attention net, in Pytorch

RETRO - Pytorch (wip) Implementation of RETRO, Deepmind's Retrieval based Attent

Phil Wang 556 Jan 4, 2023
HashNeRF-pytorch - Pure PyTorch Implementation of NVIDIA paper on Instant Training of Neural Graphics primitives

HashNeRF-pytorch Instant-NGP recently introduced a Multi-resolution Hash Encodin

Yash Sanjay Bhalgat 616 Jan 6, 2023
Generic template to bootstrap your PyTorch project with PyTorch Lightning, Hydra, W&B, and DVC.

NN Template Generic template to bootstrap your PyTorch project. Click on Use this Template and avoid writing boilerplate code for: PyTorch Lightning,

Luca Moschella 520 Dec 30, 2022
A PyTorch Extension: Tools for easy mixed precision and distributed training in Pytorch

This repository holds NVIDIA-maintained utilities to streamline mixed precision and distributed training in Pytorch. Some of the code here will be included in upstream Pytorch eventually. The intention of Apex is to make up-to-date utilities available to users as quickly as possible.

NVIDIA Corporation 6.9k Jan 3, 2023
Objective of the repository is to learn and build machine learning models using Pytorch. 30DaysofML Using Pytorch

30 Days Of Machine Learning Using Pytorch Objective of the repository is to learn and build machine learning models using Pytorch. List of Algorithms

Mayur 119 Nov 24, 2022
Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

Pretrained SOTA Deep Learning models, callbacks and more for research and production with PyTorch Lightning and PyTorch

Pytorch Lightning 1.4k Jan 1, 2023
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Mamy Ratsimbazafy 360 Dec 10, 2022
The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.

This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu

Ritchie Ng 9.2k Jan 2, 2023
Amazon Forest Computer Vision: Satellite Image tagging code using PyTorch / Keras with lots of PyTorch tricks

Amazon Forest Computer Vision Satellite Image tagging code using PyTorch / Keras Here is a sample of images we had to work with Source: https://www.ka

Mamy Ratsimbazafy 359 Jan 5, 2023
A bunch of random PyTorch models using PyTorch's C++ frontend

PyTorch Deep Learning Models using the C++ frontend Gettting started Clone the repo 1. https://github.com/mrdvince/pytorchcpp 2. cd fashionmnist or

Vince 0 Jul 13, 2021
PyTorch Autoencoders - Implementing a Variational Autoencoder (VAE) Series in Pytorch.

PyTorch Autoencoders Implementing a Variational Autoencoder (VAE) Series in Pytorch. Inspired by this repository Model List check model paper conferen

Subin An 8 Nov 21, 2022
PyTorch-LIT is the Lite Inference Toolkit (LIT) for PyTorch which focuses on easy and fast inference of large models on end-devices.

PyTorch-LIT PyTorch-LIT is the Lite Inference Toolkit (LIT) for PyTorch which focuses on easy and fast inference of large models on end-devices. With

Amin Rezaei 157 Dec 11, 2022