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        __lowerCAmelCase (					unittest.TestCase):
  
  
  
  
  
  
  
        def __init__(					self	,   lowerCAmelCase__	,   lowerCAmelCase__=7	,   lowerCAmelCase__=3	,   lowerCAmelCase__=3_0	,   lowerCAmelCase__=4_0_0	,   lowerCAmelCase__=True	,   lowerCAmelCase__=None	,   lowerCAmelCase__=True	,   lowerCAmelCase__=[0.5, 0.5, 0.5]	,   lowerCAmelCase__=[0.5, 0.5, 0.5]	,   lowerCAmelCase__=False	,   )     ->		Optional[Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Optional[Any]            =size if size is not None else {"height": 3_0, "width": 3_0}
          a__			:      str            =parent
          a__			:      Tuple            =batch_size
          a__			:      int            =num_channels
          a__			:      List[str]            =min_resolution
          a__			:      int            =max_resolution
          a__			:      str            =do_resize
          a__			:      Optional[Any]            =size
          a__			:      Dict            =do_normalize
          a__			:      Union[str, Any]            =image_mean
          a__			:      List[Any]            =image_std
          a__			:      int            =do_reduce_labels
  
  
  
  
  
  
  
        def      _lowercase						(					self							)     ->		int:
  
  
  
          '''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   _A (	):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__			:      Optional[int]            =load_dataset("hf-internal-testing/fixtures_ade20k" , split="test"		)
  
    a__			:      List[str]            =Image.open(dataset[0]["file"]		)
    a__			:      List[Any]            =Image.open(dataset[1]["file"]		)
  
    return image, map
  def   _A (	):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__			:      List[Any]            =load_dataset("hf-internal-testing/fixtures_ade20k" , split="test"		)
  
    a__			:      str            =Image.open(dataset[0]["file"]		)
    a__			:      List[str]            =Image.open(dataset[1]["file"]		)
    a__			:      int            =Image.open(dataset[2]["file"]		)
    a__			:      str            =Image.open(dataset[3]["file"]		)
  
    return [imagea, imagea], [mapa, mapa]
  
  
  
  
  
  
  
  @require_torch
  @require_vision
  class        __lowerCAmelCase (					_a		,       unittest.TestCase):
        _lowercase       :      int        =    SegformerImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  
        def      _lowercase						(					self							)     ->		str:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      List[Any]            =SegformerImageProcessingTester(self							)
  
  
  
  
  
  
  
        @property
        def      _lowercase						(					self							)     ->		List[str]:
  
  
  
          '''simple docstring'''
  
  
  
  
          return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
        def      _lowercase						(					self							)     ->		List[Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      str            =self.image_processing_class(**self.image_processor_dict							)
          self.assertTrue(hasattr(lowerCamelCase__	,   "do_resize"							)							)
          self.assertTrue(hasattr(lowerCamelCase__	,   "size"							)							)
          self.assertTrue(hasattr(lowerCamelCase__	,   "do_normalize"							)							)
          self.assertTrue(hasattr(lowerCamelCase__	,   "image_mean"							)							)
          self.assertTrue(hasattr(lowerCamelCase__	,   "image_std"							)							)
          self.assertTrue(hasattr(lowerCamelCase__	,   "do_reduce_labels"							)							)
  
  
  
  
  
  
  
        def      _lowercase						(					self							)     ->		Union[str, Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      int            =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	,   lowerCamelCase__							)
  
          a__			:      List[Any]            =self.image_processing_class.from_dict(self.image_processor_dict	,   size=4_2	,   reduce_labels=lowerCamelCase__							)
          self.assertEqual(image_processor.size	,   {"height": 4_2, "width": 4_2}							)
          self.assertEqual(image_processor.do_reduce_labels	,   lowerCamelCase__							)
  
  
  
  
  
  
  
        def      _lowercase						(					self							)     ->		Tuple:
  
  
  
          '''simple docstring'''
  
  
  
  
          pass
  
  
  
  
  
  
  
        def      _lowercase						(					self							)     ->		int:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Any            =self.image_processing_class(**self.image_processor_dict							)
          # create random PIL images
          a__			:      Dict            =prepare_image_inputs(self.image_processor_tester	,   equal_resolution=lowerCamelCase__							)
          for image in image_inputs:
            self.assertIsInstance(lowerCamelCase__	,   Image.Image							)
  
          # Test not batched input
          a__			:      Optional[Any]            =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__			:      Any            =image_processing(lowerCamelCase__	,   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__			:      Any            =self.image_processing_class(**self.image_processor_dict							)
          # create random numpy tensors
          a__			:      str            =prepare_image_inputs(self.image_processor_tester	,   equal_resolution=lowerCamelCase__	,   numpify=lowerCamelCase__							)
          for image in image_inputs:
            self.assertIsInstance(lowerCamelCase__	,   np.ndarray							)
  
          # Test not batched input
          a__			:      Tuple            =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__			:      str            =image_processing(lowerCamelCase__	,   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__			:      Tuple            =self.image_processing_class(**self.image_processor_dict							)
          # create random PyTorch tensors
          a__			:      Optional[Any]            =prepare_image_inputs(self.image_processor_tester	,   equal_resolution=lowerCamelCase__	,   torchify=lowerCamelCase__							)
          for image in image_inputs:
            self.assertIsInstance(lowerCamelCase__	,   torch.Tensor							)
  
          # Test not batched input
          a__			:      int            =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__			:      Any            =image_processing(lowerCamelCase__	,   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__			:      Dict            =self.image_processing_class(**self.image_processor_dict							)
          # create random PyTorch tensors
          a__			:      Any            =prepare_image_inputs(self.image_processor_tester	,   equal_resolution=lowerCamelCase__	,   torchify=lowerCamelCase__							)
          a__			:      List[Any]            =[]
          for image in image_inputs:
            self.assertIsInstance(lowerCamelCase__	,   torch.Tensor							)
            maps.append(torch.zeros(image.shape[-2:]							).long()							)
  
          # Test not batched input
          a__			:      Union[str, Any]            =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__			:      int            =image_processing(lowerCamelCase__	,   lowerCamelCase__	,   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__			:      List[Any]            =prepare_semantic_single_inputs()
  
          a__			:      Union[str, Any]            =image_processing(lowerCamelCase__	,   lowerCamelCase__	,   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__			:      Any            =prepare_semantic_batch_inputs()
  
          a__			:      List[Any]            =image_processing(lowerCamelCase__	,   lowerCamelCase__	,   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							)     ->		List[Any]:
  
  
  
          '''simple docstring'''
  
  
  
  
          a__			:      Dict            =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__			:      str            =prepare_semantic_single_inputs()
          a__			:      Union[str, Any]            =image_processing(lowerCamelCase__	,   lowerCamelCase__	,   return_tensors="pt"							)
          self.assertTrue(encoding["labels"].min().item() >= 0							)
          self.assertTrue(encoding["labels"].max().item() <= 1_5_0							)
  
          a__			:      Tuple            =True
          a__			:      str            =image_processing(lowerCamelCase__	,   lowerCamelCase__	,   return_tensors="pt"							)
          self.assertTrue(encoding["labels"].min().item() >= 0							)
          self.assertTrue(encoding["labels"].max().item() <= 2_5_5							)
  
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  from __future__ import annotations
  def   _A (	SCREAMING_SNAKE_CASE  :     str , SCREAMING_SNAKE_CASE  :     dict[str, str]		):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__      ,							a__      ,							a__			:      Optional[int]            ="", "", ""
    a__			:      str            =[]
  
    for character in message_part:
      tmp.append(character_to_number[character]		)
  
    for each in tmp:
      one += each[0]
      two += each[1]
      three += each[2]
  
    return one + two + three
  def   _A (	SCREAMING_SNAKE_CASE  :     str , SCREAMING_SNAKE_CASE  :     dict[str, str]		):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__      ,							a__			:      Any            ="", ""
    a__			:      Optional[int]            =[]
  
    for character in message_part:
      this_part += character_to_number[character]
  
    for digit in this_part:
      tmp += digit
      if len(SCREAMING_SNAKE_CASE		) == len(SCREAMING_SNAKE_CASE		):
        result.append(SCREAMING_SNAKE_CASE		)
        a__			:      str            =""
  
    return result[0], result[1], result[2]
  def   _A (	SCREAMING_SNAKE_CASE  :     str , SCREAMING_SNAKE_CASE  :     str		):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__			:      Optional[Any]            =alphabet.replace(" " , ""		).upper()
    a__			:      List[str]            =message.replace(" " , ""		).upper()
  
    # Check length and characters
    if len(SCREAMING_SNAKE_CASE		) != 27:
      raise KeyError("Length of alphabet has to be 27."		)
    for each in message:
      if each not in alphabet:
        raise ValueError("Each message character has to be included in alphabet!"		)
  
      # Generate dictionares
    a__			:      Any            =(
        "111",
        "112",
        "113",
        "121",
        "122",
        "123",
        "131",
        "132",
        "133",
        "211",
        "212",
        "213",
        "221",
        "222",
        "223",
        "231",
        "232",
        "233",
        "311",
        "312",
        "313",
        "321",
        "322",
        "323",
        "331",
        "332",
        "333",
    )
    a__			:      Tuple            ={}
    a__			:      List[str]            ={}
    for letter, number in zip(SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE		):
      a__			:      Dict            =number
      a__			:      Union[str, Any]            =letter
  
    return message, alphabet, character_to_number, number_to_character
  def   _A (	SCREAMING_SNAKE_CASE  :     str , SCREAMING_SNAKE_CASE  :     str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ." , SCREAMING_SNAKE_CASE  :     int = 5		):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__      ,							a__      ,							a__      ,							a__			:      Union[str, Any]            =__prepare(
        SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE		)
    a__      ,							a__			:      Union[str, Any]            ="", ""
  
    for i in range(0 , len(SCREAMING_SNAKE_CASE		) + 1 , SCREAMING_SNAKE_CASE		):
      encrypted_numeric += __encrypt_part(
          message[i : i + period] , SCREAMING_SNAKE_CASE		)
  
    for i in range(0 , len(SCREAMING_SNAKE_CASE		) , 3		):
      encrypted += number_to_character[encrypted_numeric[i : i + 3]]
  
    return encrypted
  def   _A (	SCREAMING_SNAKE_CASE  :     str , SCREAMING_SNAKE_CASE  :     str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ." , SCREAMING_SNAKE_CASE  :     int = 5		):
  
  
  
  
  
    """simple docstring"""
  
  
  
    a__      ,							a__      ,							a__      ,							a__			:      Dict            =__prepare(
        SCREAMING_SNAKE_CASE , SCREAMING_SNAKE_CASE		)
    a__			:      Optional[Any]            =[]
    a__			:      Any            =""
  
    for i in range(0 , len(SCREAMING_SNAKE_CASE		) + 1 , SCREAMING_SNAKE_CASE		):
      a__      ,							a__      ,							a__			:      Union[str, Any]            =__decrypt_part(message[i : i + period] , SCREAMING_SNAKE_CASE		)
  
      for j in range(0 , len(SCREAMING_SNAKE_CASE		)		):
        decrypted_numeric.append(a[j] + b[j] + c[j]		)
  
    for each in decrypted_numeric:
      decrypted += number_to_character[each]
  
    return decrypted
  
  
  if __name__ == "__main__":
       UpperCAmelCase			:			List[str]	  = """DEFEND THE EAST WALL OF THE CASTLE."""
       UpperCAmelCase			:			Optional[Any]	  = encrypt_message(msg, """EPSDUCVWYM.ZLKXNBTFGORIJHAQ""")
       UpperCAmelCase			:			Optional[int]	  = decrypt_message(encrypted, """EPSDUCVWYM.ZLKXNBTFGORIJHAQ""")
       print(F"""Encrypted: {encrypted}\nDecrypted: {decrypted}""")
  
  
  
  
  
  
  