From 72250c44a6a53ccc9fa73b6fd552cbea5cc79c9e Mon Sep 17 00:00:00 2001 From: bryandlee Date: Sun, 7 Nov 2021 16:42:16 +0900 Subject: [PATCH] Update README.md --- README.md | 101 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 36d614d..b139a6d 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,6 @@ ## PyTorch Implementation of [AnimeGANv2](https://github.com/TachibanaYoshino/AnimeGANv2) -**Torch Hub Usage** - -You can load Animegan v2 via `torch.hub`: - -```python -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](https://pytorch.org/docs/stable/hub.html)): -```python -model = torch.hub.load( - "bryandlee/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: -```python -model = torch.hub.load("bryandlee/animegan2-pytorch", "generator", pretrained="celeba_distill") -model = torch.hub.load("bryandlee/animegan2-pytorch", "generator", pretrained="face_paint_512_v1") -model = torch.hub.load("bryandlee/animegan2-pytorch", "generator", pretrained="face_paint_512_v2") -model = torch.hub.load("bryandlee/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`: -```python -face2paint = torch.hub.load( - 'bryandlee/animegan2-pytorch', 'face2paint', - size=512, device="cpu" -) - -img = Image.open(...).convert("RGB") -out = face2paint(model, img) -``` - **Updates** * `2021-10-17` Add weights for [face portrait v2](https://github.com/bryandlee/animegan2-pytorch#additional-models) @@ -55,6 +8,10 @@ out = face2paint(model, img) See demo: [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/akhaliq/AnimeGANv2) +* `2021-11-07` Thanks to [xhlulu](https://github.com/xhlulu), the model can be loaded using torch.hub. + + +## Basic Usage **Weight Conversion from the Original Repo (Requires TensorFlow 1.x)** ``` @@ -81,7 +38,7 @@ python test.py --input_dir [image_folder_path] --device [cpu/cuda] -## Additional Models +## Additional Model Weights **Webtoon Face** [[ckpt]](https://drive.google.com/file/d/10T6F3-_RFOCJn6lMb-6mRmcISuYWJXGc) @@ -132,3 +89,51 @@ Trained on 512x512 face images. Compared to v1, `🔻beautify` `🔺robus + + +## Torch Hub Usage + +You can load Animegan v2 via `torch.hub`: + +```python +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](https://pytorch.org/docs/stable/hub.html)): +```python +model = torch.hub.load( + "bryandlee/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: +```python +model = torch.hub.load("bryandlee/animegan2-pytorch", "generator", pretrained="celeba_distill") +model = torch.hub.load("bryandlee/animegan2-pytorch", "generator", pretrained="face_paint_512_v1") +model = torch.hub.load("bryandlee/animegan2-pytorch", "generator", pretrained="face_paint_512_v2") +model = torch.hub.load("bryandlee/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`: +```python +face2paint = torch.hub.load( + 'bryandlee/animegan2-pytorch', 'face2paint', + size=512, device="cpu" +) + +img = Image.open(...).convert("RGB") +out = face2paint(model, img) +```