code: 
  
  
  
  import unittest
  
  import numpy as np
  from datasets import load_dataset
  
  from transformers.testing_utils import require_torch, require_vision
  from transformers.utils import is_torch_available, is_vision_available
  
  from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs
  
  
  if is_torch_available():
      import torch
  
  if is_vision_available():
      from PIL import Image
  
      from transformers import SegformerImageProcessor
  
  
  
  class 		_snake_case      (			unittest.TestCase				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   def __init__(						self	,    a	,    a=7	,    a=3	,    a=3_0	,    a=4_0_0	,    a=True	,    a=None	,    a=True	,    a=[0.5, 0.5, 0.5]	,    a=[0.5, 0.5, 0.5]	,    a=False	,    )	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    size if size is not None else {'''height''': 3_0, '''width''': 3_0}
     _A           =    parent
     _A           =    batch_size
     _A           =    num_channels
     _A           =    min_resolution
     _A           =    max_resolution
     _A           =    do_resize
     _A           =    size
     _A           =    do_normalize
     _A           =    image_mean
     _A           =    image_std
     _A           =    do_reduce_labels
  
  
  
   def lowercase_		(						self					)	->							List[Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     return {
         "do_resize": self.do_resize,
         "size": self.size,
         "do_normalize": self.do_normalize,
         "image_mean": self.image_mean,
         "image_std": self.image_std,
         "do_reduce_labels": self.do_reduce_labels,
     }
  
  
  
  
  
  
  
  def     UpperCAmelCase__ (							)   -> Tuple:
    _A           =    load_dataset('''hf-internal-testing/fixtures_ade20k'''						,				split='''test'''							)
  
    _A           =    Image.open(dataset[0]['''file''']							)
    _A           =    Image.open(dataset[1]['''file''']							)
  
    return image, map
  
  
  
  
  def     UpperCAmelCase__ (							)   -> List[Any]:
    _A           =    load_dataset('''hf-internal-testing/fixtures_ade20k'''						,				split='''test'''							)
  
    _A           =    Image.open(dataset[0]['''file''']							)
    _A           =    Image.open(dataset[1]['''file''']							)
    _A           =    Image.open(dataset[2]['''file''']							)
    _A           =    Image.open(dataset[3]['''file''']							)
  
    return [imagea, imagea], [mapa, mapa]
  
  
  
  @require_torch
  @require_vision
  class 		_snake_case      (			lowerCamelCase					,unittest.TestCase				):
  
  
  
  
  
   """simple docstring"""
  
  
  
   lowerCamelCase_          =			SegformerImageProcessor if is_vision_available() else None
   def lowercase_		(						self					)	->							Tuple:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    SegformerImageProcessingTester(self					)
   @property
   def lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     return self.image_processor_tester.prepare_image_processor_dict()
   def lowercase_		(						self					)	->							Union[str, Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class(**self.image_processor_dict					)
     self.assertTrue(hasattr(a	,    '''do_resize'''					)					)
     self.assertTrue(hasattr(a	,    '''size'''					)					)
     self.assertTrue(hasattr(a	,    '''do_normalize'''					)					)
     self.assertTrue(hasattr(a	,    '''image_mean'''					)					)
     self.assertTrue(hasattr(a	,    '''image_std'''					)					)
     self.assertTrue(hasattr(a	,    '''do_reduce_labels'''					)					)
   def lowercase_		(						self					)	->							Dict:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class.from_dict(self.image_processor_dict					)
     self.assertEqual(image_processor.size	,    {'''height''': 3_0, '''width''': 3_0}					)
     self.assertEqual(image_processor.do_reduce_labels	,    a					)
  
     _A           =    self.image_processing_class.from_dict(self.image_processor_dict	,    size=4_2	,    reduce_labels=a					)
     self.assertEqual(image_processor.size	,    {'''height''': 4_2, '''width''': 4_2}					)
     self.assertEqual(image_processor.do_reduce_labels	,    a					)
   def lowercase_		(						self					)	->							Any:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     pass
   def lowercase_		(						self					)	->							Union[str, Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class(**self.image_processor_dict					)
     # create random PIL images
     _A           =    prepare_image_inputs(self.image_processor_tester	,    equal_resolution=a					)
     for image in image_inputs:
       self.assertIsInstance(a	,    Image.Image					)
  
     # Test not batched input
     _A           =    image_processing(image_inputs[0]	,    return_tensors='''pt'''					).pixel_values
     self.assertEqual(
         encoded_images.shape	,    (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
  
     # Test batched
     _A           =    image_processing(a	,    return_tensors='''pt'''					).pixel_values
     self.assertEqual(
         encoded_images.shape	,    (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
   def lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class(**self.image_processor_dict					)
     # create random numpy tensors
     _A           =    prepare_image_inputs(self.image_processor_tester	,    equal_resolution=a	,    numpify=a					)
     for image in image_inputs:
       self.assertIsInstance(a	,    np.ndarray					)
  
     # Test not batched input
     _A           =    image_processing(image_inputs[0]	,    return_tensors='''pt'''					).pixel_values
     self.assertEqual(
         encoded_images.shape	,    (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
  
     # Test batched
     _A           =    image_processing(a	,    return_tensors='''pt'''					).pixel_values
     self.assertEqual(
         encoded_images.shape	,    (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
   def lowercase_		(						self					)	->							Union[str, Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class(**self.image_processor_dict					)
     # create random PyTorch tensors
     _A           =    prepare_image_inputs(self.image_processor_tester	,    equal_resolution=a	,    torchify=a					)
     for image in image_inputs:
       self.assertIsInstance(a	,    torch.Tensor					)
  
     # Test not batched input
     _A           =    image_processing(image_inputs[0]	,    return_tensors='''pt'''					).pixel_values
     self.assertEqual(
         encoded_images.shape	,    (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
  
     # Test batched
     _A           =    image_processing(a	,    return_tensors='''pt'''					).pixel_values
     self.assertEqual(
         encoded_images.shape	,    (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
   def lowercase_		(						self					)	->							List[str]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class(**self.image_processor_dict					)
     # create random PyTorch tensors
     _A           =    prepare_image_inputs(self.image_processor_tester	,    equal_resolution=a	,    torchify=a					)
     _A           =    []
     for image in image_inputs:
       self.assertIsInstance(a	,    torch.Tensor					)
       maps.append(torch.zeros(image.shape[-2:]					).long()					)
  
     # Test not batched input
     _A           =    image_processing(image_inputs[0]	,    maps[0]	,    return_tensors='''pt'''					)
     self.assertEqual(
         encoding['''pixel_values'''].shape	,    (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(
         encoding['''labels'''].shape	,    (
             1,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(encoding['''labels'''].dtype	,    torch.long					)
     self.assertTrue(encoding['''labels'''].min().item() >= 0					)
     self.assertTrue(encoding['''labels'''].max().item() <= 2_5_5					)
  
     # Test batched
     _A           =    image_processing(a	,    a	,    return_tensors='''pt'''					)
     self.assertEqual(
         encoding['''pixel_values'''].shape	,    (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(
         encoding['''labels'''].shape	,    (
             self.image_processor_tester.batch_size,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(encoding['''labels'''].dtype	,    torch.long					)
     self.assertTrue(encoding['''labels'''].min().item() >= 0					)
     self.assertTrue(encoding['''labels'''].max().item() <= 2_5_5					)
  
     # Test not batched input (PIL images)
     _A    ,   _A           =    prepare_semantic_single_inputs()
  
     _A           =    image_processing(a	,    a	,    return_tensors='''pt'''					)
     self.assertEqual(
         encoding['''pixel_values'''].shape	,    (
             1,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(
         encoding['''labels'''].shape	,    (
             1,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(encoding['''labels'''].dtype	,    torch.long					)
     self.assertTrue(encoding['''labels'''].min().item() >= 0					)
     self.assertTrue(encoding['''labels'''].max().item() <= 2_5_5					)
  
     # Test batched input (PIL images)
     _A    ,   _A           =    prepare_semantic_batch_inputs()
  
     _A           =    image_processing(a	,    a	,    return_tensors='''pt'''					)
     self.assertEqual(
         encoding['''pixel_values'''].shape	,    (
             2,
             self.image_processor_tester.num_channels,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(
         encoding['''labels'''].shape	,    (
             2,
             self.image_processor_tester.size['''height'''],
             self.image_processor_tester.size['''width'''],
         )	,    )
     self.assertEqual(encoding['''labels'''].dtype	,    torch.long					)
     self.assertTrue(encoding['''labels'''].min().item() >= 0					)
     self.assertTrue(encoding['''labels'''].max().item() <= 2_5_5					)
  
  
  
   def lowercase_		(						self					)	->							Union[str, Any]:
  
  
  
  
     """simple docstring"""
  
  
  
  
  
  
  
     _A           =    self.image_processing_class(**self.image_processor_dict					)
  
     # ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
     _A    ,   _A           =    prepare_semantic_single_inputs()
     _A           =    image_processing(a	,    a	,    return_tensors='''pt'''					)
     self.assertTrue(encoding['''labels'''].min().item() >= 0					)
     self.assertTrue(encoding['''labels'''].max().item() <= 1_5_0					)
  
     _A           =    True
     _A           =    image_processing(a	,    a	,    return_tensors='''pt'''					)
     self.assertTrue(encoding['''labels'''].min().item() >= 0					)
     self.assertTrue(encoding['''labels'''].max().item() <= 2_5_5					)
style_context: 
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case = 1_000							)   -> str:
    if (not isinstance(__snake_case						,				__snake_case							)) or (digit_position <= 0):
      raise ValueError('''Digit position must be a positive integer'''							)
    elif (not isinstance(__snake_case						,				__snake_case							)) or (precision < 0):
      raise ValueError('''Precision must be a nonnegative integer'''							)
  
    # compute an approximation of (16 ** (n - 1)) * pi whose fractional part is mostly
    # accurate
    _A           =    (
        4 * _subsum(__snake_case						,				1						,				__snake_case							)
        - 2 * _subsum(__snake_case						,				4						,				__snake_case							)
        - _subsum(__snake_case						,				5						,				__snake_case							)
        - _subsum(__snake_case						,				6						,				__snake_case							)
    )
  
    # return the first hex digit of the fractional part of the result
    return hex(int((sum_result % 1) * 16							)							)[2:]
  
  
  
  
  def     UpperCAmelCase__ (							__snake_case						,				__snake_case						,				__snake_case							)   -> float:
    _A           =    0.0
    for sum_index in range(digit_pos_to_extract + precision							):
      _A           =    8 * sum_index + denominator_addend
      if sum_index < digit_pos_to_extract:
        # if the exponential term is an integer and we mod it by the denominator
        # before dividing, only the integer part of the sum will change;
        # the fractional part will not
        _A           =    pow(
            16						,				digit_pos_to_extract - 1 - sum_index						,				__snake_case							)
      else:
        _A           =    pow(16						,				digit_pos_to_extract - 1 - sum_index							)
      total += exponential_term / denominator
    return total
  
  
  if __name__ == "__main__":
      import doctest
  
      doctest.testmod()