def A__  (			lowercase:     int,		lowercase:     int					)				->		int:
       return int(input_a == input_a == 0					)



def A__  (			)				->		None:
       print('Truth Table of NOR Gate:'					)
       print('|   Input 1   |  Input 2  | Output |'					)
       print(F'|      0      |    0      |  {nor_gate(0,		0					)}     |'					)
       print(F'|      0      |    1      |  {nor_gate(0,		1					)}     |'					)
       print(F'|      1      |    0      |  {nor_gate(1,		0					)}     |'					)
       print(F'|      1      |    1      |  {nor_gate(1,		1					)}     |'					)


if __name__ == "__main__":
    import doctest

    doctest.testmod()
    main()







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 ConditionalDetrImageProcessor



class  SCREAMING_SNAKE_CASE_ (					unittest.TestCase			):
  '''simple docstring'''


  def __init__(				self    :					Union[str, Any]      ,	SCREAMING_SNAKE_CASE__    :					Any      ,	SCREAMING_SNAKE_CASE__    :					Tuple=7      ,	SCREAMING_SNAKE_CASE__    :					Dict=3      ,	SCREAMING_SNAKE_CASE__    :					Tuple=30      ,	SCREAMING_SNAKE_CASE__    :					int=4_00      ,	SCREAMING_SNAKE_CASE__    :					Dict=True      ,	SCREAMING_SNAKE_CASE__    :					Dict=None      ,	SCREAMING_SNAKE_CASE__    :					List[Any]=True      ,	SCREAMING_SNAKE_CASE__    :					Dict=[0.5, 0.5, 0.5]      ,	SCREAMING_SNAKE_CASE__    :					str=[0.5, 0.5, 0.5]      ,	SCREAMING_SNAKE_CASE__    :					Optional[Any]=True      ,	SCREAMING_SNAKE_CASE__    :					Any=1 / 2_55      ,	SCREAMING_SNAKE_CASE__    :					int=True      ,	)    ->				Optional[int]:
         # by setting size["longest_edge"] > max_resolution we're effectively not testing this :p
         A						:     Optional[Any]         =size if size is not None else {'shortest_edge': 18, 'longest_edge': 13_33}
         A						:     Union[str, Any]         =parent
         A						:     Union[str, Any]         =batch_size
         A						:     Union[str, Any]         =num_channels
         A						:     int         =min_resolution
         A						:     List[Any]         =max_resolution
         A						:     Dict         =do_resize
         A						:     Tuple         =size
         A						:     List[str]         =do_normalize
         A						:     List[Any]         =image_mean
         A						:     Dict         =image_std
         A						:     Any         =do_rescale
         A						:     List[str]         =rescale_factor
         A						:     Optional[Any]         =do_pad







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Tuple     )    ->				List[Any]:
         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 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[Any]      ,	SCREAMING_SNAKE_CASE__    :					Any      ,	SCREAMING_SNAKE_CASE__    :					Dict=False     )    ->				Dict:
         if not batched:
                A						:     Any         =image_inputs[0]
                if isinstance(SCREAMING_SNAKE_CASE__      ,	Image.Image     ):
                       A  ,  A						:     Union[str, Any]         =image.size
                else:
                       A  ,  A						:     Tuple         =image.shape[1], image.shape[2]
                if w < h:
                       A						:     Any         =int(self.size['shortest_edge'] * h / w     )
                       A						:     Any         =self.size['shortest_edge']
                elif w > h:
                       A						:     Dict         =self.size['shortest_edge']
                       A						:     Dict         =int(self.size['shortest_edge'] * w / h     )
                else:
                       A						:     List[str]         =self.size['shortest_edge']
                       A						:     Dict         =self.size['shortest_edge']

         else:
                A						:     List[Any]         =[]
                for image in image_inputs:
                       A  ,  A						:     int         =self.get_expected_values([image]     )
                       expected_values.append((expected_height, expected_width)     )
                A						:     str         =max(SCREAMING_SNAKE_CASE__      ,	key=lambda SCREAMING_SNAKE_CASE__     : item[0]     )[0]
                A						:     Tuple         =max(SCREAMING_SNAKE_CASE__      ,	key=lambda SCREAMING_SNAKE_CASE__     : item[1]     )[1]

         return expected_height, expected_width







@require_torch
@require_vision
class  SCREAMING_SNAKE_CASE_ (					lowerCAmelCase_   ,						unittest.TestCase			):
  '''simple docstring'''


  lowercase		:     List[Any]            =				ConditionalDetrImageProcessor if is_vision_available() else None







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Tuple     )    ->				Tuple:
         A						:     str         =ConditionalDetrImageProcessingTester(self     )







  @property
  def 		SCREAMING_SNAKE_CASE_		(				self    :					Union[str, Any]     )    ->				int:
         return self.image_processor_tester.prepare_image_processor_dict()







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Any     )    ->				Tuple:
         A						:     Tuple         =self.image_processing_class(**self.image_processor_dict     )
         self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,	'image_mean'     )     )
         self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,	'image_std'     )     )
         self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,	'do_normalize'     )     )
         self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,	'do_resize'     )     )
         self.assertTrue(hasattr(SCREAMING_SNAKE_CASE__      ,	'size'     )     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[str]     )    ->				int:
         A						:     int         =self.image_processing_class.from_dict(self.image_processor_dict     )
         self.assertEqual(image_processor.size      ,	{'shortest_edge': 18, 'longest_edge': 13_33}     )
         self.assertEqual(image_processor.do_pad      ,	SCREAMING_SNAKE_CASE__     )

         A						:     str         =self.image_processing_class.from_dict(
             self.image_processor_dict      ,	size=42      ,	max_size=84      ,	pad_and_return_pixel_mask=SCREAMING_SNAKE_CASE__     )
         self.assertEqual(image_processor.size      ,	{'shortest_edge': 42, 'longest_edge': 84}     )
         self.assertEqual(image_processor.do_pad      ,	SCREAMING_SNAKE_CASE__     )







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Optional[int]     )    ->				Optional[int]:
         pass







  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[Any]     )    ->				Union[str, Any]:
         # Initialize image_processing
         A						:     Union[str, Any]         =self.image_processing_class(**self.image_processor_dict     )
         # create random PIL images
         A						:     Tuple         =prepare_image_inputs(self.image_processor_tester      ,	equal_resolution=SCREAMING_SNAKE_CASE__     )
         for image in image_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE__      ,	Image.Image     )

         # Test not batched input
         A						:     List[Any]         =image_processing(image_inputs[0]      ,	return_tensors='pt'     ).pixel_values

         A  ,  A						:     List[str]         =self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__     )

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

         # Test batched
         A  ,  A						:     Union[str, Any]         =self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__      ,	batched=SCREAMING_SNAKE_CASE__     )

         A						:     Union[str, Any]         =image_processing(SCREAMING_SNAKE_CASE__      ,	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 		SCREAMING_SNAKE_CASE_		(				self    :					Union[str, Any]     )    ->				int:
         # Initialize image_processing
         A						:     Optional[Any]         =self.image_processing_class(**self.image_processor_dict     )
         # create random numpy tensors
         A						:     str         =prepare_image_inputs(self.image_processor_tester      ,	equal_resolution=SCREAMING_SNAKE_CASE__      ,	numpify=SCREAMING_SNAKE_CASE__     )
         for image in image_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE__      ,	np.ndarray     )

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

         A  ,  A						:     Any         =self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__     )

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

         # Test batched
         A						:     Tuple         =image_processing(SCREAMING_SNAKE_CASE__      ,	return_tensors='pt'     ).pixel_values

         A  ,  A						:     Optional[int]         =self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__      ,	batched=SCREAMING_SNAKE_CASE__     )

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







  def 		SCREAMING_SNAKE_CASE_		(				self    :					Union[str, Any]     )    ->				List[str]:
         # Initialize image_processing
         A						:     Optional[Any]         =self.image_processing_class(**self.image_processor_dict     )
         # create random PyTorch tensors
         A						:     Any         =prepare_image_inputs(self.image_processor_tester      ,	equal_resolution=SCREAMING_SNAKE_CASE__      ,	torchify=SCREAMING_SNAKE_CASE__     )
         for image in image_inputs:
                self.assertIsInstance(SCREAMING_SNAKE_CASE__      ,	torch.Tensor     )

         # Test not batched input
         A						:     Optional[int]         =image_processing(image_inputs[0]      ,	return_tensors='pt'     ).pixel_values

         A  ,  A						:     Tuple         =self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__     )

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

         # Test batched
         A						:     Tuple         =image_processing(SCREAMING_SNAKE_CASE__      ,	return_tensors='pt'     ).pixel_values

         A  ,  A						:     int         =self.image_processor_tester.get_expected_values(SCREAMING_SNAKE_CASE__      ,	batched=SCREAMING_SNAKE_CASE__     )

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







  @slow
  def 		SCREAMING_SNAKE_CASE_		(				self    :					Any     )    ->				Union[str, Any]:
         # prepare image and target
         A						:     Union[str, Any]         =Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
         with open('./tests/fixtures/tests_samples/COCO/coco_annotations.txt'      ,	'r'     ) as f:
                A						:     List[Any]         =json.loads(f.read()     )

         A						:     Any         ={'image_id': 3_97_69, 'annotations': target}

         # encode them
         A						:     str         =ConditionalDetrImageProcessor.from_pretrained('microsoft/conditional-detr-resnet-50'     )
         A						:     Any         =image_processing(images=SCREAMING_SNAKE_CASE__      ,	annotations=SCREAMING_SNAKE_CASE__      ,	return_tensors='pt'     )

         # verify pixel values
         A						:     Optional[Any]         =torch.Size([1, 3, 8_00, 10_66]     )
         self.assertEqual(encoding['pixel_values'].shape      ,	SCREAMING_SNAKE_CASE__     )

         A						:     List[str]         =torch.tensor([0.2_7_9_6, 0.3_1_3_8, 0.3_4_8_1]     )
         self.assertTrue(torch.allclose(encoding['pixel_values'][0, 0, 0, :3]      ,	SCREAMING_SNAKE_CASE__      ,	atol=1e-4     )     )

         # verify area
         A						:     Dict         =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']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify boxes
         A						:     str         =torch.Size([6, 4]     )
         self.assertEqual(encoding['labels'][0]['boxes'].shape      ,	SCREAMING_SNAKE_CASE__     )
         A						:     Union[str, Any]         =torch.tensor([0.5_5_0_3, 0.2_7_6_5, 0.0_6_0_4, 0.2_2_1_5]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]      ,	SCREAMING_SNAKE_CASE__      ,	atol=1e-3     )     )
         # verify image_id
         A						:     Dict         =torch.tensor([3_97_69]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify is_crowd
         A						:     List[str]         =torch.tensor([0, 0, 0, 0, 0, 0]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify class_labels
         A						:     Union[str, Any]         =torch.tensor([75, 75, 63, 65, 17, 17]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify orig_size
         A						:     List[Any]         =torch.tensor([4_80, 6_40]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify size
         A						:     int         =torch.tensor([8_00, 10_66]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['size']      ,	SCREAMING_SNAKE_CASE__     )     )







  @slow
  def 		SCREAMING_SNAKE_CASE_		(				self    :					List[Any]     )    ->				Tuple:
         # prepare image, target and masks_path
         A						:     List[str]         =Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     )
         with open('./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'      ,	'r'     ) as f:
                A						:     Optional[int]         =json.loads(f.read()     )

         A						:     int         ={'file_name': '000000039769.png', 'image_id': 3_97_69, 'segments_info': target}

         A						:     Optional[Any]         =pathlib.Path('./tests/fixtures/tests_samples/COCO/coco_panoptic'     )

         # encode them
         A						:     List[Any]         =ConditionalDetrImageProcessor(format='coco_panoptic'     )
         A						:     Union[str, Any]         =image_processing(images=SCREAMING_SNAKE_CASE__      ,	annotations=SCREAMING_SNAKE_CASE__      ,	masks_path=SCREAMING_SNAKE_CASE__      ,	return_tensors='pt'     )

         # verify pixel values
         A						:     Dict         =torch.Size([1, 3, 8_00, 10_66]     )
         self.assertEqual(encoding['pixel_values'].shape      ,	SCREAMING_SNAKE_CASE__     )

         A						:     Dict         =torch.tensor([0.2_7_9_6, 0.3_1_3_8, 0.3_4_8_1]     )
         self.assertTrue(torch.allclose(encoding['pixel_values'][0, 0, 0, :3]      ,	SCREAMING_SNAKE_CASE__      ,	atol=1e-4     )     )

         # verify area
         A						:     Optional[int]         =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']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify boxes
         A						:     List[Any]         =torch.Size([6, 4]     )
         self.assertEqual(encoding['labels'][0]['boxes'].shape      ,	SCREAMING_SNAKE_CASE__     )
         A						:     Any         =torch.tensor([0.2_6_2_5, 0.5_4_3_7, 0.4_6_8_8, 0.8_6_2_5]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['boxes'][0]      ,	SCREAMING_SNAKE_CASE__      ,	atol=1e-3     )     )
         # verify image_id
         A						:     List[Any]         =torch.tensor([3_97_69]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['image_id']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify is_crowd
         A						:     Any         =torch.tensor([0, 0, 0, 0, 0, 0]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['iscrowd']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify class_labels
         A						:     str         =torch.tensor([17, 17, 63, 75, 75, 93]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['class_labels']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify masks
         A						:     int         =82_28_73
         self.assertEqual(encoding['labels'][0]['masks'].sum().item()      ,	SCREAMING_SNAKE_CASE__     )
         # verify orig_size
         A						:     Any         =torch.tensor([4_80, 6_40]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['orig_size']      ,	SCREAMING_SNAKE_CASE__     )     )
         # verify size
         A						:     str         =torch.tensor([8_00, 10_66]     )
         self.assertTrue(torch.allclose(encoding['labels'][0]['size']      ,	SCREAMING_SNAKE_CASE__     )     )






