

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


		"""simple docstring"""

		def __init__(			self   ,      snake_case   ,      snake_case=7   ,      snake_case=3   ,      snake_case=3_0   ,      snake_case=4_0_0   ,      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   ,      ):


							'''simple docstring'''

							UpperCAmelCase		:							str        =       size if size is not None else {"height": 3_0, "width": 3_0}
							UpperCAmelCase		:							Optional[Any]        =       parent
							UpperCAmelCase		:							List[str]        =       batch_size
							UpperCAmelCase		:							List[Any]        =       num_channels
							UpperCAmelCase		:							Optional[Any]        =       min_resolution
							UpperCAmelCase		:							Any        =       max_resolution
							UpperCAmelCase		:							Optional[Any]        =       do_resize
							UpperCAmelCase		:							Dict        =       size
							UpperCAmelCase		:							Union[str, Any]        =       do_normalize
							UpperCAmelCase		:							List[Any]        =       image_mean
							UpperCAmelCase		:							Optional[int]        =       image_std
							UpperCAmelCase		:							Optional[int]        =       do_reduce_labels







		def 				A_	(			self      ):


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



					'''simple docstring'''







					UpperCAmelCase		:							int        =       load_dataset("hf-internal-testing/fixtures_ade20k"			,   split="test"							)

					UpperCAmelCase		:							Union[str, Any]        =       Image.open(dataset[0]["file"]							)
					UpperCAmelCase		:							List[str]        =       Image.open(dataset[1]["file"]							)

					return image, map





def 				lowercase (					):



					'''simple docstring'''







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

					UpperCAmelCase		:							Optional[Any]        =       Image.open(dataset[0]["file"]							)
					UpperCAmelCase		:							Dict        =       Image.open(dataset[1]["file"]							)
					UpperCAmelCase		:							Tuple        =       Image.open(dataset[2]["file"]							)
					UpperCAmelCase		:							Dict        =       Image.open(dataset[3]["file"]							)

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







@require_torch
@require_vision
class   UpperCamelCase__   (       lowercase__							,							unittest.TestCase       ):


		"""simple docstring"""

		SCREAMING_SNAKE_CASE__  :     Any       =							SegformerImageProcessor if is_vision_available() else None







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							List[str]        =       SegformerImageProcessingTester(self      )







		@property
		def 				A_	(			self      ):


							'''simple docstring'''

							return self.image_processor_tester.prepare_image_processor_dict()







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							int        =       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 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Tuple        =       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   ,      snake_case      )

							UpperCAmelCase		:							str        =       self.image_processing_class.from_dict(self.image_processor_dict   ,      size=4_2   ,      reduce_labels=snake_case      )
							self.assertEqual(image_processor.size   ,      {"height": 4_2, "width": 4_2}      )
							self.assertEqual(image_processor.do_reduce_labels   ,      snake_case      )







		def 				A_	(			self      ):


							'''simple docstring'''

							pass







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Dict        =       self.image_processing_class(**self.image_processor_dict      )
							# create random PIL images
							UpperCAmelCase		:							Union[str, Any]        =       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
							UpperCAmelCase		:							List[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
							UpperCAmelCase		:							Optional[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 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Any        =       self.image_processing_class(**self.image_processor_dict      )
							# create random numpy tensors
							UpperCAmelCase		:							Dict        =       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
							UpperCAmelCase		:							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
							UpperCAmelCase		:							Optional[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 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							List[str]        =       self.image_processing_class(**self.image_processor_dict      )
							# create random PyTorch tensors
							UpperCAmelCase		:							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
							UpperCAmelCase		:							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
							UpperCAmelCase		:							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 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[int]        =       self.image_processing_class(**self.image_processor_dict      )
							# create random PyTorch tensors
							UpperCAmelCase		:							str        =       prepare_image_inputs(self.image_processor_tester   ,      equal_resolution=snake_case   ,      torchify=snake_case      )
							UpperCAmelCase		:							List[str]        =       []
							for image in image_inputs:
												self.assertIsInstance(snake_case   ,      torch.Tensor      )
												maps.append(torch.zeros(image.shape[-2:]      ).long()      )

							# Test not batched input
							UpperCAmelCase		:							Tuple        =       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
							UpperCAmelCase		:							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_5_5      )

							# Test not batched input (PIL images)
							UpperCAmelCase ,			UpperCAmelCase		:							str        =       prepare_semantic_single_inputs()

							UpperCAmelCase		:							Any        =       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_5_5      )

							# Test batched input (PIL images)
							UpperCAmelCase ,			UpperCAmelCase		:							Any        =       prepare_semantic_batch_inputs()

							UpperCAmelCase		:							Optional[int]        =       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_5_5      )







		def 				A_	(			self      ):


							'''simple docstring'''

							UpperCAmelCase		:							Optional[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
							UpperCAmelCase ,			UpperCAmelCase		:							List[str]        =       prepare_semantic_single_inputs()
							UpperCAmelCase		:							str        =       image_processing(snake_case   ,      snake_case   ,      return_tensors="pt"      )
							self.assertTrue(encoding["labels"].min().item() >= 0      )
							self.assertTrue(encoding["labels"].max().item() <= 1_5_0      )

							UpperCAmelCase		:							List[str]        =       True
							UpperCAmelCase		:							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_5_5      )



'''simple docstring'''

def 				lowercase (					__magic_name__			,   __magic_name__							):



					'''simple docstring'''







					UpperCAmelCase		:							Dict        =       1.0
					for i in range(1			,   r + 1							):
										ret *= (n + 1 - i) / i
					return round(__magic_name__							)





def 				lowercase (					__magic_name__							):



					'''simple docstring'''







					return choose(8 + n			,   __magic_name__							) + choose(9 + n			,   __magic_name__							) - 10





def 				lowercase (					__magic_name__							):



					'''simple docstring'''







					return sum(non_bouncy_exact(__magic_name__							) for i in range(1			,   n + 1							)							)





def 				lowercase (					__magic_name__ = 100							):



					'''simple docstring'''







					return non_bouncy_upto(__magic_name__							)


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