class_docstr: Constructs a MobileViT feature extractor.
  
  This feature extractor inherits from [`FeatureExtractionMixin`] which contains most of the main methods. Users
  should refer to this superclass for more information regarding those methods.
  
  Args:
      do_resize (`bool`, *optional*, defaults to `True`):
          Whether to resize the input to a certain `size`.
      size (`int` or `Tuple(int)`, *optional*, defaults to 288):
          Resize the input to the given size. If a tuple is provided, it should be (width, height). If only an
          integer is provided, then the input will be resized to match the shorter side. Only has an effect if
          `do_resize` is set to `True`.
      resample (`int`, *optional*, defaults to `PIL.Image.Resampling.BILINEAR`):
          An optional resampling filter. This can be one of `PIL.Image.Resampling.NEAREST`,
          `PIL.Image.Resampling.BOX`, `PIL.Image.Resampling.BILINEAR`, `PIL.Image.Resampling.HAMMING`,
          `PIL.Image.Resampling.BICUBIC` or `PIL.Image.Resampling.LANCZOS`. Only has an effect if `do_resize` is set
          to `True`.
      do_center_crop (`bool`, *optional*, defaults to `True`):
          Whether to crop the input at the center. If the input size is smaller than `crop_size` along any edge, the
          image is padded with 0's and then center cropped.
      crop_size (`int`, *optional*, defaults to 256):
          Desired output size when applying center-cropping. Only has an effect if `do_center_crop` is set to `True`.
      do_flip_channel_order (`bool`, *optional*, defaults to `True`):
          Whether to flip the color channels from RGB to BGR.
class_docstr_tok: ["Constructs","a","MobileViT","feature","extractor",".","This","feature","extractor","inherits","from","[","`","FeatureExtractionMixin","`","]","which","contains","most","of","the","main","methods",".","Users","should","refer","to","this","superclass","for","more","information","regarding","those","methods",".","Args",":","do_resize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","resize","the","input","to","a","certain","`","size","`",".","size","(","`","int","`","or","`","Tuple","(","int",")","`",",","*","optional","*",",","defaults","to","288",")",":","Resize","the","input","to","the","given","size",".","If","a","tuple","is","provided",",","it","should","be","(","width",",","height",")",".","If","only","an","integer","is","provided",",","then","the","input","will","be","resized","to","match","the","shorter","side",".","Only","has","an","effect","if","`","do_resize","`","is","set","to","`","True","`",".","resample","(","`","int","`",",","*","optional","*",",","defaults","to","`","PIL.Image.Resampling.BILINEAR","`",")",":","An","optional","resampling","filter",".","This","can","be","one","of","`","PIL.Image.Resampling.NEAREST","`",",","`","PIL.Image.Resampling.BOX","`",",","`","PIL.Image.Resampling.BILINEAR","`",",","`","PIL.Image.Resampling.HAMMING","`",",","`","PIL.Image.Resampling.BICUBIC","`","or","`","PIL.Image.Resampling.LANCZOS","`",".","Only","has","an","effect","if","`","do_resize","`","is","set","to","`","True","`",".","do_center_crop","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","crop","the","input","at","the","center",".","If","the","input","size","is","smaller","than","`","crop_size","`","along","any","edge",",","the","image","is","padded","with","0","'s","and","then","center","cropped",".","crop_size","(","`","int","`",",","*","optional","*",",","defaults","to","256",")",":","Desired","output","size","when","applying","center-cropping",".","Only","has","an","effect","if","`","do_center_crop","`","is","set","to","`","True","`",".","do_flip_channel_order","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","flip","the","color","channels","from","RGB","to","BGR","."]
docstr: Converts the output of [`MobileViTForSemanticSegmentation`] into semantic segmentation maps. Only supports
  PyTorch.
  
  Args:
      outputs ([`MobileViTForSemanticSegmentation`]):
          Raw outputs of the model.
      target_sizes (`List[Tuple]`, *optional*):
          A list of length `batch_size`, where each item is a `Tuple[int, int]` corresponding to the requested
          final size (height, width) of each prediction. If left to None, predictions will not be resized.
  Returns:
      `List[torch.Tensor]`:
          A list of length `batch_size`, where each item is a semantic segmentation map of shape (height, width)
          corresponding to the target_sizes entry (if `target_sizes` is specified). Each entry of each
          `torch.Tensor` correspond to a semantic class id.
docstr_tok: ["Converts","the","output","of","[","`","MobileViTForSemanticSegmentation","`","]","into","semantic","segmentation","maps",".","Only","supports","PyTorch",".","Args",":","outputs","(","[","`","MobileViTForSemanticSegmentation","`","]",")",":","Raw","outputs","of","the","model",".","target_sizes","(","`","List","[","Tuple","]","`",",","*","optional","*",")",":","A","list","of","length","`","batch_size","`",",","where","each","item","is","a","`","Tuple","[","int",",","int","]","`","corresponding","to","the","requested","final","size","(","height",",","width",")","of","each","prediction",".","If","left","to","None",",","predictions","will","not","be","resized",".","Returns",":","`","List","[","torch.Tensor","]","`",":","A","list","of","length","`","batch_size","`",",","where","each","item","is","a","semantic","segmentation","map","of","shape","(","height",",","width",")","corresponding","to","the","target_sizes","entry","(","if","`","target_sizes","`","is","specified",")",".","Each","entry","of","each","`","torch.Tensor","`","correspond","to","a","semantic","class","id","."]
code: def post_process_semantic_segmentation(
      self, outputs, target_sizes: List[Tuple] = None
  ):
      """
      Converts the output of [`MobileViTForSemanticSegmentation`] into semantic segmentation maps. Only supports
      PyTorch.
  
      Args:
          outputs ([`MobileViTForSemanticSegmentation`]):
              Raw outputs of the model.
          target_sizes (`List[Tuple]`, *optional*):
              A list of length `batch_size`, where each item is a `Tuple[int, int]` corresponding to the requested
              final size (height, width) of each prediction. If left to None, predictions will not be resized.
      Returns:
          `List[torch.Tensor]`:
              A list of length `batch_size`, where each item is a semantic segmentation map of shape (height, width)
              corresponding to the target_sizes entry (if `target_sizes` is specified). Each entry of each
              `torch.Tensor` correspond to a semantic class id.
      """
      logits = outputs.logits
  
      # Resize logits and compute semantic segmentation maps
      if target_sizes is not None:
          if len(logits) != len(target_sizes):
              raise ValueError(
                  "Make sure that you pass in as many target sizes as the batch dimension of the logits"
              )
  
          if is_torch_tensor(target_sizes):
              target_sizes = target_sizes.numpy()
  
          semantic_segmentation = []
  
          for idx in range(len(logits)):
              resized_logits = torch.nn.functional.interpolate(
                  logits[idx].unsqueeze(dim=0),
                  size=target_sizes[idx],
                  mode="bilinear",
                  align_corners=False,
              )
              semantic_map = resized_logits[0].argmax(dim=0)
              semantic_segmentation.append(semantic_map)
      else:
          semantic_segmentation = logits.argmax(dim=1)
          semantic_segmentation = [
              semantic_segmentation[i]
              for i in range(semantic_segmentation.shape[0])
          ]
  
      return semantic_segmentation
  
file_path: H2O/h2o_flexgen/benchmark/third_party/transformers/src/transformers/models/mobilevit/feature_extraction_mobilevit.py
imports: from typing import List, Optional, Tuple, Union
  import numpy
  from PIL import Image
  from transformers.image_utils import PILImageResampling
  from ...feature_extraction_utils import BatchFeature, FeatureExtractionMixin
  from ...image_utils import ImageFeatureExtractionMixin, ImageInput, is_torch_tensor
  from ...utils import TensorType, is_torch_available, logging
label_desc: Use image node_id 3 for calling the MobileViTFeatureExtractor obj's underlying member method code with example usage: obj.post_process_semantic_segmentation(outputs, target_sizes) and returns: semantic_segmentation