code: def segment(
      self,
      image: Union[str, np.ndarray],
      labels: Union[str, List[str]],
      visualization: bool = False,
      output_dir: str = "lseg_output",
  ) -> Dict[str, Union[np.ndarray, Dict[str, np.ndarray]]]:
      if isinstance(image, str):
          image = cv2.imread(image)
      elif isinstance(image, np.ndarray):
          image = image
      else:
          raise Exception("image should be a str / np.ndarray")
  
      if isinstance(labels, str):
          labels = [labels, "other"]
          print(
              '"other" category label is automatically added because the length of labels is equal to 1'
          )
          print("new labels: ", labels)
      elif isinstance(labels, list):
          if len(labels) == 1:
              labels.append("other")
              print(
                  '"other" category label is automatically added because the length of labels is equal to 1'
              )
              print("new labels: ", labels)
          elif len(labels) == 0:
              raise Exception("labels should not be empty.")
      else:
          raise Exception("labels should be a str or list.")
  
      class_num = len(labels)
  
      labels_ = list(set(labels))
      labels_.sort(key=labels.index)
      labels = labels_
  
      input_labels = []
      for label in labels:
          from_lang = self.language_recognition.recognize(query=label)
          if from_lang != "en":
              label = self.translate.translate(
                  query=label, from_lang=from_lang, to_lang="en"
              )
          input_labels.append(label)
  
      labels_dict = {k: v for k, v in zip(input_labels, labels)}
  
      input_labels_ = list(set(input_labels))
      input_labels_.sort(key=input_labels.index)
      input_labels = input_labels_
  
      labels = []
      for input_label in input_labels:
          labels.append(labels_dict[input_label])
  
      if len(labels) < class_num:
          print("remove the same labels...")
          print("new labels: ", labels)
  
      h, w = image.shape[:2]
      image = image[
          : -(h % 32) if h % 32 else None,
          : -(w % 32) if w % 32 else None,
      ]
      images = self.transforms(
          cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
      ).unsqueeze(0)
      texts = self.tokenizer(
          input_labels, padding=True, return_tensors="pd"
      )["input_ids"]
  
      with paddle.no_grad():
          results = self.forward(images, texts)
          results = paddle.argmax(results, 1).cast(paddle.uint8)
          gray_seg = results.numpy()[0]
  
      colormap = self.get_colormap(len(labels))
      color_seg = cv2.applyColorMap(gray_seg, colormap)
      mix_seg = cv2.addWeighted(image, 0.5, color_seg, 0.5, 0.0)
  
      classes_seg = {}
      for i, label in enumerate(labels):
          mask = ((gray_seg == i).astype("uint8") * 255)[..., None]
          classes_seg[label] = np.concatenate([image, mask], 2)
  
      if visualization:
          save_dir = os.path.join(output_dir, str(int(time.time())))
          if not os.path.isdir(save_dir):
              os.makedirs(save_dir)
          for label, dst in classes_seg.items():
              cv2.imwrite(os.path.join(save_dir, "%s.png" % label), dst)
  
      return {
          "gray": gray_seg,
          "color": color_seg,
          "mix": mix_seg,
          "classes": classes_seg,
      }
  
imports: import argparse
  import base64
  import os
  import time
  from typing import Dict
  from typing import List
  from typing import Union
  import cv2
  import numpy
  import paddle
  import paddle.vision.transforms
  from paddlenlp.transformers.clip.tokenizer import CLIPTokenizer
  import paddlehub
  from .None import models
  from paddlehub.module.module import moduleinfo
  from paddlehub.module.module import runnable
  from paddlehub.module.module import serving
label_desc: Use image node_id 3 for calling the LSeg obj's underlying member method code with example usage: obj.segment(image, labels, visualization, output_dir) and returns: dict