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 	UpperCamelCase_     (     unittest.TestCase       ):
  
  
  
  					def __init__(		self    :    Any					,			lowerCamelCase    :    Union[str, Any]					,			lowerCamelCase    :    Dict=7					,			lowerCamelCase    :    Tuple=3					,			lowerCamelCase    :    Dict=30					,			lowerCamelCase    :    Optional[int]=4_00					,			lowerCamelCase    :    Optional[int]=True					,			lowerCamelCase    :    Dict=None					,			lowerCamelCase    :    Tuple=True					,			lowerCamelCase    :    str=[0.5, 0.5, 0.5]					,			lowerCamelCase    :    List[Any]=[0.5, 0.5, 0.5]					,			lowerCamelCase    :    Union[str, Any]=False					,			):
  							lowerCamelCase_  :    Any   	=			size if size is not None else {'height': 30, 'width': 30}
  							lowerCamelCase_  :    int   	=			parent
  							lowerCamelCase_  :    str   	=			batch_size
  							lowerCamelCase_  :    Optional[int]   	=			num_channels
  							lowerCamelCase_  :    Any   	=			min_resolution
  							lowerCamelCase_  :    Tuple   	=			max_resolution
  							lowerCamelCase_  :    Union[str, Any]   	=			do_resize
  							lowerCamelCase_  :    int   	=			size
  							lowerCamelCase_  :    Any   	=			do_normalize
  							lowerCamelCase_  :    List[str]   	=			image_mean
  							lowerCamelCase_  :    Union[str, Any]   	=			image_std
  							lowerCamelCase_  :    List[str]   	=			do_reduce_labels
  
  
  
  
  
  					def      __a    (		self    :    int	):
  							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    (   ):
  		lowerCamelCase_  :    Optional[Any]   	=			load_dataset('hf-internal-testing/fixtures_ade20k'       ,split='test'	)
  
  		lowerCamelCase_  :    Any   	=			Image.open(dataset[0]['file']	)
  		lowerCamelCase_  :    Tuple   	=			Image.open(dataset[1]['file']	)
  
  		return image, map
  
  
  def 		_SCREAMING_SNAKE_CASE    (   ):
  		lowerCamelCase_  :    Tuple   	=			load_dataset('hf-internal-testing/fixtures_ade20k'       ,split='test'	)
  
  		lowerCamelCase_  :    Union[str, Any]   	=			Image.open(dataset[0]['file']	)
  		lowerCamelCase_  :    Tuple   	=			Image.open(dataset[1]['file']	)
  		lowerCamelCase_  :    List[Any]   	=			Image.open(dataset[2]['file']	)
  		lowerCamelCase_  :    Optional[int]   	=			Image.open(dataset[3]['file']	)
  
  		return [imagea, imagea], [mapa, mapa]
  
  
  
  
  
  
  @require_torch
  @require_vision
  class 	UpperCamelCase_     (     _UpperCAmelCase     ,    unittest.TestCase       ):
  					_a			:	Optional[int]							=				SegformerImageProcessor if is_vision_available() else None
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    List[str]   	=			SegformerImageProcessingTester(self	)
  
  
  
  					@property
  					def      __a    (		self    :    Dict	):
  							return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  					def      __a    (		self    :    Dict	):
  							lowerCamelCase_  :    Tuple   	=			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      __a    (		self    :    Dict	):
  							lowerCamelCase_  :    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					,			lowerCamelCase	)
  
  							lowerCamelCase_  :    int   	=			self.image_processing_class.from_dict(self.image_processor_dict					,			size=42					,			reduce_labels=lowerCamelCase	)
  							self.assertEqual(image_processor.size					,			{'height': 42, 'width': 42}	)
  							self.assertEqual(image_processor.do_reduce_labels					,			lowerCamelCase	)
  
  
  
  					def      __a    (		self    :    str	):
  							pass
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    Dict   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random PIL images
  							lowerCamelCase_  :    str   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=lowerCamelCase	)
  							for image in image_inputs:
  									self.assertIsInstance(lowerCamelCase					,			Image.Image	)
  
  							# Test not batched input
  							lowerCamelCase_  :    Union[str, 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
  							lowerCamelCase_  :    Tuple   	=			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      __a    (		self    :    Tuple	):
  							lowerCamelCase_  :    Optional[int]   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random numpy tensors
  							lowerCamelCase_  :    Any   	=			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
  							lowerCamelCase_  :    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
  							lowerCamelCase_  :    Optional[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      __a    (		self    :    List[str]	):
  							lowerCamelCase_  :    List[Any]   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random PyTorch tensors
  							lowerCamelCase_  :    Dict   	=			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
  							lowerCamelCase_  :    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
  							lowerCamelCase_  :    List[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      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    List[Any]   	=			self.image_processing_class(**self.image_processor_dict	)
  							# create random PyTorch tensors
  							lowerCamelCase_  :    List[str]   	=			prepare_image_inputs(self.image_processor_tester					,			equal_resolution=lowerCamelCase					,			torchify=lowerCamelCase	)
  							lowerCamelCase_  :    List[Any]   	=			[]
  							for image in image_inputs:
  									self.assertIsInstance(lowerCamelCase					,			torch.Tensor	)
  									maps.append(torch.zeros(image.shape[-2:]	).long()	)
  
  							# Test not batched input
  							lowerCamelCase_  :    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
  							lowerCamelCase_  :    Union[str, Any]   	=			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_55	)
  
  							# Test not batched input (PIL images)
  							lowerCamelCase_	,			lowerCamelCase_  :    Any   	=			prepare_semantic_single_inputs()
  
  							lowerCamelCase_  :    Optional[int]   	=			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_55	)
  
  							# Test batched input (PIL images)
  							lowerCamelCase_	,			lowerCamelCase_  :    int   	=			prepare_semantic_batch_inputs()
  
  							lowerCamelCase_  :    int   	=			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_55	)
  
  
  
  
  
  					def      __a    (		self    :    List[Any]	):
  							lowerCamelCase_  :    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
  							lowerCamelCase_	,			lowerCamelCase_  :    Union[str, Any]   	=			prepare_semantic_single_inputs()
  							lowerCamelCase_  :    str   	=			image_processing(lowerCamelCase					,			lowerCamelCase					,			return_tensors='pt'	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 1_50	)
  
  							lowerCamelCase_  :    List[Any]   	=			True
  							lowerCamelCase_  :    str   	=			image_processing(lowerCamelCase					,			lowerCamelCase					,			return_tensors='pt'	)
  							self.assertTrue(encoding['labels'].min().item() >= 0	)
  							self.assertTrue(encoding['labels'].max().item() <= 2_55	)
  
style_context: 
  
  
  
  
  
  def 		_SCREAMING_SNAKE_CASE    (   lowerCAmelCase__       ,lowerCAmelCase__	):
  		return (input_a, input_a).count(0	) % 2
  
  
  def 		_SCREAMING_SNAKE_CASE    (   ):
  		assert xor_gate(0       ,0	) == 0
  		assert xor_gate(0       ,1	) == 1
  		assert xor_gate(1       ,0	) == 1
  		assert xor_gate(1       ,1	) == 0
  
  
  if __name__ == "__main__":
  		print(xor_gate(0, 0))
  		print(xor_gate(0, 1))
  