diff --git a/.DS_Store b/.DS_Store index 5a7b06f..094c66e 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/README.md b/README.md index 43a9562..fe2885b 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ Official implementation of DCT-Net for Portrait Stylization. (2022-08-08) The pertained model and infer code of 'anime' style is available now. More styles coming soon. +(2022-10-09) The multi-style pre-trained models (3d, handdrawn, sketch, artstyle) and usage are available now. + ## Web Demo - Integrated into [Huggingface Spaces 🤗](https://huggingface.co/spaces) using [Gradio](https://github.com/gradio-app/gradio). Try out the Web Demo [![Hugging Face Spaces](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue)](https://huggingface.co/spaces/SIGGRAPH2022/DCT-Net) @@ -72,6 +74,47 @@ python run_sdk.py python run.py ``` +## Multi-style + +Multi-style models and usages are provided here. + +![demo_img](assets/styles.png) + +```bash +git clone https://github.com/menyifang/DCT-Net.git +cd DCT-Net +``` + +### Multi-style models download + +- upgrade modelscope>=0.4.7 + +```bash +conda activate dctnet +pip install --upgrade "modelscope[cv]" -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html +``` + +- Download the pretrained models with specific styles [option: anime, 3d, handdrawn, sketch, artstyle] +```bash +python multi-style/download.py --style 3d +``` + +### Inference + +- Quick infer with python SDK, style choice [option: anime, 3d, handdrawn, sketch, artstyle] + +```bash +python multi-style/run_sdk.py --style 3d +``` + +- Infer from source code & downloaded models +```bash +python multi-style/run.py --style 3d +``` + + + + ## Acknowledgments diff --git a/assets/styles.png b/assets/styles.png new file mode 100644 index 0000000..da767ea Binary files /dev/null and b/assets/styles.png differ diff --git a/input.png b/input.png index 74f5ff9..6202c0f 100644 Binary files a/input.png and b/input.png differ diff --git a/multi-style/download.py b/multi-style/download.py new file mode 100644 index 0000000..9ebc2c2 --- /dev/null +++ b/multi-style/download.py @@ -0,0 +1,35 @@ +from modelscope.hub.snapshot_download import snapshot_download +import argparse + + + +def process(args): + style = args.style + print('download %s model'%style) + if style == "anime": + model_dir = snapshot_download('damo/cv_unet_person-image-cartoon_compound-models', cache_dir='.') + + elif style == "3d": + model_dir = snapshot_download('damo/cv_unet_person-image-cartoon-3d_compound-models', cache_dir='.') + + elif style == "handdrawn": + model_dir = snapshot_download('damo/cv_unet_person-image-cartoon-handdrawn_compound-models', cache_dir='.') + + elif style == "sketch": + model_dir = snapshot_download('damo/cv_unet_person-image-cartoon-sketch_compound-models', cache_dir='.') + + elif style == "artstyle": + model_dir = snapshot_download('damo/cv_unet_person-image-cartoon-artstyle_compound-models', cache_dir='.') + + else: + print('no such style %s'% style) + + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--style', type=str, default='anime') + args = parser.parse_args() + + process(args) diff --git a/multi-style/run.py b/multi-style/run.py new file mode 100644 index 0000000..3a42889 --- /dev/null +++ b/multi-style/run.py @@ -0,0 +1,49 @@ +import sys +sys.path.append('.') + +import cv2 +from source.cartoonize import Cartoonizer +import os +import argparse + + +def process(args): + + style = args.style + if style == "anime": + algo = Cartoonizer(dataroot='damo/cv_unet_person-image-cartoon_compound-models') + + elif style == "3d": + algo = Cartoonizer(dataroot='damo/cv_unet_person-image-cartoon-3d_compound-models') + + elif style == "handdrawn": + algo = Cartoonizer(dataroot='damo/cv_unet_person-image-cartoon-handdrawn_compound-models') + + elif style == "sketch": + algo = Cartoonizer(dataroot='damo/cv_unet_person-image-cartoon-sketch_compound-models') + + elif style == "artstyle": + algo = Cartoonizer(dataroot='damo/cv_unet_person-image-cartoon-artstyle_compound-models') + + else: + print('no such style %s' % style) + return 0 + + img = cv2.imread('input.png')[..., ::-1] + result = algo.cartoonize(img) + cv2.imwrite('result1_%s.png'%style, result) + + print('finished!') + + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--style', type=str, default='anime') + args = parser.parse_args() + + process(args) + + + diff --git a/multi-style/run_sdk.py b/multi-style/run_sdk.py new file mode 100644 index 0000000..0626744 --- /dev/null +++ b/multi-style/run_sdk.py @@ -0,0 +1,42 @@ +import cv2, argparse +from modelscope.outputs import OutputKeys +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks + +def process(args): + style = args.style + print('choose style %s'%style) + if style == "anime": + img_cartoon = pipeline(Tasks.image_portrait_stylization, + model='damo/cv_unet_person-image-cartoon_compound-models') + elif style == "3d": + img_cartoon = pipeline(Tasks.image_portrait_stylization, + model='damo/cv_unet_person-image-cartoon-3d_compound-models') + elif style == "handdrawn": + img_cartoon = pipeline(Tasks.image_portrait_stylization, + model='damo/cv_unet_person-image-cartoon-handdrawn_compound-models') + elif style == "sketch": + img_cartoon = pipeline(Tasks.image_portrait_stylization, + model='damo/cv_unet_person-image-cartoon-sketch_compound-models') + elif style == "artstyle": + img_cartoon = pipeline(Tasks.image_portrait_stylization, + model='damo/cv_unet_person-image-cartoon-artstyle_compound-models') + else: + print('no such style %s'% style) + return 0 + + + result = img_cartoon('input.png') + + cv2.imwrite('result_%s.png'%style, result[OutputKeys.OUTPUT_IMG]) + print('finished!') + + + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--style', type=str, default='anime') + args = parser.parse_args() + + process(args)