Skip to content

Latest commit

 

History

History
139 lines (95 loc) · 3.81 KB

File metadata and controls

139 lines (95 loc) · 3.81 KB

UGATIT_100w

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 -

I.Basic Information

  • Application Effect Display

    • Sample results:


      Input image

      Output image

  • Module Introduction

    • 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.

II.Installation

III.Module API Prediction

  • 1、Prediction Code Example

    • 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'])
  • 2、API

    • 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]

IV.Server Deployment

  • PaddleHub Serving can deploy an online service of style transfer.

  • Step 1: Start PaddleHub Serving

    • 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.

  • Step 2: Send a predictive request

    • 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"])

V.Release Note

  • 1.0.0

    First release

    • $ hub install UGATIT_100w==1.0.0