Image_To_Anime

Image to Anime

The goal of Image to Anime was to create a new version of the image that would possess the same clean lines and evoke the characteristic feel found in anime productions, capturing the unique artistry and aesthetics associated with this style.

mit
Image-to-Image
PyTorch
English
by @AIOZNetwork
22

Last updated: a month ago


Generic badge Generic badge

Image To Anime

Summary

Introduction

With a model called AnimeGANv2, it uses Generative Adversarial Networks (GAN) architecture to train and create high-quality anime images. GAN is a two-part network architecture consisting of a generator and a discriminator. The generator network aims to create anime images that resemble real images, while the discriminator network tries to distinguish between images generated from the generator network and real images.

Parameters

Inputs

  • input - (image - .png/.jpg/.jpeg): This is the type of realistic image that users need to convert.

Output

  • output - (image -.png): The image is recreated according to the user's request. The size of the image when reproduced will not change.

Examples

InputOutput

Usage for developers

Please find below the details to track the information and access the code for processing the model on our platform.

Requirements

opencv-python
numpy
torch

Code based on AIOZ structure

from .model import Generator
import torch, os
import cv2
import numpy as np

...
def do_ai_task(
        input: Union[str, Path],
        model_storage_directory: Union[str, Path],
        device: Literal["cpu", "cuda", "gpu"] = "cpu",
        *args, **kwargs) -> Any:
        
        # Define Model AI
        path_weight = os.path.abspath(model_storage_directory + "...")
        net = Generator()
        net.load_state_dict(torch.load(path_weight, map_location= device))
        net.to(device).eval()
        
        # Processing input
        input = cv2.imread(input)
        input = cv2.cvtColor(input, cv2.COLOR_BGR2RGB).astype(np.float32)/ 127.5 - 1.0 # [-1, 1]
        input = torch.from_numpy(input).to(device).unsqueeze(0)
        with torch.no_grad():
            out = net(input, False)
        out = out.squeeze(0).cpu()
        out = ((out + 1.) * 127.5).numpy().clip(0, 255).astype(np.uint8)
        out = cv2.cvtColor(out, cv2.COLOR_RGB2BGR)
        cv2.imwrite("output.png", out)
        output = open("output.png", "rb")  # io.BufferedReader
    return output

Reference

This repository is based on and inspired by Bryand Lee's work. We sincerely appreciate their generosity in sharing the code.

License

We respect and comply with the terms of the author's license cited in the Reference section.