Module Name | UGATIT_100w |
---|---|
Category | image generation |
Network | U-GAT-IT |
Dataset | selfie2anime |
Fine-tuning supported or not | No |
Module Size | 41MB |
Latest update date | 2021-02-26 |
Data indicators | - |
-
- UGATIT is a model for style transfer. This module can be used to transfer a face image to cartoon style. For more information, please refer to UGATIT-Paddle Project.
-
-
paddlepaddle >= 1.8.0
-
paddlehub >= 1.8.0 | How to install PaddleHub
-
-
-
$ hub install UGATIT_100w
- In case of any problems during installation, please refer to: Windows_Quickstart | Linux_Quickstart | Mac_Quickstart
-
-
-
import paddlehub as hub import cv2 model = hub.Module(name="UGATIT_100w") result = model.style_transfer(images=[cv2.imread('/PATH/TO/IMAGE')]) # or # result = model.style_transfer(paths=['/PATH/TO/IMAGE'])
-
-
-
def style_transfer(images=None, paths=None, batch_size=1, output_dir='output', visualization=False)
-
Style transfer API.
-
Parameters
- images (list[numpy.ndarray]): image data, ndarray.shape is in the format [H, W, C], BGR;
- paths (list[str]): image path;
- batch_size (int): the size of batch;
- visualization (bool): Whether to save the results as picture files;
- output_dir (str): save path of images;
NOTE: choose one parameter to provide data from paths and images
-
Return
- res (list[numpy.ndarray]): result list,ndarray.shape is [H, W, C]
-
-
-
PaddleHub Serving can deploy an online service of style transfer.
-
-
Run the startup command:
-
$ hub serving start -m UGATIT_100w
-
The servitization API is now deployed and the default port number is 8866.
-
NOTE: If GPU is used for prediction, set CUDA_VISIBLE_DEVICES environment variable before the service, otherwise it need not be set.
-
-
-
With a configured server, use the following lines of code to send the prediction request and obtain the result
-
import requests import json import cv2 import base64 def cv2_to_base64(image): data = cv2.imencode('.jpg', image)[1] return base64.b64encode(data.tostring()).decode('utf8') # Send an HTTP request data = {'images':[cv2_to_base64(cv2.imread("/PATH/TO/IMAGE"))]} headers = {"Content-type": "application/json"} url = "http://127.0.0.1:8866/predict/UGATIT_100w" r = requests.post(url=url, headers=headers, data=json.dumps(data)) # print prediction results print(r.json()["results"])
-
-
1.0.0
First release
-
$ hub install UGATIT_100w==1.0.0
-