



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




					'''simple docstring'''



					def __init__(	self					:						Dict  ,	UpperCamelCase_					:						str  ,	UpperCamelCase_					:						Dict=7  ,	UpperCamelCase_					:						str=3  ,	UpperCamelCase_					:						List[str]=30  ,	UpperCamelCase_					:						str=400  ,	UpperCamelCase_					:						Optional[int]=True  ,	UpperCamelCase_					:						Dict=None  ,	UpperCamelCase_					:						Optional[int]=True  ,	UpperCamelCase_					:						int=[0.5, 0.5, 0.5]  ,	UpperCamelCase_					:						Optional[int]=[0.5, 0.5, 0.5]  ,	UpperCamelCase_					:						List[str]=False  ,	)	->							Union[str, Any]:



						'''simple docstring'''





						_lowercase       :							Optional[int]  	=		size if size is not None else {'height': 30, 'width': 30}
						_lowercase       :							str  	=		parent
						_lowercase       :							int  	=		batch_size
						_lowercase       :							Tuple  	=		num_channels
						_lowercase       :							Optional[int]  	=		min_resolution
						_lowercase       :							Dict  	=		max_resolution
						_lowercase       :							Tuple  	=		do_resize
						_lowercase       :							Optional[int]  	=		size
						_lowercase       :							Tuple  	=		do_normalize
						_lowercase       :							Any  	=		image_mean
						_lowercase       :							Dict  	=		image_std
						_lowercase       :							Optional[int]  	=		do_reduce_labels




					def     __UpperCAmelCase  (	self					:						Optional[int]       )	->							Optional[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     __UpperCamelCase					(				)			->      Any:
	_lowercase       :							Dict  	=		load_dataset('hf-internal-testing/fixtures_ade20k',					split='test'       )

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

	return image, map







def     __UpperCamelCase					(				)			->      Tuple:
	_lowercase       :							str  	=		load_dataset('hf-internal-testing/fixtures_ade20k',					split='test'       )

	_lowercase       :							Tuple  	=		Image.open(dataset[0]['file']       )
	_lowercase       :							Tuple  	=		Image.open(dataset[1]['file']       )
	_lowercase       :							List[str]  	=		Image.open(dataset[2]['file']       )
	_lowercase       :							List[str]  	=		Image.open(dataset[3]['file']       )

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






@require_torch
@require_vision
class 		lowerCamelCase__   (    A						, unittest.TestCase  ):




					'''simple docstring'''



					A_         =    SegformerImageProcessor if is_vision_available() else None




					def     __UpperCAmelCase  (	self					:						int       )	->							Optional[int]:



						'''simple docstring'''





						_lowercase       :							int  	=		SegformerImageProcessingTester(self       )




					@property
					def     __UpperCAmelCase  (	self					:						List[str]       )	->							Optional[Any]:



						'''simple docstring'''





						return self.image_processor_tester.prepare_image_processor_dict()




					def     __UpperCAmelCase  (	self					:						str       )	->							List[Any]:



						'''simple docstring'''





						_lowercase       :							int  	=		self.image_processing_class(**self.image_processor_dict       )
						self.assertTrue(hasattr(UpperCamelCase_  ,	'do_resize'       )       )
						self.assertTrue(hasattr(UpperCamelCase_  ,	'size'       )       )
						self.assertTrue(hasattr(UpperCamelCase_  ,	'do_normalize'       )       )
						self.assertTrue(hasattr(UpperCamelCase_  ,	'image_mean'       )       )
						self.assertTrue(hasattr(UpperCamelCase_  ,	'image_std'       )       )
						self.assertTrue(hasattr(UpperCamelCase_  ,	'do_reduce_labels'       )       )




					def     __UpperCAmelCase  (	self					:						Dict       )	->							List[Any]:



						'''simple docstring'''





						_lowercase       :							Optional[int]  	=		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  ,	UpperCamelCase_       )

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




					def     __UpperCAmelCase  (	self					:						Optional[Any]       )	->							List[str]:



						'''simple docstring'''





						pass




					def     __UpperCAmelCase  (	self					:						str       )	->							Tuple:



						'''simple docstring'''





						_lowercase       :							Tuple  	=		self.image_processing_class(**self.image_processor_dict       )
						# create random PIL images
						_lowercase       :							List[Any]  	=		prepare_image_inputs(self.image_processor_tester  ,	equal_resolution=UpperCamelCase_       )
						for image in image_inputs:
							self.assertIsInstance(UpperCamelCase_  ,	Image.Image       )

						# Test not batched input
						_lowercase       :							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
						_lowercase       :							Union[str, Any]  	=		image_processing(UpperCamelCase_  ,	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     __UpperCAmelCase  (	self					:						Dict       )	->							Dict:



						'''simple docstring'''





						_lowercase       :							Optional[int]  	=		self.image_processing_class(**self.image_processor_dict       )
						# create random numpy tensors
						_lowercase       :							Any  	=		prepare_image_inputs(self.image_processor_tester  ,	equal_resolution=UpperCamelCase_  ,	numpify=UpperCamelCase_       )
						for image in image_inputs:
							self.assertIsInstance(UpperCamelCase_  ,	np.ndarray       )

						# Test not batched input
						_lowercase       :							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
						_lowercase       :							int  	=		image_processing(UpperCamelCase_  ,	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     __UpperCAmelCase  (	self					:						str       )	->							List[Any]:



						'''simple docstring'''





						_lowercase       :							Any  	=		self.image_processing_class(**self.image_processor_dict       )
						# create random PyTorch tensors
						_lowercase       :							str  	=		prepare_image_inputs(self.image_processor_tester  ,	equal_resolution=UpperCamelCase_  ,	torchify=UpperCamelCase_       )
						for image in image_inputs:
							self.assertIsInstance(UpperCamelCase_  ,	torch.Tensor       )

						# Test not batched input
						_lowercase       :							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
						_lowercase       :							Optional[int]  	=		image_processing(UpperCamelCase_  ,	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     __UpperCAmelCase  (	self					:						int       )	->							List[Any]:



						'''simple docstring'''





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

						# Test not batched input
						_lowercase       :							str  	=		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
						_lowercase       :							int  	=		image_processing(UpperCamelCase_  ,	UpperCamelCase_  ,	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)
						_lowercase	,     _lowercase       :							Union[str, Any]  	=		prepare_semantic_single_inputs()

						_lowercase       :							List[Any]  	=		image_processing(UpperCamelCase_  ,	UpperCamelCase_  ,	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)
						_lowercase	,     _lowercase       :							int  	=		prepare_semantic_batch_inputs()

						_lowercase       :							Dict  	=		image_processing(UpperCamelCase_  ,	UpperCamelCase_  ,	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     __UpperCAmelCase  (	self					:						Optional[Any]       )	->							List[Any]:



						'''simple docstring'''





						_lowercase       :							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
						_lowercase	,     _lowercase       :							str  	=		prepare_semantic_single_inputs()
						_lowercase       :							List[str]  	=		image_processing(UpperCamelCase_  ,	UpperCamelCase_  ,	return_tensors='pt'       )
						self.assertTrue(encoding['labels'].min().item() >= 0       )
						self.assertTrue(encoding['labels'].max().item() <= 150       )

						_lowercase       :							List[str]  	=		True
						_lowercase       :							Dict  	=		image_processing(UpperCamelCase_  ,	UpperCamelCase_  ,	return_tensors='pt'       )
						self.assertTrue(encoding['labels'].min().item() >= 0       )
						self.assertTrue(encoding['labels'].max().item() <= 255       )





'''simple docstring'''

def     __UpperCamelCase					(				_lowercase = 1000       )			->      int:
	_lowercase       :							Dict  	=		0
	_lowercase       :							int  	=		0
	while 1:
		num += 3
		if num >= n:
			break
		total += num
		num += 2
		if num >= n:
			break
		total += num
		num += 1
		if num >= n:
			break
		total += num
		num += 3
		if num >= n:
			break
		total += num
		num += 1
		if num >= n:
			break
		total += num
		num += 2
		if num >= n:
			break
		total += num
		num += 3
		if num >= n:
			break
		total += num
	return total


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