update multi-style models

pull/29/head
menyifang 2 years ago
parent da7507498a
commit 6d5917c982

BIN
.DS_Store vendored

Binary file not shown.

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 942 KiB

After

Width:  |  Height:  |  Size: 1.1 MiB

@ -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)

@ -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)

@ -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)
Loading…
Cancel
Save