
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     a_       (			unittest.TestCase							):



       """simple docstring"""






       def __init__(		self				,       _lowerCamelCase				,       _lowerCamelCase=7				,       _lowerCamelCase=3				,       _lowerCamelCase=30				,       _lowerCamelCase=400				,       _lowerCamelCase=True				,       _lowerCamelCase=None				,       _lowerCamelCase=True				,       _lowerCamelCase=[0.5, 0.5, 0.5]				,       _lowerCamelCase=[0.5, 0.5, 0.5]				,       _lowerCamelCase=False				,       )					->int:
           SCREAMING_SNAKE_CASE				:				List[str]				      = size if size is not None else {"height": 30, "width": 30}
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = parent
           SCREAMING_SNAKE_CASE				:				Dict				      = batch_size
           SCREAMING_SNAKE_CASE				:				Any				      = num_channels
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = min_resolution
           SCREAMING_SNAKE_CASE				:				int				      = max_resolution
           SCREAMING_SNAKE_CASE				:				int				      = do_resize
           SCREAMING_SNAKE_CASE				:				List[Any]				      = size
           SCREAMING_SNAKE_CASE				:				int				      = do_normalize
           SCREAMING_SNAKE_CASE				:				Any				      = image_mean
           SCREAMING_SNAKE_CASE				:				str				      = image_std
           SCREAMING_SNAKE_CASE				:				List[Any]				      = do_reduce_labels






       def 	__lowerCAmelCase     (		self   )					->Dict:
           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_(    ):



    """simple docstring"""



    SCREAMING_SNAKE_CASE				:				List[str]				      = load_dataset('''hf-internal-testing/fixtures_ade20k''' ,						split='''test'''   )

    SCREAMING_SNAKE_CASE				:				Any				      = Image.open(dataset[0]['''file''']   )
    SCREAMING_SNAKE_CASE				:				Optional[int]				      = Image.open(dataset[1]['''file''']   )

    return image, map







def 				UpperCAmelCase_(    ):



    """simple docstring"""



    SCREAMING_SNAKE_CASE				:				Optional[int]				      = load_dataset('''hf-internal-testing/fixtures_ade20k''' ,						split='''test'''   )

    SCREAMING_SNAKE_CASE				:				Optional[int]				      = Image.open(dataset[0]['''file''']   )
    SCREAMING_SNAKE_CASE				:				List[str]				      = Image.open(dataset[1]['''file''']   )
    SCREAMING_SNAKE_CASE				:				Dict				      = Image.open(dataset[2]['''file''']   )
    SCREAMING_SNAKE_CASE				:				List[str]				      = Image.open(dataset[3]['''file''']   )

    return [imagea, imagea], [mapa, mapa]






@require_torch
@require_vision
class     a_       (			_snake_case				,    unittest.TestCase							):



       """simple docstring"""
       __SCREAMING_SNAKE_CASE       :					Dict						=  SegformerImageProcessor if is_vision_available() else None






       def 	__lowerCAmelCase     (		self   )					->Optional[int]:
           SCREAMING_SNAKE_CASE				:				List[str]				      = SegformerImageProcessingTester(self   )






       @property
       def 	__lowerCAmelCase     (		self   )					->int:
           return self.image_processor_tester.prepare_image_processor_dict()






       def 	__lowerCAmelCase     (		self   )					->str:
           SCREAMING_SNAKE_CASE				:				List[Any]				      = self.image_processing_class(**self.image_processor_dict   )
           self.assertTrue(hasattr(snake_case_				,       '''do_resize'''   )   )
           self.assertTrue(hasattr(snake_case_				,       '''size'''   )   )
           self.assertTrue(hasattr(snake_case_				,       '''do_normalize'''   )   )
           self.assertTrue(hasattr(snake_case_				,       '''image_mean'''   )   )
           self.assertTrue(hasattr(snake_case_				,       '''image_std'''   )   )
           self.assertTrue(hasattr(snake_case_				,       '''do_reduce_labels'''   )   )






       def 	__lowerCAmelCase     (		self   )					->Optional[int]:
           SCREAMING_SNAKE_CASE				:				List[str]				      = self.image_processing_class.from_dict(self.image_processor_dict   )
           self.assertEqual(image_processor.size				,       {'''height''': 30, '''width''': 30}   )
           self.assertEqual(image_processor.do_reduce_labels				,       snake_case_   )

           SCREAMING_SNAKE_CASE				:				int				      = self.image_processing_class.from_dict(self.image_processor_dict				,       size=42				,       reduce_labels=snake_case_   )
           self.assertEqual(image_processor.size				,       {'''height''': 42, '''width''': 42}   )
           self.assertEqual(image_processor.do_reduce_labels				,       snake_case_   )






       def 	__lowerCAmelCase     (		self   )					->Union[str, Any]:
           pass






       def 	__lowerCAmelCase     (		self   )					->Tuple:
           # Initialize image_processing
           SCREAMING_SNAKE_CASE				:				List[Any]				      = self.image_processing_class(**self.image_processor_dict   )
           # create random PIL images
           SCREAMING_SNAKE_CASE				:				List[str]				      = prepare_image_inputs(self.image_processor_tester				,       equal_resolution=snake_case_   )
           for image in image_inputs:
               self.assertIsInstance(snake_case_				,       Image.Image   )

           # Test not batched input
           SCREAMING_SNAKE_CASE				:				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
           SCREAMING_SNAKE_CASE				:				List[Any]				      = image_processing(snake_case_				,       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 	__lowerCAmelCase     (		self   )					->Dict:
           # Initialize image_processing
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = self.image_processing_class(**self.image_processor_dict   )
           # create random numpy tensors
           SCREAMING_SNAKE_CASE				:				Any				      = prepare_image_inputs(self.image_processor_tester				,       equal_resolution=snake_case_				,       numpify=snake_case_   )
           for image in image_inputs:
               self.assertIsInstance(snake_case_				,       np.ndarray   )

           # Test not batched input
           SCREAMING_SNAKE_CASE				:				Optional[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
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = image_processing(snake_case_				,       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 	__lowerCAmelCase     (		self   )					->int:
           # Initialize image_processing
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = self.image_processing_class(**self.image_processor_dict   )
           # create random PyTorch tensors
           SCREAMING_SNAKE_CASE				:				Optional[Any]				      = prepare_image_inputs(self.image_processor_tester				,       equal_resolution=snake_case_				,       torchify=snake_case_   )
           for image in image_inputs:
               self.assertIsInstance(snake_case_				,       torch.Tensor   )

           # Test not batched input
           SCREAMING_SNAKE_CASE				:				Dict				      = 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
           SCREAMING_SNAKE_CASE				:				List[Any]				      = image_processing(snake_case_				,       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 	__lowerCAmelCase     (		self   )					->Dict:
           # Initialize image_processing
           SCREAMING_SNAKE_CASE				:				int				      = self.image_processing_class(**self.image_processor_dict   )
           # create random PyTorch tensors
           SCREAMING_SNAKE_CASE				:				List[str]				      = prepare_image_inputs(self.image_processor_tester				,       equal_resolution=snake_case_				,       torchify=snake_case_   )
           SCREAMING_SNAKE_CASE				:				Optional[int]				      = []
           for image in image_inputs:
               self.assertIsInstance(snake_case_				,       torch.Tensor   )
               maps.append(torch.zeros(image.shape[-2:]   ).long()   )

           # Test not batched input
           SCREAMING_SNAKE_CASE				:				Optional[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() <= 255   )

           # Test batched
           SCREAMING_SNAKE_CASE				:				List[Any]				      = image_processing(snake_case_				,       snake_case_				,       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() <= 255   )

           # Test not batched input (PIL images)
           SCREAMING_SNAKE_CASE				:				int				      = prepare_semantic_single_inputs()

           SCREAMING_SNAKE_CASE				:				List[str]				      = image_processing(snake_case_				,       snake_case_				,       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() <= 255   )

           # Test batched input (PIL images)
           SCREAMING_SNAKE_CASE				:				str				      = prepare_semantic_batch_inputs()

           SCREAMING_SNAKE_CASE				:				List[Any]				      = image_processing(snake_case_				,       snake_case_				,       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() <= 255   )






       def 	__lowerCAmelCase     (		self   )					->Any:
           # Initialize image_processing
           SCREAMING_SNAKE_CASE				:				List[Any]				      = 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
           SCREAMING_SNAKE_CASE				:				List[Any]				      = prepare_semantic_single_inputs()
           SCREAMING_SNAKE_CASE				:				Dict				      = image_processing(snake_case_				,       snake_case_				,       return_tensors='''pt'''   )
           self.assertTrue(encoding['''labels'''].min().item() >= 0   )
           self.assertTrue(encoding['''labels'''].max().item() <= 150   )

           SCREAMING_SNAKE_CASE				:				Tuple				      = True
           SCREAMING_SNAKE_CASE				:				Union[str, Any]				      = image_processing(snake_case_				,       snake_case_				,       return_tensors='''pt'''   )
           self.assertTrue(encoding['''labels'''].min().item() >= 0   )
           self.assertTrue(encoding['''labels'''].max().item() <= 255   )


"""simple docstring"""
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   _UpperCAmelCase					(       unittest.TestCase):
    def __init__(     self    ,     snake_case_    ,     snake_case_=7    ,     snake_case_=3    ,     snake_case_=30    ,     snake_case_=4_00    ,     snake_case_=True    ,     snake_case_=None    ,     snake_case_=True    ,     snake_case_=[0.5, 0.5, 0.5]    ,     snake_case_=[0.5, 0.5, 0.5]    ,     snake_case_=False    ,     ):
      _snake_case  :    List[str]            = size if size is not None else {"height": 30, "width": 30}
      _snake_case  :    Optional[int]            = parent
      _snake_case  :    Dict            = batch_size
      _snake_case  :    Any            = num_channels
      _snake_case  :    Optional[Any]            = min_resolution
      _snake_case  :    int            = max_resolution
      _snake_case  :    int            = do_resize
      _snake_case  :    List[Any]            = size
      _snake_case  :    int            = do_normalize
      _snake_case  :    Any            = image_mean
      _snake_case  :    str            = image_std
      _snake_case  :    List[Any]            = do_reduce_labels


    def        lowerCamelCase__						(     self  ):
      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"""







  _snake_case  :    List[str]            = load_dataset("hf-internal-testing/fixtures_ade20k"							,  split="test"		)

  _snake_case  :    Any            = Image.open(dataset[0]["file"]		)
  _snake_case  :    Optional[int]            = Image.open(dataset[1]["file"]		)

  return image, map
def 					a__ ( ):

  """simple docstring"""







  _snake_case  :    Optional[int]            = load_dataset("hf-internal-testing/fixtures_ade20k"							,  split="test"		)

  _snake_case  :    Optional[int]            = Image.open(dataset[0]["file"]		)
  _snake_case  :    List[str]            = Image.open(dataset[1]["file"]		)
  _snake_case  :    Dict            = Image.open(dataset[2]["file"]		)
  _snake_case  :    List[str]            = Image.open(dataset[3]["file"]		)

  return [imagea, imagea], [mapa, mapa]






@require_torch
@require_vision
class   _UpperCAmelCase					(       _snake_case		,       unittest.TestCase):
    __lowercase				:			Dict	=       SegformerImageProcessor if is_vision_available() else None
    def        lowerCamelCase__						(     self  ):
      _snake_case  :    List[str]            = SegformerImageProcessingTester(self  )
    @property
    def        lowerCamelCase__						(     self  ):
      return self.image_processor_tester.prepare_image_processor_dict()
    def        lowerCamelCase__						(     self  ):
      _snake_case  :    List[Any]            = self.image_processing_class(**self.image_processor_dict  )
      self.assertTrue(hasattr(snake_case_    ,     "do_resize"  )  )
      self.assertTrue(hasattr(snake_case_    ,     "size"  )  )
      self.assertTrue(hasattr(snake_case_    ,     "do_normalize"  )  )
      self.assertTrue(hasattr(snake_case_    ,     "image_mean"  )  )
      self.assertTrue(hasattr(snake_case_    ,     "image_std"  )  )
      self.assertTrue(hasattr(snake_case_    ,     "do_reduce_labels"  )  )
    def        lowerCamelCase__						(     self  ):
      _snake_case  :    List[str]            = self.image_processing_class.from_dict(self.image_processor_dict  )
      self.assertEqual(image_processor.size    ,     {"height": 30, "width": 30}  )
      self.assertEqual(image_processor.do_reduce_labels    ,     snake_case_  )

      _snake_case  :    int            = self.image_processing_class.from_dict(self.image_processor_dict    ,     size=42    ,     reduce_labels=snake_case_  )
      self.assertEqual(image_processor.size    ,     {"height": 42, "width": 42}  )
      self.assertEqual(image_processor.do_reduce_labels    ,     snake_case_  )
    def        lowerCamelCase__						(     self  ):
      pass
    def        lowerCamelCase__						(     self  ):
      # Initialize image_processing
      _snake_case  :    List[Any]            = self.image_processing_class(**self.image_processor_dict  )
      # create random PIL images
      _snake_case  :    List[str]            = prepare_image_inputs(self.image_processor_tester    ,     equal_resolution=snake_case_  )
      for image in image_inputs:
        self.assertIsInstance(snake_case_    ,     Image.Image  )

      # Test not batched input
      _snake_case  :    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
      _snake_case  :    List[Any]            = image_processing(snake_case_    ,     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        lowerCamelCase__						(     self  ):
      # Initialize image_processing
      _snake_case  :    Optional[Any]            = self.image_processing_class(**self.image_processor_dict  )
      # create random numpy tensors
      _snake_case  :    Any            = prepare_image_inputs(self.image_processor_tester    ,     equal_resolution=snake_case_    ,     numpify=snake_case_  )
      for image in image_inputs:
        self.assertIsInstance(snake_case_    ,     np.ndarray  )

      # Test not batched input
      _snake_case  :    Optional[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
      _snake_case  :    Optional[int]            = image_processing(snake_case_    ,     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        lowerCamelCase__						(     self  ):
      # Initialize image_processing
      _snake_case  :    Optional[int]            = self.image_processing_class(**self.image_processor_dict  )
      # create random PyTorch tensors
      _snake_case  :    Optional[Any]            = prepare_image_inputs(self.image_processor_tester    ,     equal_resolution=snake_case_    ,     torchify=snake_case_  )
      for image in image_inputs:
        self.assertIsInstance(snake_case_    ,     torch.Tensor  )

      # Test not batched input
      _snake_case  :    Dict            = 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
      _snake_case  :    List[Any]            = image_processing(snake_case_    ,     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        lowerCamelCase__						(     self  ):
      # Initialize image_processing
      _snake_case  :    int            = self.image_processing_class(**self.image_processor_dict  )
      # create random PyTorch tensors
      _snake_case  :    List[str]            = prepare_image_inputs(self.image_processor_tester    ,     equal_resolution=snake_case_    ,     torchify=snake_case_  )
      _snake_case  :    Optional[int]            = []
      for image in image_inputs:
        self.assertIsInstance(snake_case_    ,     torch.Tensor  )
        maps.append(torch.zeros(image.shape[-2:]  ).long()  )

      # Test not batched input
      _snake_case  :    Optional[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_55  )

      # Test batched
      _snake_case  :    List[Any]            = image_processing(snake_case_    ,     snake_case_    ,     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_55  )

      # Test not batched input (PIL images)
      _snake_case      ,       _snake_case  :    int            = prepare_semantic_single_inputs()

      _snake_case  :    List[str]            = image_processing(snake_case_    ,     snake_case_    ,     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_55  )

      # Test batched input (PIL images)
      _snake_case      ,       _snake_case  :    str            = prepare_semantic_batch_inputs()

      _snake_case  :    List[Any]            = image_processing(snake_case_    ,     snake_case_    ,     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_55  )


    def        lowerCamelCase__						(     self  ):
      # Initialize image_processing
      _snake_case  :    List[Any]            = 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
      _snake_case      ,       _snake_case  :    List[Any]            = prepare_semantic_single_inputs()
      _snake_case  :    Dict            = image_processing(snake_case_    ,     snake_case_    ,     return_tensors="pt"  )
      self.assertTrue(encoding["labels"].min().item() >= 0  )
      self.assertTrue(encoding["labels"].max().item() <= 1_50  )

      _snake_case  :    Tuple            = True
      _snake_case  :    Union[str, Any]            = image_processing(snake_case_    ,     snake_case_    ,     return_tensors="pt"  )
      self.assertTrue(encoding["labels"].min().item() >= 0  )
      self.assertTrue(encoding["labels"].max().item() <= 2_55  )

