|
|
|
# Cartoonize with CartoonGAN
|
|
|
|
|
|
|
|
*author: Shiyu*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Description
|
|
|
|
|
|
|
|
Convert an image into an cartoon image using [`CartoonGAN`](https://github.com/Yijunmaverick/CartoonGAN-Test-Pytorch-Torch).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Code Example
|
|
|
|
|
|
|
|
Load an image from path './test.png'.
|
|
|
|
|
|
|
|
*Write the pipeline in simplified style*:
|
|
|
|
|
|
|
|
```python
|
|
|
|
import towhee
|
|
|
|
|
|
|
|
towhee.glob('./test.png') \
|
|
|
|
.image_decode() \
|
|
|
|
.img2img_translation.cartoongan(model_name = 'Hayao') \
|
|
|
|
.show()
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="./results1.png" height="150px"/>
|
|
|
|
|
|
|
|
*Write a pipeline with explicit inputs/outputs name specifications:*
|
|
|
|
|
|
|
|
```python
|
|
|
|
import towhee
|
|
|
|
|
|
|
|
towhee.glob['path']('./test.png') \
|
|
|
|
.image_decode['path', 'origin']() \
|
|
|
|
.img2img_translation.cartoongan['origin', 'hayao'](model_name = 'Hayao') \
|
|
|
|
.img2img_translation.cartoongan['origin', 'hosoda'](model_name = 'Hosoda') \
|
|
|
|
.img2img_translation.cartoongan['origin', 'paprika'](model_name = 'Paprika') \
|
|
|
|
.img2img_translation.cartoongan['origin', 'shinkai'](model_name = 'Shinkai') \
|
|
|
|
.select['origin', 'hayao', 'hosoda', 'paprika', 'shinkai']() \
|
|
|
|
.show()
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="./results2.png" alt="results1" height="150px"/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Factory Constructor
|
|
|
|
|
|
|
|
Create the operator via the following factory method
|
|
|
|
|
|
|
|
***img2img_translation.cartoongan(model_name = 'which anime model to use')***
|
|
|
|
|
|
|
|
Model options:
|
|
|
|
|
|
|
|
- Hayao
|
|
|
|
- Hosoda
|
|
|
|
- Paprika
|
|
|
|
- Shinkai
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<br />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Interface
|
|
|
|
|
|
|
|
Takes in a numpy rgb image in channels first. It transforms input into animated image in numpy form.
|
|
|
|
|
|
|
|
|
|
|
|
**Parameters:**
|
|
|
|
|
|
|
|
***model_name***: *str*
|
|
|
|
|
|
|
|
Which model to use for transfer.
|
|
|
|
|
|
|
|
***framework***: *str*
|
|
|
|
|
|
|
|
Which ML framework being used, for now only supports PyTorch.
|
|
|
|
|
|
|
|
***device***: *str*
|
|
|
|
|
|
|
|
Which device being used('cpu' or 'cuda'), defaults to 'cpu'.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
**Returns**: *towhee.types.Image (a sub-class of numpy.ndarray)*
|
|
|
|
|
|
|
|
The new image.
|
|
|
|
|
|
|
|
|