README_en.md 5.4 KB
Newer Older
H
haoyuying 已提交
1 2 3 4
# ace2p

|Module Name|ace2p|
| :--- | :---: | 
H
haoyuying 已提交
5
|Category|Image segmentation|
H
haoyuying 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|Network|ACE2P|
|Dataset|LIP|
|Fine-tuning supported or not|No|
|Module Size|259MB|
|Data indicators|-|
|Latest update date |2021-02-26|


## I. Basic Information 

- ### Application Effect Display

  - Network architecture:
      <p align="center">
      <img src="https://bj.bcebos.com/paddlehub/paddlehub-img/ace2p_network.jpg" hspace='10'/> <br />
      </p>

  - Color palette

      <p align="left">
      <img src="https://bj.bcebos.com/paddlehub/paddlehub-img/ace2p_palette.jpg" hspace='10'/> <br />
      </p>

  - Sample results:
      <p align="center">
      <img src="https://user-images.githubusercontent.com/35907364/130913092-312a5f37-842e-4fd0-8db4-5f853fd8419f.jpg" width = "337" height = "505" hspace='10'/> <img src="https://user-images.githubusercontent.com/35907364/130913765-c9572c77-c6bf-46ec-9653-04ff356b4b85.png" width = "337" height = "505" hspace='10'/>
      </p>

- ### Module Introduction

  - Human Parsing is a fine-grained semantic segmentation task that aims to identify the components (for example, body parts and clothing) of a human image at the pixel level.  The PaddleHub Module uses ResNet101 as the backbone network, and accepts input image sizes of 473x473x3.



## II. Installation

- ### 1、Environmental Dependence

  - paddlepaddle >= 2.0.0

  - paddlehub >= 2.0.0  

- ### 2、Installation

    - ```shell
      $ hub install ace2p
      ```
H
haoyuying 已提交
53 54
    - In case of any problems during installation, please refer to:[Windows_Quickstart](../../../../docs/docs_en/get_start/windows_quickstart.md)
    | [Linux_Quickstart](../../../../docs/docs_en/get_start/linux_quickstart.md) | [Mac_Quickstart](../../../../docs/docs_en/get_start/mac_quickstart.md)  
H
haoyuying 已提交
55 56 57 58 59 60


## III. Module API Prediction

- ### 1、Command line Prediction

H
haoyuying 已提交
61 62 63 64 65 66
    - ```shell
      $ hub run ace2p --input_path "/PATH/TO/IMAGE"
      ```

    - If you want to call the Hub module through the command line, please refer to: [PaddleHub Command Line Instruction](../../../../docs/docs_en/tutorial/cmd_usage.rst)

H
haoyuying 已提交
67 68 69

- ### 2、Prediction Code Example

H
haoyuying 已提交
70
  - ```python
H
haoyuying 已提交
71 72 73 74 75 76 77
    import paddlehub as hub
    import cv2

    human_parser = hub.Module(name="ace2p")
    result = human_parser.segmentation(images=[cv2.imread('/PATH/TO/IMAGE')])
    ```
  
H
haoyuying 已提交
78 79 80 81 82 83 84 85 86 87
- ### 3、API

  - ```python
    def segmentation(images=None,
                    paths=None,
                    batch_size=1,
                    use_gpu=False,
                    output_dir='ace2p_output',
                    visualization=False):
    ```
H
haoyuying 已提交
88

H
haoyuying 已提交
89
    - Prediction API, used for human parsing.
H
haoyuying 已提交
90 91 92

    - **Parameter**

H
haoyuying 已提交
93 94 95 96 97
        * images (list\[numpy.ndarray\]): Image data, ndarray.shape is in the format [H, W, C], BGR.
        * paths (list\[str\]): Image path.
        * batch\_size (int): Batch size.
        * use\_gpu (bool): Use GPU or not. **set the CUDA_VISIBLE_DEVICES environment variable first if you are using GPU**
        * output\_dir (str): Save path of output, default is 'ace2p_output'.
H
haoyuying 已提交
98 99 100 101 102
        * visualization (bool): Whether to save the recognition results as picture files.

    - **Return**

        * res (list\[dict\]): The list of recognition results, where each element is dict and each field is: 
H
haoyuying 已提交
103
            * save\_path (str, optional): Save path of the result.
H
haoyuying 已提交
104 105 106
            * data (numpy.ndarray): The result of portrait segmentation. 


H
haoyuying 已提交
107 108 109 110 111 112
  - ```python
    def save_inference_model(dirname,
                            model_filename=None,
                            params_filename=None,
                            combined=True)
    ```
H
haoyuying 已提交
113 114 115 116 117

    - Save the model to the specified path.

    - **Parameters**
      * dirname: Save path.
H
haoyuying 已提交
118 119
      * model\_filename: mMdel file name,defalt is \_\_model\_\_
      * params\_filename: Parameter file name,defalt is \_\_params\_\_(Only takes effect when `combined` is True)
H
haoyuying 已提交
120 121 122 123 124 125 126 127 128 129 130
      * combined: Whether to save the parameters to a unified file.


## IV. Server Deployment

- PaddleHub Serving can deploy an online service of  human parsing

- ### Step 1: Start PaddleHub Serving

  - Run the startup command:
  
H
haoyuying 已提交
131 132 133
    - ```shell
      $ hub serving start -m ace2p
      ```
H
haoyuying 已提交
134 135 136 137 138 139 140 141 142 143

  - 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


H
haoyuying 已提交
144
    - ```python
H
haoyuying 已提交
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
      import requests
      import json
      import cv2
      import base64

      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


      # 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/ace2p"
      r = requests.post(url=url, headers=headers, data=json.dumps(data))

      # print prediction results
      print(base64_to_cv2(r.json()["results"][0]['data']))
      ```


## 五、更新历史

- 1.0.0

  First release

* 1.1.0

  Adapt to paddlehub2.0