Top Related Projects
[Open Source]. The improved version of AnimeGAN. Landscape photos/videos to anime
Official tensorflow implementation for CVPR2020 paper “Learning to Cartoonize Using White-box Cartoon Representations”
[CVPR 2022] Pastiche Master: Exemplar-Based High-Resolution Portrait Style Transfer
PhotoMaker [CVPR 2024]
Bringing Old Photo Back to Life (CVPR 2020 oral)
Quick Overview
Photo2Cartoon is an AI-powered project that transforms portrait photos into cartoon-style images. It uses a combination of face parsing, face detection, and generative adversarial networks (GANs) to create high-quality cartoon renderings while preserving the subject's key facial features and expressions.
Pros
- Produces high-quality cartoon-style images from portrait photos
- Preserves facial features and expressions effectively
- Offers both a pre-trained model and the ability to train custom models
- Provides a user-friendly web interface for easy use
Cons
- Limited to portrait photos; doesn't work well with full-body images or non-human subjects
- Requires specific hardware (NVIDIA GPU) for optimal performance
- May struggle with certain facial features or complex backgrounds
- Documentation is primarily in Chinese, which may be challenging for non-Chinese speakers
Code Examples
- Loading the pre-trained model:
from photo2cartoon import Photo2Cartoon
model = Photo2Cartoon()
- Converting a photo to a cartoon:
input_path = "path/to/input/photo.jpg"
output_path = "path/to/output/cartoon.jpg"
cartoon_image = model.inference(input_path)
cartoon_image.save(output_path)
- Training a custom model:
from photo2cartoon import Photo2CartoonTrainer
trainer = Photo2CartoonTrainer(
photo_dir="path/to/photo/dataset",
cartoon_dir="path/to/cartoon/dataset",
epochs=100,
batch_size=1
)
trainer.train()
Getting Started
To get started with Photo2Cartoon:
-
Clone the repository:
git clone https://github.com/minivision-ai/photo2cartoon.git cd photo2cartoon
-
Install dependencies:
pip install -r requirements.txt
-
Download the pre-trained model:
wget https://github.com/minivision-ai/photo2cartoon/releases/download/v1.0/photo2cartoon_weights.zip unzip photo2cartoon_weights.zip
-
Run the web interface:
python ui_server.py
-
Open a web browser and navigate to
http://localhost:3000
to use the interface.
Competitor Comparisons
[Open Source]. The improved version of AnimeGAN. Landscape photos/videos to anime
Pros of AnimeGANv2
- Supports multiple anime styles, offering more versatility in output
- Generally produces higher quality anime-style images with better detail preservation
- Includes pre-trained models for easier implementation
Cons of AnimeGANv2
- Requires more computational resources due to its complex architecture
- Less focused on cartoon-style output, which may not suit all use cases
- Documentation is less comprehensive, potentially making it harder for beginners
Code Comparison
AnimeGANv2:
from test import AnimeGANv2
model = AnimeGANv2()
output = model.inference('input.jpg')
photo2cartoon:
from photo2cartoon import Photo2Cartoon
p2c = Photo2Cartoon()
cartoon = p2c.inference('input.jpg')
Both repositories offer similar high-level APIs for inference, but AnimeGANv2 provides more options for style selection and fine-tuning. photo2cartoon has a simpler implementation focused specifically on cartoon-style conversion.
AnimeGANv2 excels in producing high-quality anime-style images with multiple style options, while photo2cartoon offers a more streamlined approach for cartoon-style conversion. The choice between the two depends on the specific requirements of the project, available computational resources, and the desired output style.
Official tensorflow implementation for CVPR2020 paper “Learning to Cartoonize Using White-box Cartoon Representations”
Pros of White-box-Cartoonization
- More detailed and customizable cartoonization process
- Provides a white-box approach, offering better interpretability
- Supports both image and video cartoonization
Cons of White-box-Cartoonization
- Requires more computational resources
- Longer processing time for cartoonization
- More complex setup and usage
Code Comparison
White-box-Cartoonization:
output = cartoonize(input_img, model)
guided_filter = GuidedFilter(r=5, eps=2e-1)
output = guided_filter(output, output)
photo2cartoon:
c2p = Photo2Cartoon()
cartoon_img = c2p.inference(img)
White-box-Cartoonization offers more control over the cartoonization process, allowing for fine-tuning of parameters and applying additional filters. photo2cartoon provides a simpler, more straightforward implementation with fewer customization options.
Both projects aim to transform photos into cartoon-style images, but White-box-Cartoonization offers a more comprehensive approach with additional features and flexibility. However, this comes at the cost of increased complexity and resource requirements. photo2cartoon, on the other hand, provides a more streamlined solution that may be easier to integrate into existing projects but with less control over the output.
[CVPR 2022] Pastiche Master: Exemplar-Based High-Resolution Portrait Style Transfer
Pros of DualStyleGAN
- Offers more diverse and flexible style transfer options
- Capable of generating high-quality, high-resolution outputs
- Provides better preservation of facial details and expressions
Cons of DualStyleGAN
- More complex implementation and potentially higher computational requirements
- May require more fine-tuning and parameter adjustments for optimal results
- Limited to facial style transfer, while Photo2Cartoon can handle full-body images
Code Comparison
DualStyleGAN:
from models.stylegan2_generator import Generator
from models.dual_generator import DualGenerator
generator = Generator(size, style_dim, n_mlp)
dual_generator = DualGenerator(generator, n_style_layers)
Photo2Cartoon:
from models.UGATIT import UGATIT
from utils.utils import *
model = UGATIT(args)
model.build_model()
DualStyleGAN focuses on a more sophisticated generator architecture, while Photo2Cartoon utilizes a UGATIT-based model. DualStyleGAN's implementation suggests a more flexible approach to style manipulation, potentially offering greater control over the output. Photo2Cartoon's code appears simpler and more straightforward, which may make it easier to use and integrate into existing projects.
PhotoMaker [CVPR 2024]
Pros of PhotoMaker
- More versatile, capable of generating various styles beyond cartoons
- Supports custom style inputs for personalized results
- Offers more advanced features like multi-subject handling
Cons of PhotoMaker
- Potentially more complex to use due to additional features
- May require more computational resources
- Less specialized for cartoon-style outputs compared to Photo2Cartoon
Code Comparison
PhotoMaker:
from photomaker import PhotoMaker
pm = PhotoMaker()
result = pm.generate(
input_image="path/to/input.jpg",
style_image="path/to/style.jpg",
num_outputs=1
)
Photo2Cartoon:
from photo2cartoon import Photo2Cartoon
p2c = Photo2Cartoon()
result = p2c.transform(
input_image="path/to/input.jpg"
)
Both repositories offer Python-based interfaces for image transformation. PhotoMaker provides more flexibility with style inputs and multiple output options, while Photo2Cartoon focuses specifically on cartoon-style conversions with a simpler API. PhotoMaker's approach allows for greater customization but may require more setup and configuration. Photo2Cartoon offers a more straightforward solution for users specifically interested in cartoon-style transformations.
Bringing Old Photo Back to Life (CVPR 2020 oral)
Pros of Bringing-Old-Photos-Back-to-Life
- Focuses on restoring and enhancing old, damaged photos
- Utilizes advanced AI techniques for face restoration and colorization
- Provides a comprehensive solution for multiple photo restoration tasks
Cons of Bringing-Old-Photos-Back-to-Life
- More complex setup and usage compared to Photo2Cartoon
- Requires more computational resources due to its comprehensive approach
- May have a steeper learning curve for users unfamiliar with deep learning frameworks
Code Comparison
Photo2Cartoon:
from photo2cartoon import Photo2Cartoon
p2c = Photo2Cartoon()
cartoon = p2c.inference(img)
Bringing-Old-Photos-Back-to-Life:
from bringing_old_photos_back_to_life import Restoration
restorer = Restoration()
restored_image = restorer.restore(image_path)
Both projects use Python and provide simple inference methods, but Bringing-Old-Photos-Back-to-Life offers a more comprehensive restoration process, while Photo2Cartoon focuses specifically on creating cartoon-style images from photos.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
人åå¡éå (Photo to Cartoon)
ä¸æç | English Version
该项ç®ä¸ºå°è§ç§æå¡éèåæ¢ç´¢é¡¹ç®ãæ¨å¯ä½¿ç¨å¾®ä¿¡æ«æä¸æ¹äºç»´ç ææç´¢âAIå¡éç§âå°ç¨åºä½éªå¡éåææã
ä¹å¯ä»¥åå¾æ们çaiå¼æ¾å¹³å°è¿è¡å¨çº¿ä½éªï¼https://ai.minivision.cn/#/coreability/cartoon
ææ¯äº¤æµQQ群ï¼937627932
Updates
2021.12.2
: å¨Replicateå¹³å°ä½éª2020.12.2
: å¼æºåºäºpaddlepaddleç项ç®photo2cartoon-paddleã2020.12.1
: å¢å onnxæµè¯æ¨¡å, 详æ è¯·è§ test_onnx.pyã
ç®ä»
人åå¡éé£æ ¼æ¸²æçç®æ æ¯ï¼å¨ä¿æåå¾åIDä¿¡æ¯å纹çç»èçåæ¶ï¼å°çå®ç §ç转æ¢ä¸ºå¡éé£æ ¼çéçå®æå¾åãæ们çæè·¯æ¯ï¼ä»å¤§éç §ç/å¡éæ°æ®ä¸ä¹ å¾ç §çå°å¡éç»çæ å°ãä¸è¬èè¨ï¼åºäºæ对æ°æ®çpix2pixæ¹æ³è½è¾¾å°è¾å¥½çå¾å转æ¢ææï¼ä½æ¬ä»»å¡çè¾å ¥è¾åºè½®å»å¹¶éä¸ä¸å¯¹åºï¼ä¾å¦å¡éé£æ ¼çç¼çæ´å¤§ãä¸å·´æ´ç¦ï¼ä¸æ对çæ°æ®ç»å¶é¾åº¦å¤§ãææ¬è¾é«ï¼å æ¤æ们éç¨unpaired image translationæ¹æ³æ¥å®ç°ã
Unpaired image translationæµæ´¾æç»å ¸æ¹æ³æ¯CycleGANï¼ä½åå§CycleGANççæç»æå¾å¾åå¨è¾ä¸ºææ¾ç伪影ä¸ä¸ç¨³å®ãè¿æç论æU-GAT-ITæåºäºä¸ç§å½ä¸åæ¹æ³ââAdaLINï¼è½å¤èªå¨è°èInstance NormåLayer Normçæ¯éï¼åç»åattentionæºå¶è½å¤å®ç°ç²¾ç¾ç人åæ¥æ¼«é£æ ¼è½¬æ¢ã
ä¸å¤¸å¼ çæ¥æ¼«é£ä¸åï¼æ们çå¡éé£æ ¼æ´ååå®ï¼è¦æ±æ¢æå¡éç»çç®æ´Qèï¼åææç¡®ç身份信æ¯ã为æ¤æ们å¢å äºFace ID Lossï¼ä½¿ç¨é¢è®ç»ç人è¸è¯å«æ¨¡åæåç §çåå¡éç»çIDç¹å¾ï¼éè¿ä½å¼¦è·ç¦»æ¥çº¦æçæçå¡éç»ã
æ¤å¤ï¼æ们æåºäºä¸ç§Soft-AdaLINï¼Soft Adaptive Layer-Instance Normalizationï¼å½ä¸åæ¹æ³ï¼å¨åè§èåæ¶å°ç¼ç å¨çåå¼æ¹å·®ï¼ç §çç¹å¾ï¼ä¸è§£ç å¨çåå¼æ¹å·®ï¼å¡éç¹å¾ï¼ç¸èåã
模åç»ææ¹é¢ï¼å¨U-GAT-ITçåºç¡ä¸ï¼æ们å¨ç¼ç å¨ä¹åå解ç å¨ä¹ååå¢å äº2个hourglass模åï¼æ¸è¿å°æå模åç¹å¾æ½è±¡åé建è½åã
ç±äºå®éªæ°æ®è¾ä¸ºå®ä¹ï¼ä¸ºäºéä½è®ç»é¾åº¦ï¼æ们å°æ°æ®å¤çæåºå®ç模å¼ãé¦å æ£æµå¾åä¸ç人è¸åå ³é®ç¹ï¼æ ¹æ®äººè¸å ³é®ç¹æè½¬æ ¡æ£å¾åï¼å¹¶æç»ä¸æ åè£åªï¼åå°è£åªåç头åè¾å ¥äººååå²æ¨¡åå»é¤èæ¯ã
Start
å®è£ ä¾èµåº
项ç®æéç主è¦ä¾èµåºå¦ä¸ï¼
- python 3.6
- pytorch 1.4
- tensorflow-gpu 1.14
- face-alignment
- dlib
- onnxruntime
Cloneï¼
git clone https://github.com/minivision-ai/photo2cartoon.git
cd ./photo2cartoon
ä¸è½½èµæº
è°·æç½ç | ç¾åº¦ç½ç æåç :y2ch
- 人åå¡éåé¢è®ç»æ¨¡åï¼photo2cartoon_weights.pt(20200504æ´æ°)ï¼åæ¾å¨
models
è·¯å¾ä¸ã - 头ååå²æ¨¡åï¼seg_model_384.pbï¼åæ¾å¨
utils
è·¯å¾ä¸ã - 人è¸è¯å«é¢è®ç»æ¨¡åï¼model_mobilefacenet.pthï¼åæ¾å¨
models
è·¯å¾ä¸ãï¼From: InsightFace_Pytorchï¼ - å¡éç»å¼æºæ°æ®ï¼
cartoon_data
ï¼å å«trainB
åtestB
ã - 人åå¡éåonnx模åï¼photo2cartoon_weights.onnx è°·æç½çï¼åæ¾å¨
models
è·¯å¾ä¸ã
æµè¯
å°ä¸å¼ æµè¯ç §çï¼äºæ´²å¹´è½»å¥³æ§ï¼è½¬æ¢ä¸ºå¡éé£æ ¼ï¼
python test.py --photo_path ./images/photo_test.jpg --save_path ./images/cartoon_result.png
æµè¯onnx模å
python test_onnx.py --photo_path ./images/photo_test.jpg --save_path ./images/cartoon_result.png
è®ç»
1.æ°æ®åå¤
è®ç»æ°æ®å æ¬çå®ç §çåå¡éç»åï¼ä¸ºéä½è®ç»å¤æ度ï¼æ们对两类æ°æ®è¿è¡äºå¦ä¸é¢å¤çï¼
- æ£æµäººè¸åå ³é®ç¹ã
- æ ¹æ®å ³é®ç¹æè½¬æ ¡æ£äººè¸ã
- å°å ³é®ç¹è¾¹çæ¡æåºå®çæ¯ä¾æ©å¼ 并è£åªåºäººè¸åºåã
- 使ç¨äººååå²æ¨¡åå°èæ¯ç½®ç½ã
æ们å¼æºäº204å¼ å¤çåçå¡éç»æ°æ®ï¼æ¨è¿éåå¤çº¦1000å¼ äººåç §çï¼ä¸ºå¹é å¡éæ°æ®ï¼å°½é使ç¨äºæ´²å¹´è½»å¥³æ§ç §çï¼äººè¸å¤§å°æå¥½è¶ è¿200x200åç´ ï¼ï¼ä½¿ç¨ä»¥ä¸å½ä»¤è¿è¡é¢å¤çï¼
python data_process.py --data_path YourPhotoFolderPath --save_path YourSaveFolderPath
å°å¤çåçæ°æ®æç
§ä»¥ä¸å±çº§åæ¾ï¼trainA
ãtestA
ä¸åæ¾ç
§ç头åæ°æ®ï¼trainB
ãtestB
ä¸åæ¾å¡é头åæ°æ®ã
âââ dataset
âââ photo2cartoon
âââ trainA
âââ xxx.jpg
âââ yyy.png
âââ ...
âââ trainB
âââ zzz.jpg
âââ www.png
âââ ...
âââ testA
âââ aaa.jpg
âââ bbb.png
âââ ...
âââ testB
âââ ccc.jpg
âââ ddd.png
âââ ...
2.è®ç»
éæ°è®ç»:
python train.py --dataset photo2cartoon
å è½½é¢è®ç»åæ°:
python train.py --dataset photo2cartoon --pretrained_weights models/photo2cartoon_weights.pt
å¤GPUè®ç»(ä»å»ºè®®ä½¿ç¨batch_size=1ï¼åå¡è®ç»):
python train.py --dataset photo2cartoon --batch_size 4 --gpu_ids 0 1 2 3
Q&A
Qï¼ä¸ºä»ä¹å¼æºçå¡éå模åä¸å°ç¨åºä¸çæææå·®å¼ï¼
Aï¼å¼æºæ¨¡åçè®ç»æ°æ®æ¶éèªäºèç½ï¼ä¸ºäºå¾å°æ´å ç²¾ç¾çææï¼æ们å¨è®ç»å°ç¨åºä¸å¡éå模åæ¶ï¼éç¨äºå®å¶çå¡éç»æ°æ®ï¼200å¤å¼ ï¼ï¼ä¸å¢å¤§äºè¾å ¥å辨çãæ¤å¤ï¼å°ç¨åºä¸ç人è¸ç¹å¾æåå¨éç¨èªç çè¯å«æ¨¡åï¼ææä¼äºæ¬é¡¹ç®ä½¿ç¨çå¼æºè¯å«æ¨¡åã
Qï¼å¦ä½éåæææ好ç模åï¼
Aï¼é¦å è®ç»æ¨¡å200k iterationsï¼ç¶å使ç¨FIDææ æéåºæä¼æ¨¡åï¼æç»æéåºç模å为è¿ä»£90k iterationsæ¶ç模åã
Qï¼å ³äºäººè¸ç¹å¾æå模åã
Aï¼å®éªä¸æ们åç°ï¼ä½¿ç¨èªç çè¯å«æ¨¡å计ç®Face ID Lossè®ç»ææè¿å¥½äºä½¿ç¨å¼æºè¯å«æ¨¡åï¼è¥è®ç»ææåºç°é²æ£æ§é®é¢ï¼å¯å°è¯å°Face ID Lossæéç½®é¶ã
Qï¼äººååå²æ¨¡åæ¯å¦è½ç¨ä¸åå²å身åï¼
Aï¼ä¸è½ã该模åæ¯é对æ¬é¡¹ç®è®ç»çä¸ç¨æ¨¡åï¼éå è£åªåºäººè¸åºååè¾å ¥ã
Tips
æ们å¼æºç模åæ¯åºäºäºæ´²å¹´è½»å¥³æ§è®ç»çï¼å¯¹äºå ¶ä»äººç¾¤è¦çä¸è¶³ï¼æ¨å¯æ ¹æ®ä½¿ç¨åºæ¯èªè¡æ¶éç¸åºäººç¾¤çæ°æ®è¿è¡è®ç»ãæ们çå¼æ¾å¹³å°æä¾äºè½å¤è¦çå类人群çå¡éåæå¡ï¼æ¨å¯åå¾ä½éªãå¦æå®å¶å¡éé£æ ¼éæ±è¯·èç³»åå¡:18852075216ã
åè
U-GAT-IT: Unsupervised Generative Attentional Networks with Adaptive Layer-Instance Normalization for Image-to-Image Translation [Paper][Code]
Top Related Projects
[Open Source]. The improved version of AnimeGAN. Landscape photos/videos to anime
Official tensorflow implementation for CVPR2020 paper “Learning to Cartoonize Using White-box Cartoon Representations”
[CVPR 2022] Pastiche Master: Exemplar-Based High-Resolution Portrait Style Transfer
PhotoMaker [CVPR 2024]
Bringing Old Photo Back to Life (CVPR 2020 oral)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot