{"id":23530316,"url":"https://github.com/vinesmsuic/white-box-cartoonization-pytorch","last_synced_at":"2025-04-22T17:25:07.742Z","repository":{"id":37322330,"uuid":"456483294","full_name":"vinesmsuic/White-box-Cartoonization-PyTorch","owner":"vinesmsuic","description":"PyTorch implementation of “Learning to Cartoonize Using White-box Cartoon Representations” (CVPR 2020). Now with gradio demo","archived":false,"fork":false,"pushed_at":"2023-01-16T02:11:23.000Z","size":17536,"stargazers_count":42,"open_issues_count":2,"forks_count":10,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T17:25:04.014Z","etag":null,"topics":["artificial-intelligence","deep-learning","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vinesmsuic.png","metadata":{"files":{"readme":"README.MD","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-07T11:48:05.000Z","updated_at":"2025-03-23T22:06:43.000Z","dependencies_parsed_at":"2023-01-21T10:17:43.517Z","dependency_job_id":null,"html_url":"https://github.com/vinesmsuic/White-box-Cartoonization-PyTorch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinesmsuic%2FWhite-box-Cartoonization-PyTorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinesmsuic%2FWhite-box-Cartoonization-PyTorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinesmsuic%2FWhite-box-Cartoonization-PyTorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinesmsuic%2FWhite-box-Cartoonization-PyTorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinesmsuic","download_url":"https://codeload.github.com/vinesmsuic/White-box-Cartoonization-PyTorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250286069,"owners_count":21405357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["artificial-intelligence","deep-learning","pytorch"],"created_at":"2024-12-25T21:16:36.592Z","updated_at":"2025-04-22T17:25:07.707Z","avatar_url":"https://github.com/vinesmsuic.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# White-box-Cartoonization (PyTorch)\n\nUnofficial PyTorch implementation of White-box-Cartoonization. We followed the original Tensorflow training implementation from the paper author ([Xinrui Wang](https://github.com/SystemErrorWang/White-box-Cartoonization)).\n\n**Key difference from Tensorflow implementation:**\n* Its PyTorch.\n* We used PyTorchVGG19 instead of CaffeVGG16 model, which has a different range of input/output and std/mean.\n\n![](https://github.com/SystemErrorWang/White-box-Cartoonization/raw/master/images/method.jpg)\n\n\n\n# Our Results \n\n\n* Images:\n\u003cp align = 'center'\u003e\n\u003cimg src = 'https://i.imgur.com/834daEl.jpg' width = '400px'\u003e\n\u003cimg src = 'https://i.imgur.com/UtVkrZw.png' width = '400px'\u003e\n    \n    \n\u003cimg src = 'https://i.imgur.com/d2AR2Dj.jpg' width = '400px'\u003e\n\u003cimg src = 'https://i.imgur.com/HGkBgYU.png' width = '400px'\u003e\n    \n\u003cimg src = 'https://i.imgur.com/TKNqrIC.jpg' width = '400px'\u003e\n\u003cimg src = 'https://i.imgur.com/hlzOATo.png' width = '400px'\u003e\n    \n\u003cimg src = 'https://i.imgur.com/Yp81tY6.jpg' width = '400px'\u003e\n\u003cimg src = 'https://i.imgur.com/y5xPwRg.png' width = '400px'\u003e\n    \n\u003cimg src = 'https://i.imgur.com/tBzdzU1.jpg' width = '400px'\u003e\n\u003cimg src = 'https://i.imgur.com/UyKpO4d.png' width = '400px'\u003e\n    \n\u003c/p\u003e\n\n# Repo Structure\n\n```python\n├─checkpoints\n│  └─project_name\n├─data\n│  ├─train \n│  │  ├─cartoon # You put cartoon images here\n│  │  └─photo   # You put photo images here\n│  └─val\n│      └─photo # You put photo images here\n└─results\n    ├─.... # folder will be created automatically\n```\n\n\n# Dependencies\n\n* PyTorch\n\nSome uncommon dependencies below:\n```bash\npip install -U albumentations\npip install more-itertools\npip install tqdm\npip install gradio\n```\n\n# Image inference Demo\n\nI have only trained a model on scenery images only.\n\n```bash\npython3 image_infer_demo.py -w weights/sceneryonly.pth.tar\n```\nShould start a demo like this:\n\u003cimg src = 'https://i.imgur.com/rH7DVhy.png' width = '100%'\u003e\n\n# To start training\n\n0. Read https://vinesmsuic.github.io/i2i-wbcartoonization/ to understand the implementation\n1. Prepare the photo and cartoon data\n2. Get the pre-trained VGG19 weight and put it in the root folder : \n   https://download.pytorch.org/models/vgg19-dcbb9e9d.pth\n3. Edit `config.py`\n4. Training (if you need to use the parser, type `python train.py -h` to see existing options\n\n```bash\npython train.py\n```\n\n* The training consist of initialization phase and training phase.\n* Wait for a long time and see the results at `results` folder\n\n# More options:\n\n## Train\n```\nusage: train.py [-h] [--name NAME] [--batch_size BATCH_SIZE]\n                [--num_workers NUM_WORKERS]\n                [--save_model_freq SAVE_MODEL_FREQ]\n                [--save_img_freq SAVE_IMG_FREQ] [--epochs EPOCHS]\n                [--lambda_surface LAMBDA_SURFACE]\n                [--lambda_texture LAMBDA_TEXTURE]\n                [--lambda_structure LAMBDA_STRUCTURE]\n                [--lambda_content LAMBDA_CONTENT]\n                [--lambda_variation LAMBDA_VARIATION]\n\ntrain.py: Model training script of White-box Cartoonization. Pretraining\nincluded.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --name NAME           project name. default name:project_name\n  --batch_size BATCH_SIZE\n                        batch size. default batch size:32\n  --num_workers NUM_WORKERS\n                        number of workers. default number of workers:8\n  --save_model_freq SAVE_MODEL_FREQ\n                        saving model each N epochs. default value:5\n  --save_img_freq SAVE_IMG_FREQ\n                        saving training image each N steps. default value:1000\n  --epochs EPOCHS       default value:200\n  --lambda_surface LAMBDA_SURFACE\n                        lambda value of surface rep. default:0.1\n  --lambda_texture LAMBDA_TEXTURE\n                        lambda value of texture rep. default:1\n  --lambda_structure LAMBDA_STRUCTURE\n                        lambda value of structure rep. default:200\n  --lambda_content LAMBDA_CONTENT\n                        lambda value of content loss. default:180\n  --lambda_variation LAMBDA_VARIATION\n                        lambda value of variation loss. default:10000\n```\n\n## Test\n```\nusage: test.py [-h] [--dataroot DATAROOT] [--weight_path WEIGHT_PATH] [--dest_folder DEST_FOLDER] [--sample_size SAMPLE_SIZE] [--shuffle] [--concat_img]\n               [--no_post_processing]\n\ntest.py: Model testing script of White-box Cartoonization. For inference, please refer to inference.py\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --dataroot DATAROOT   path to image data test folder. default path:data\\val\\photo\n  --weight_path WEIGHT_PATH\n                        path to model weight file. default path:checkpoints\\project_name\\i_gen.pth.tar\n  --dest_folder DEST_FOLDER\n                        path to destination folder for saving images. default path:results\\project_name\\test\n  --sample_size SAMPLE_SIZE\n                        only inference certain number of images. default=50.\n  --shuffle             shuffle test data\n  --concat_img          concat input and output images instead of separated save files\n  --no_post_processing  disable post_processing (not recommended). This will probably cause output to have terrible noise\n```\n\n## Inference (Support Video)\n```\nusage: inference.py [-h] -s SOURCE -w WEIGHT_PATH [--batch_size BATCH_SIZE] --dest_folder DEST_FOLDER\n                    [--suffix SUFFIX]\n\ninference.py: Model inference script of White-box Cartoonization.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -s SOURCE, --source SOURCE\n                        filepath to a source image or a video or a images folder.\n  -w WEIGHT_PATH, --weight_path WEIGHT_PATH\n                        path to model weight file.\n  --batch_size BATCH_SIZE\n                        batch size for video inference. default size:32\n  --dest_folder DEST_FOLDER\n                        Destination folder path for saving results.\n  --suffix SUFFIX       Output suffix.\n```\n\nFor example:\n```bash\npython3 image_infer_demo.py -w weights/sceneryonly.pth.tar --batch_size 8 -s input.mp4 --dest_folder .\n```\n\n## Compress Inference Video (h265)\n```\nffmpeg -i input.mp4 -vcodec libx265 -crf 28 output.mp4\n```\n\n\n# TODO\n- [ ] ~~Automatic Mixed Precision~~\n- [ ] ~~LR Scheduler~~\n- [ ] Loss visualization\n- [ ] WandB visualization\n- [ ] Adding Face data for Training\n- [x] Parser\n- [x] Post processing\n- [x] Inference Code\n- [x] Explaining Code\n- [X] Live Demo with Gradio\n\n# Working Environments\n* Windows with CUDA\n* Ubuntu with CUDA\n\n# Citing\nIf you use this repository in your research, consider citing it using the following Bibtex entry:\n```bibtex\n@InProceedings{Wang_2020_CVPR, \n    author = {Wang, Xinrui and Yu, Jinze}, \n    title = {Learning to Cartoonize Using White-Box Cartoon Representations}, \n    booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)}, \n    month = {June}, \n    year = {2020} \n}\n\n@misc{Ku_PytorchWBCartoon,\n  author={Wing-Fung Ku},\n  title={White-box-Cartoonization-PyTorch: Full PyTorch implementation of White-Box Cartoon Representations},\n  month={May},\n  year={2022},\n  howpublished={\\url{https://github.com/vinesmsuic/White-box-Cartoonization-PyTorch}},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinesmsuic%2Fwhite-box-cartoonization-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinesmsuic%2Fwhite-box-cartoonization-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinesmsuic%2Fwhite-box-cartoonization-pytorch/lists"}