class_docstr: Prepare image data for the model specified by "prefix". For multiple models requiring image data,
  we need to create a ImageProcessor for each related model so that they will have independent input.
class_docstr_tok: ["Prepare","image","data","for","the","model","specified","by","``","prefix","''",".","For","multiple","models","requiring","image","data",",","we","need","to","create","a","ImageProcessor","for","each","related","model","so","that","they","will","have","independent","input","."]
docstr: Read images, process them, and stack them for semantic segmentation.
  
  Parameters
  ----------
  image_features
      One sample may have multiple image columns in a pd.DataFrame and multiple images
      inside each image column.
  feature_modalities
      What modality each column belongs to.
  is_training
      Whether to process images in the training mode.
  image_mode
      A string which defines the type and depth of a pixel in the image.
      For example, RGB, RGBA, CMYK, and etc.
  
  Returns
  -------
  A dictionary containing one sample's image, the valid number and the ground truth image label.
  For multi-class semantic segmentation, the dictionary also includes information of per-category binary masks derived from the ground truth image. This logic follows the data processing of mask-based semantic segmentation.
docstr_tok: ["Read","images",",","process","them",",","and","stack","them","for","semantic","segmentation",".","Parameters","--","--","--","--","--","image_features","One","sample","may","have","multiple","image","columns","in","a","pd.DataFrame","and","multiple","images","inside","each","image","column",".","feature_modalities","What","modality","each","column","belongs","to",".","is_training","Whether","to","process","images","in","the","training","mode",".","image_mode","A","string","which","defines","the","type","and","depth","of","a","pixel","in","the","image",".","For","example",",","RGB",",","RGBA",",","CMYK",",","and","etc",".","Returns","--","--","--","-","A","dictionary","containing","one","sample","'s","image",",","the","valid","number","and","the","ground","truth","image","label",".","For","multi-class","semantic","segmentation",",","the","dictionary","also","includes","information","of","per-category","binary","masks","derived","from","the","ground","truth","image",".","This","logic","follows","the","data","processing","of","mask-based","semantic","segmentation","."]
code: def process_one_sample(
      self,
      image_features: Dict[str, Union[List[str], List[bytearray]]],
      feature_modalities: Dict[str, List[str]],
      is_training: bool,
      image_mode: Optional[str] = "RGB",
  ) -> Dict:
      """
      Read images, process them, and stack them for semantic segmentation.
  
      Parameters
      ----------
      image_features
          One sample may have multiple image columns in a pd.DataFrame and multiple images
          inside each image column.
      feature_modalities
          What modality each column belongs to.
      is_training
          Whether to process images in the training mode.
      image_mode
          A string which defines the type and depth of a pixel in the image.
          For example, RGB, RGBA, CMYK, and etc.
  
      Returns
      -------
      A dictionary containing one sample's image, the valid number and the ground truth image label.
      For multi-class semantic segmentation, the dictionary also includes information of per-category binary masks derived from the ground truth image. This logic follows the data processing of mask-based semantic segmentation.
      """
      images = []
      gts = []
      if self.num_classes > 1:
          gt_masks_per_category = []
          gt_classes = []
  
      ret = {}
      annotation_column = None
      for column_name, column_modality in feature_modalities.items():
          if column_modality == SEMANTIC_SEGMENTATION_IMG:
              image_column = column_name
          if column_modality == SEMANTIC_SEGMENTATION_GT:
              annotation_column = column_name
  
      per_col_image_features = image_features[image_column]
      if is_training or annotation_column is not None:
          per_col_gt_features = image_features[annotation_column]
  
      for idx, img_feature in enumerate(
          per_col_image_features[: self.max_img_num_per_col]
      ):
          try:
              with PIL.Image.open(img_feature) as img:
                  img = img.convert(image_mode)
          except Exception as e:
              continue
          if annotation_column:
              gt_feature = per_col_gt_features[idx]
  
              with PIL.Image.open(gt_feature) as gt:
                  gt = gt.convert(gt.mode)
              if self.num_classes == 1:
                  gt = gt.convert("L")
              if self.num_classes > 1:
                  gt = np.array(gt).astype(
                      "float32"
                  )  # There may be issues with 'transforms.ToTensor()' without this line because 'transforms.ToTensor()' converts 'unit8' to values between 0 and 1.
                  gt = Image.fromarray(gt)
          if is_training:
              if random.random() < 0.5:
                  img = self.train_transforms(img)
                  gt = self.train_transforms(gt)
              img = self.img_processor(img)
              gt = self.gt_processor(gt)
          else:
              img = self.img_processor(img)
              if annotation_column is not None:
                  gt = self.gt_processor(gt)
  
          images.append(img)
          if is_training or annotation_column is not None:
              gts.append(gt)
  
              if self.num_classes > 1:
                  # Prepare per-category binary masks
                  (
                      per_gt_masks_per_category,
                      per_gt_classes,
                  ) = self.prepare_per_category_binary_masks(gt)
                  gt_masks_per_category.append(
                      per_gt_masks_per_category
                  )
                  gt_classes.append(per_gt_classes)
  
      ret.update(
          {
              self.image_key: images[0]
              if len(images) != 0
              else torch.tensor([]),
              self.label_key: gts[0]
              if len(gts) != 0
              else torch.tensor([]),
          }
      )
      if self.num_classes > 1:
          ret.update(
              {
                  self.mask_label_key: gt_masks_per_category[0]
                  if len(gt_masks_per_category) != 0
                  else [],
                  self.class_label_key: gt_classes[0]
                  if len(gt_classes) != 0
                  else [],
              }
          )
      return ret
  
imports: import logging
  import random
  import warnings
  from io import BytesIO
  from typing import Dict, List, Optional, Union
  import numpy
  import PIL
  import torch
  from omegaconf import DictConfig
  from PIL import Image, ImageFile
  from torch import nn
  from torchvision import transforms
  from .utils import construct_image_processor, image_mean_std
  from ..constants import CLASS_LABEL, COLUMN, IMAGE, IMAGE_BYTEARRAY, IMAGE_VALID_NUM, LABEL, MASK_LABEL, SEMANTIC_SEGMENTATION_GT, SEMANTIC_SEGMENTATION_IMG
  from .collator import ListCollator, PadCollator, StackCollator
label_desc: Use image node_id 9 for calling the SemanticSegImageProcessor obj's underlying member method code with example usage: obj.process_one_sample(image_features, feature_modalities, is_training, image_mode) and returns: ret