code: def preprocess(self, images, batch_size, use_gpu):
      # 获取人脸关键点
      outputs = self.face_detector.keypoint_detection(
          images=images, batch_size=batch_size, use_gpu=use_gpu
      )
  
      crops = []
      for output, image in zip(outputs, images):
          for landmarks in output["data"]:
              landmarks = np.array(landmarks)
  
              # rotation angle
              left_eye_corner = landmarks[36]
              right_eye_corner = landmarks[45]
              radian = np.arctan(
                  (left_eye_corner[1] - right_eye_corner[1])
                  / (left_eye_corner[0] - right_eye_corner[0])
              )
  
              # image size after rotating
              height, width, _ = image.shape
              cos = math.cos(radian)
              sin = math.sin(radian)
              new_w = int(width * abs(cos) + height * abs(sin))
              new_h = int(width * abs(sin) + height * abs(cos))
  
              # translation
              Tx = new_w // 2 - width // 2
              Ty = new_h // 2 - height // 2
  
              # affine matrix
              M = np.array(
                  [
                      [
                          cos,
                          sin,
                          (1 - cos) * width / 2.0
                          - sin * height / 2.0
                          + Tx,
                      ],
                      [
                          -sin,
                          cos,
                          sin * width / 2.0
                          + (1 - cos) * height / 2.0
                          + Ty,
                      ],
                  ]
              )
  
              image = cv2.warpAffine(
                  image, M, (new_w, new_h), borderValue=(255, 255, 255)
              )
  
              landmarks = np.concatenate(
                  [landmarks, np.ones((landmarks.shape[0], 1))], axis=1
              )
              landmarks = np.dot(M, landmarks.T).T
              landmarks_top = np.min(landmarks[:, 1])
              landmarks_bottom = np.max(landmarks[:, 1])
              landmarks_left = np.min(landmarks[:, 0])
              landmarks_right = np.max(landmarks[:, 0])
  
              # expand bbox
              top = int(
                  landmarks_top
                  - 0.8 * (landmarks_bottom - landmarks_top)
              )
              bottom = int(
                  landmarks_bottom
                  + 0.3 * (landmarks_bottom - landmarks_top)
              )
              left = int(
                  landmarks_left
                  - 0.3 * (landmarks_right - landmarks_left)
              )
              right = int(
                  landmarks_right
                  + 0.3 * (landmarks_right - landmarks_left)
              )
  
              # crop
              if bottom - top > right - left:
                  left -= ((bottom - top) - (right - left)) // 2
                  right = left + (bottom - top)
              else:
                  top -= ((right - left) - (bottom - top)) // 2
                  bottom = top + (right - left)
  
              image_crop = (
                  np.ones(
                      (bottom - top + 1, right - left + 1, 3), np.uint8
                  )
                  * 255
              )
  
              h, w = image.shape[:2]
              left_white = max(0, -left)
              left = max(0, left)
              right = min(right, w - 1)
              right_white = left_white + (right - left)
              top_white = max(0, -top)
              top = max(0, top)
              bottom = min(bottom, h - 1)
              bottom_white = top_white + (bottom - top)
  
              image_crop[
                  top_white : bottom_white + 1,
                  left_white : right_white + 1,
              ] = image[top : bottom + 1, left : right + 1].copy()
              crops.append(image_crop)
  
      # 获取人像分割的输出
      results = self.seg.Segmentation(
          images=crops, batch_size=batch_size
      )
  
      faces = []
      masks = []
  
      for result in results:
          # 提取MASK和输出图像
          face = result["face"]
          mask = result["mask"]
  
          # 图像格式转换
          face = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
  
          # 图像拼接
          face_rgba = np.dstack((face, mask))
  
          # 图像缩放
          face_rgba = cv2.resize(
              face_rgba, (256, 256), interpolation=cv2.INTER_AREA
          )
  
          # 拆分图像
          face = face_rgba[:, :, :3].copy()
          mask = face_rgba[:, :, 3][:, :, np.newaxis].copy() / 255.0
  
          # 数据格式转换
          face = np.transpose(
              face[np.newaxis, :, :, :], (0, 3, 1, 2)
          ).astype(np.float32)
  
          faces.append(face)
          masks.append(mask)
  
      input_datas = np.concatenate(faces, 0)
  
      # 切分数据
      datas_num = input_datas.shape[0]
      split_num = (
          datas_num // batch_size + 1
          if datas_num % batch_size != 0
          else datas_num // batch_size
      )
      input_datas = np.array_split(input_datas, split_num)
  
      return input_datas, masks
  
file_path: PaddleHub/modules/image/Image_gan/style_transfer/Photo2Cartoon/module.py
imports: import os
  import cv2
  import math
  import paddle
  import numpy
  import paddle.nn
  import paddlehub
  from Photo2Cartoon.model import ResnetGenerator
  from paddlehub.module.module import moduleinfo
label_desc: Use image node_id 3 for calling the Photo2Cartoon obj's underlying member method code with example usage: obj.preprocess(images, batch_size, use_gpu) and returns: input_datas,  masks