Skip to content

Latest commit

 

History

History
134 lines (89 loc) · 3.63 KB

File metadata and controls

134 lines (89 loc) · 3.63 KB

UGATIT_83w

Module Name UGATIT_83w
Category Image editing
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:

  • Module Introduction

    • UGATIT can transfer the input face image into the anime style.

II. Installation

III. Module API Prediction

  • 1、Prediction Code Example

    • import cv2
      import paddlehub as hub
      
      model = hub.Module(name='UGATIT_83w', use_gpu=False)
      result = model.style_transfer(images=[cv2.imread('/PATH/TO/IMAGE')])
      # or
      # result = model.style_transfer(paths=['/PATH/TO/IMAGE'])
  • 2、API

    • def style_transfer(
          self,
          images=None,
          paths=None,
          batch_size=1,
          output_dir='output',
          visualization=False
      )
      • Style transfer API, convert the input face image into anime style.

      • Parameters

        • images (list[numpy.ndarray]): Image data, ndarray.shape is in the format [H, W, C], BGR.
        • paths (list[str]): image path,default is None;
        • batch_size (int): Batch size, default is 1;
        • visualization (bool): Whether to save the recognition results as picture files, default is False.
        • output_dir (str): Save path of images, output by default.

        NOTE: Choose one of paths and images to provide data.

      • Return

        • res (list[numpy.ndarray]): Result, ndarray.shape is in the format [H, W, C].

IV. Server Deployment

  • PaddleHub Serving can deploy an online service of Style transfer task.

  • Step 1: Start PaddleHub Serving

    • Run the startup command:

      • $ hub serving start -m UGATIT_83w
    • 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_83w"
        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