Skip to content

Latest commit

 

History

History
173 lines (115 loc) · 5.25 KB

File metadata and controls

173 lines (115 loc) · 5.25 KB

dcscn

Module Name dcscn
Category Image editing
Network dcscn
Dataset DIV2k
Fine-tuning supported or not No
Module Size 260KB
Data indicators PSNR37.63
Data indicators 2021-02-26

I. Basic Information

  • Application Effect Display

    • Sample results:

  • Module Introduction

    • DCSCN is a super resolution model based on 'Fast and Accurate Image Super Resolution by Deep CNN with Skip Connection and Network in Network'. The model uses residual structure and skip connections to extract local and global features. It uses a parallel 1*1 convolutional network to learn detailed features to improve model performance. This model provides super resolution result with scale factor x2.

    • For more information, please refer to: dcscn

II. Installation

III. Module API Prediction

  • 1、Command line Prediction

  • 2、Prediction Code Example

    • import cv2
      import paddlehub as hub
      
      sr_model = hub.Module(name='dcscn')
      im = cv2.imread('/PATH/TO/IMAGE').astype('float32')
      res = sr_model.reconstruct(images=[im], visualization=True)
      print(res[0]['data'])
  • 3、API

    • def reconstruct(images=None,
                      paths=None,
                      use_gpu=False,
                      visualization=False,
                      output_dir="dcscn_output")
      • Prediction API.

      • Parameter

        • images (list[numpy.ndarray]): Image data,ndarray.shape is in the format [H, W, C],BGR.
        • paths (list[str]): image path.
        • use_gpu (bool): Use GPU or not. set the CUDA_VISIBLE_DEVICES environment variable first if you are using GPU.
        • visualization (bool): Whether to save the recognition results as picture files.
        • output_dir (str): Save path of images, "dcscn_output" by default.
      • Return

        • res (list[dict]): The list of model results, where each element is dict and each field is:
          • save_path (str, optional): Save path of the result, save_path is '' if no image is saved.
          • data (numpy.ndarray): Result of super resolution.
    • def save_inference_model(dirname)
      • Save the model to the specified path.

      • Parameters

        • dirname: Model save path.

IV. Server Deployment

  • PaddleHub Serving can deploy an online service of super resolution.

  • Step 1: Start PaddleHub Serving

    • Run the startup command:

      • $ hub serving start -m dcscn
    • 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 base64
        
        import cv2
        import numpy as np
        
        def cv2_to_base64(image):
            data = cv2.imencode('.jpg', image)[1]
            return base64.b64encode(data.tostring()).decode('utf8')
        def base64_to_cv2(b64str):
            data = base64.b64decode(b64str.encode('utf8'))
            data = np.fromstring(data, np.uint8)
            data = cv2.imdecode(data, cv2.IMREAD_COLOR)
            return data
        
        
        org_im = cv2.imread('/PATH/TO/IMAGE')
        data = {'images':[cv2_to_base64(org_im)]}
        headers = {"Content-type": "application/json"}
        url = "http://127.0.0.1:8866/predict/dcscn"
        r = requests.post(url=url, headers=headers, data=json.dumps(data))
        
        sr = np.expand_dims(cv2.cvtColor(base64_to_cv2(r.json()["results"][0]['data']), cv2.COLOR_BGR2GRAY), axis=2)
        shape =sr.shape
        org_im = cv2.cvtColor(org_im, cv2.COLOR_BGR2YUV)
        uv = cv2.resize(org_im[...,1:], (shape[1], shape[0]), interpolation=cv2.INTER_CUBIC)
        combine_im =  cv2.cvtColor(np.concatenate((sr, uv), axis=2), cv2.COLOR_YUV2BGR)
        cv2.imwrite('dcscn_X2.png', combine_im)
        print("save image as dcscn_X2.png")

V. Release Note

  • 1.0.0

    First release

  • 1.1.0

    Remove Fluid API

    $ hub install dcscn == 1.1.0