






import json
import pathlib
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision, slow
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 YolosImageProcessor




class 				a_					(		unittest.TestCase						):


							'''simple docstring'''






							def __init__(						self     ,     lowercase_     ,     lowercase_=7     ,     lowercase_=3     ,     lowercase_=3_0     ,     lowercase_=4_0_0     ,     lowercase_=True     ,     lowercase_=None     ,     lowercase_=True     ,     lowercase_=[0.5, 0.5, 0.5]     ,     lowercase_=[0.5, 0.5, 0.5]     ,     lowercase_=True     ,     lowercase_=1 / 2_5_5     ,     lowercase_=True     ,     )   ->   int:
														'''simple docstring'''

														lowerCAmelCase_									=	size if size is not None else {'shortest_edge': 1_8, 'longest_edge': 1_3_3_3}
														lowerCAmelCase_									=	parent
														lowerCAmelCase_									=	batch_size
														lowerCAmelCase_									=	num_channels
														lowerCAmelCase_									=	min_resolution
														lowerCAmelCase_									=	max_resolution
														lowerCAmelCase_									=	do_resize
														lowerCAmelCase_									=	size
														lowerCAmelCase_									=	do_normalize
														lowerCAmelCase_									=	image_mean
														lowerCAmelCase_									=	image_std
														lowerCAmelCase_									=	do_rescale
														lowerCAmelCase_									=	rescale_factor
														lowerCAmelCase_									=	do_pad

							def 	_lowercase			(						self  )   ->   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_rescale": self.do_rescale,
														    "rescale_factor": self.rescale_factor,
														    "do_pad": self.do_pad,
														}






							def 	_lowercase			(						self     ,     lowercase_     ,     lowercase_=False  )   ->   int:
														'''simple docstring'''

														if not batched:
																					lowerCAmelCase_									=	image_inputs[0]
																					if isinstance(__UpperCAmelCase     ,     Image.Image  ):
																												lowerCAmelCase_		,  lowerCAmelCase_									=	image.size
																					else:
																												lowerCAmelCase_		,  lowerCAmelCase_									=	image.shape[1], image.shape[2]
																					if w < h:
																												lowerCAmelCase_									=	int(self.size['shortest_edge'] * h / w  )
																												lowerCAmelCase_									=	self.size['shortest_edge']
																					elif w > h:
																												lowerCAmelCase_									=	self.size['shortest_edge']
																												lowerCAmelCase_									=	int(self.size['shortest_edge'] * w / h  )
																					else:
																												lowerCAmelCase_									=	self.size['shortest_edge']
																												lowerCAmelCase_									=	self.size['shortest_edge']

														else:
																					lowerCAmelCase_									=	[]
																					for image in image_inputs:
																												lowerCAmelCase_		,  lowerCAmelCase_									=	self.get_expected_values([image]  )
																												expected_values.append((expected_height, expected_width)  )
																					lowerCAmelCase_									=	max(__UpperCAmelCase     ,     key=lambda lowercase_  : item[0]  )[0]
																					lowerCAmelCase_									=	max(__UpperCAmelCase     ,     key=lambda lowercase_  : item[1]  )[1]

														return expected_height, expected_width




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


							'''simple docstring'''






							__a:      Optional[Any]					       =       YolosImageProcessor if is_vision_available() else None

							def 	_lowercase			(						self  )   ->   List[Any]:
														'''simple docstring'''

														lowerCAmelCase_									=	YolosImageProcessingTester(self  )

							@property
							def 	_lowercase			(						self  )   ->   List[str]:
														'''simple docstring'''

														return self.image_processor_tester.prepare_image_processor_dict()

							def 	_lowercase			(						self  )   ->   int:
														'''simple docstring'''

														lowerCAmelCase_									=	self.image_processing_class(**self.image_processor_dict  )
														self.assertTrue(hasattr(__UpperCAmelCase     ,     'image_mean'  )  )
														self.assertTrue(hasattr(__UpperCAmelCase     ,     'image_std'  )  )
														self.assertTrue(hasattr(__UpperCAmelCase     ,     'do_normalize'  )  )
														self.assertTrue(hasattr(__UpperCAmelCase     ,     'do_resize'  )  )
														self.assertTrue(hasattr(__UpperCAmelCase     ,     'size'  )  )

							def 	_lowercase			(						self  )   ->   Any:
														'''simple docstring'''

														lowerCAmelCase_									=	self.image_processing_class.from_dict(self.image_processor_dict  )
														self.assertEqual(image_processor.size     ,     {'shortest_edge': 1_8, 'longest_edge': 1_3_3_3}  )
														self.assertEqual(image_processor.do_pad     ,     __UpperCAmelCase  )

														lowerCAmelCase_									=	self.image_processing_class.from_dict(
														    self.image_processor_dict     ,     size=4_2     ,     max_size=8_4     ,     pad_and_return_pixel_mask=__UpperCAmelCase  )
														self.assertEqual(image_processor.size     ,     {'shortest_edge': 4_2, 'longest_edge': 8_4}  )
														self.assertEqual(image_processor.do_pad     ,     __UpperCAmelCase  )

							def 	_lowercase			(						self  )   ->   int:
														'''simple docstring'''

														pass

							def 	_lowercase			(						self  )   ->   Optional[Any]:
														'''simple docstring'''

														lowerCAmelCase_									=	self.image_processing_class(**self.image_processor_dict  )
														# create random PIL images
														lowerCAmelCase_									=	prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=__UpperCAmelCase  )
														for image in image_inputs:
																					self.assertIsInstance(__UpperCAmelCase     ,     Image.Image  )

														# Test not batched input
														lowerCAmelCase_									=	image_processing(image_inputs[0]     ,     return_tensors='pt'  ).pixel_values

														lowerCAmelCase_		,  lowerCAmelCase_									=	self.image_processor_tester.get_expected_values(__UpperCAmelCase  )

														self.assertEqual(
														    encoded_images.shape     ,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,     )

														# Test batched
														lowerCAmelCase_		,  lowerCAmelCase_									=	self.image_processor_tester.get_expected_values(__UpperCAmelCase     ,     batched=__UpperCAmelCase  )

														lowerCAmelCase_									=	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,
														        expected_height,
														        expected_width,
														    )     ,     )

							def 	_lowercase			(						self  )   ->   Union[str, Any]:
														'''simple docstring'''

														lowerCAmelCase_									=	self.image_processing_class(**self.image_processor_dict  )
														# create random numpy tensors
														lowerCAmelCase_									=	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
														lowerCAmelCase_									=	image_processing(image_inputs[0]     ,     return_tensors='pt'  ).pixel_values

														lowerCAmelCase_		,  lowerCAmelCase_									=	self.image_processor_tester.get_expected_values(__UpperCAmelCase  )

														self.assertEqual(
														    encoded_images.shape     ,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,     )

														# Test batched
														lowerCAmelCase_									=	image_processing(__UpperCAmelCase     ,     return_tensors='pt'  ).pixel_values

														lowerCAmelCase_		,  lowerCAmelCase_									=	self.image_processor_tester.get_expected_values(__UpperCAmelCase     ,     batched=__UpperCAmelCase  )

														self.assertEqual(
														    encoded_images.shape     ,     (
														        self.image_processor_tester.batch_size,
														        self.image_processor_tester.num_channels,
														        expected_height,
														        expected_width,
														    )     ,     )

							def 	_lowercase			(						self  )   ->   Any:
														'''simple docstring'''

														lowerCAmelCase_									=	self.image_processing_class(**self.image_processor_dict  )
														# create random PyTorch tensors
														lowerCAmelCase_									=	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
														lowerCAmelCase_									=	image_processing(image_inputs[0]     ,     return_tensors='pt'  ).pixel_values

														lowerCAmelCase_		,  lowerCAmelCase_									=	self.image_processor_tester.get_expected_values(__UpperCAmelCase  )

														self.assertEqual(
														    encoded_images.shape     ,     (1, self.image_processor_tester.num_channels, expected_height, expected_width)     ,     )

														# Test batched
														lowerCAmelCase_									=	image_processing(__UpperCAmelCase     ,     return_tensors='pt'  ).pixel_values

														lowerCAmelCase_		,  lowerCAmelCase_									=	self.image_processor_tester.get_expected_values(__UpperCAmelCase     ,     batched=__UpperCAmelCase  )

														self.assertEqual(
														    encoded_images.shape     ,     (
														        self.image_processor_tester.batch_size,
														        self.image_processor_tester.num_channels,
														        expected_height,
														        expected_width,
														    )     ,     )

							def 	_lowercase			(						self  )   ->   Dict:
														'''simple docstring'''

														lowerCAmelCase_									=	self.image_processing_class(**self.image_processor_dict  )
														lowerCAmelCase_									=	self.image_processing_class(do_resize=__UpperCAmelCase     ,     do_normalize=__UpperCAmelCase     ,     do_rescale=__UpperCAmelCase  )
														# create random PyTorch tensors
														lowerCAmelCase_									=	prepare_image_inputs(self.image_processor_tester     ,     equal_resolution=__UpperCAmelCase     ,     torchify=__UpperCAmelCase  )
														for image in image_inputs:
																					self.assertIsInstance(__UpperCAmelCase     ,     torch.Tensor  )

														# Test whether the method "pad" and calling the image processor return the same tensors
														lowerCAmelCase_									=	image_processing_a.pad(__UpperCAmelCase     ,     return_tensors='pt'  )
														lowerCAmelCase_									=	image_processing_a(__UpperCAmelCase     ,     return_tensors='pt'  )

														self.assertTrue(
														    torch.allclose(encoded_images_with_method['pixel_values']     ,     encoded_images['pixel_values']     ,     atol=1e-4  )  )

							@slow
							def 	_lowercase			(						self  )   ->   int:
														'''simple docstring'''

														lowerCAmelCase_									=	Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
														with open('./tests/fixtures/tests_samples/COCO/coco_annotations.txt'     ,     'r'  ) as f:
																					lowerCAmelCase_									=	json.loads(f.read()  )

														lowerCAmelCase_									=	{'image_id': 3_9_7_6_9, 'annotations': target}

														# encode them
														lowerCAmelCase_									=	YolosImageProcessor.from_pretrained('hustvl/yolos-small'  )
														lowerCAmelCase_									=	image_processing(images=__UpperCAmelCase     ,     annotations=__UpperCAmelCase     ,     return_tensors='pt'  )

														# verify pixel values
														lowerCAmelCase_									=	torch.Size([1, 3, 8_0_0, 1_0_6_6]  )
														self.assertEqual(encoding['pixel_values'].shape     ,     __UpperCAmelCase  )

														lowerCAmelCase_									=	torch.tensor([0.27_96, 0.31_38, 0.34_81]  )
														self.assertTrue(torch.allclose(encoding['pixel_values'][0, 0, 0, :3]     ,     __UpperCAmelCase     ,     atol=1e-4  )  )

														# verify area
														lowerCAmelCase_									=	torch.tensor([5_8_8_7.9_6_0_0, 1_1_2_5_0.2_0_6_1, 4_8_9_3_5_3.8_4_3_8, 8_3_7_1_2_2.7_5_0_0, 1_4_7_9_6_7.5_1_5_6, 1_6_5_7_3_2.3_4_3_8]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['area']     ,     __UpperCAmelCase  )  )
														# verify boxes
														lowerCAmelCase_									=	torch.Size([6, 4]  )
														self.assertEqual(encoding['labels'][0]['boxes'].shape     ,     __UpperCAmelCase  )
														lowerCAmelCase_									=	torch.tensor([0.55_03, 0.27_65, 0.06_04, 0.22_15]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]     ,     __UpperCAmelCase     ,     atol=1e-3  )  )
														# verify image_id
														lowerCAmelCase_									=	torch.tensor([3_9_7_6_9]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']     ,     __UpperCAmelCase  )  )
														# verify is_crowd
														lowerCAmelCase_									=	torch.tensor([0, 0, 0, 0, 0, 0]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']     ,     __UpperCAmelCase  )  )
														# verify class_labels
														lowerCAmelCase_									=	torch.tensor([7_5, 7_5, 6_3, 6_5, 1_7, 1_7]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']     ,     __UpperCAmelCase  )  )
														# verify orig_size
														lowerCAmelCase_									=	torch.tensor([4_8_0, 6_4_0]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']     ,     __UpperCAmelCase  )  )
														# verify size
														lowerCAmelCase_									=	torch.tensor([8_0_0, 1_0_6_6]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['size']     ,     __UpperCAmelCase  )  )






							@slow
							def 	_lowercase			(						self  )   ->   List[Any]:
														'''simple docstring'''

														lowerCAmelCase_									=	Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'  )
														with open('./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'     ,     'r'  ) as f:
																					lowerCAmelCase_									=	json.loads(f.read()  )

														lowerCAmelCase_									=	{'file_name': '000000039769.png', 'image_id': 3_9_7_6_9, 'segments_info': target}

														lowerCAmelCase_									=	pathlib.Path('./tests/fixtures/tests_samples/COCO/coco_panoptic'  )

														# encode them
														lowerCAmelCase_									=	YolosImageProcessor(format='coco_panoptic'  )
														lowerCAmelCase_									=	image_processing(images=__UpperCAmelCase     ,     annotations=__UpperCAmelCase     ,     masks_path=__UpperCAmelCase     ,     return_tensors='pt'  )

														# verify pixel values
														lowerCAmelCase_									=	torch.Size([1, 3, 8_0_0, 1_0_6_6]  )
														self.assertEqual(encoding['pixel_values'].shape     ,     __UpperCAmelCase  )

														lowerCAmelCase_									=	torch.tensor([0.27_96, 0.31_38, 0.34_81]  )
														self.assertTrue(torch.allclose(encoding['pixel_values'][0, 0, 0, :3]     ,     __UpperCAmelCase     ,     atol=1e-4  )  )

														# verify area
														lowerCAmelCase_									=	torch.tensor([1_4_7_9_7_9.6_8_7_5, 1_6_5_5_2_7.0_4_6_9, 4_8_4_6_3_8.5_9_3_8, 1_1_2_9_2.9_3_7_5, 5_8_7_9.6_5_6_2, 7_6_3_4.1_1_4_7]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['area']     ,     __UpperCAmelCase  )  )
														# verify boxes
														lowerCAmelCase_									=	torch.Size([6, 4]  )
														self.assertEqual(encoding['labels'][0]['boxes'].shape     ,     __UpperCAmelCase  )
														lowerCAmelCase_									=	torch.tensor([0.26_25, 0.54_37, 0.46_88, 0.86_25]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]     ,     __UpperCAmelCase     ,     atol=1e-3  )  )
														# verify image_id
														lowerCAmelCase_									=	torch.tensor([3_9_7_6_9]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']     ,     __UpperCAmelCase  )  )
														# verify is_crowd
														lowerCAmelCase_									=	torch.tensor([0, 0, 0, 0, 0, 0]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']     ,     __UpperCAmelCase  )  )
														# verify class_labels
														lowerCAmelCase_									=	torch.tensor([1_7, 1_7, 6_3, 7_5, 7_5, 9_3]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']     ,     __UpperCAmelCase  )  )
														# verify masks
														lowerCAmelCase_									=	8_2_2_8_7_3
														self.assertEqual(encoding['labels'][0]['masks'].sum().item()     ,     __UpperCAmelCase  )
														# verify orig_size
														lowerCAmelCase_									=	torch.tensor([4_8_0, 6_4_0]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']     ,     __UpperCAmelCase  )  )
														# verify size
														lowerCAmelCase_									=	torch.tensor([8_0_0, 1_0_6_6]  )
														self.assertTrue(torch.allclose(encoding['labels'][0]['size']     ,     __UpperCAmelCase  )  )








def 		a__      (		_UpperCamelCase      :			int			,_UpperCamelCase      :			int				):
   while second != 0:
      __lowerCamelCase    				=     first & second
      first ^= second
      __lowerCamelCase    				=     c << 1
   return first


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  a_								=       int(input("""Enter the first number: """).strip())
  a_								=       int(input("""Enter the second number: """).strip())
  print(f"{add(first, second) = }")






