






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		:					int							,__lowerCamelCase		:					List[str]							,__lowerCamelCase		:					Optional[int]=7							,__lowerCamelCase		:					Any=3							,__lowerCamelCase		:					List[str]=30							,__lowerCamelCase		:					str=4_00							,__lowerCamelCase		:					Any=True							,__lowerCamelCase		:					Tuple=None							,__lowerCamelCase		:					Any=True							,__lowerCamelCase		:					str=[0.5, 0.5, 0.5]							,__lowerCamelCase		:					str=[0.5, 0.5, 0.5]							,__lowerCamelCase		:					str=False							,):





        '''simple docstring'''



        a		=			size if size is not None else {'''height''': 30, '''width''': 30}
        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  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





        '''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   SCREAMING_SNAKE_CASE__						(   )   ->  Tuple:


 """simple docstring"""



 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   SCREAMING_SNAKE_CASE__						(   )   ->  Optional[int]:


 """simple docstring"""



 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 				lowerCamelCase_     (	_SCREAMING_SNAKE_CASE ,						unittest.TestCase     ):
       SCREAMING_SNAKE_CASE_						     =			SegformerImageProcessor if is_vision_available() else None
       def  SCREAMING_SNAKE_CASE_ (						self		:					List[str]					):





        '''simple docstring'''



        a		=			SegformerImageProcessingTester(self					)
       @property
       def  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





        '''simple docstring'''



        return self.image_processor_tester.prepare_image_processor_dict()
       def  SCREAMING_SNAKE_CASE_ (						self		:					str					):





        '''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  SCREAMING_SNAKE_CASE_ (						self		:					Optional[int]					):





        '''simple docstring'''



        a		=			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							,__A					)

        a		=			self.image_processing_class.from_dict(self.image_processor_dict							,size=42							,reduce_labels=__A					)
        self.assertEqual(image_processor.size							,{'''height''': 42, '''width''': 42}					)
        self.assertEqual(image_processor.do_reduce_labels							,__A					)
       def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[int]					):





        '''simple docstring'''



        pass
       def  SCREAMING_SNAKE_CASE_ (						self		:					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  SCREAMING_SNAKE_CASE_ (						self		:					Any					):





        '''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  SCREAMING_SNAKE_CASE_ (						self		:					Dict					):





        '''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  SCREAMING_SNAKE_CASE_ (						self		:					int					):





        '''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_55					)

        # 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_55					)

        # 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_55					)

        # 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_55					)




       def  SCREAMING_SNAKE_CASE_ (						self		:					Optional[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_50					)

        a		=			True
        a		=			image_processing(__A							,__A							,return_tensors='''pt'''					)
        self.assertTrue(encoding['''labels'''].min().item() >= 0					)
        self.assertTrue(encoding['''labels'''].max().item() <= 2_55					)













def   SCREAMING_SNAKE_CASE__						(   snake_case_  )   ->  int:


	"""simple docstring"""



	return n * (2 * n - 1)





def   SCREAMING_SNAKE_CASE__						(   snake_case_  )   ->  bool:


	"""simple docstring"""



	a		=			(1 + 2_4 * n) ** 0.5
	return ((1 + root) / 6) % 1 == 0





def   SCREAMING_SNAKE_CASE__						(   snake_case_ = 1_4_4  )   ->  int:


	"""simple docstring"""



	a		=			start
	a		=			hexagonal_num(snake_case_  )
	while not is_pentagonal(snake_case_  ):
		n += 1
		a		=			hexagonal_num(snake_case_  )
	return num


if __name__ == "__main__":
				print(F"{solution()} = ")





