





"""simple docstring"""






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 DeformableDetrImageProcessor






class 	__snake_case	(     unittest.TestCase):




  def __init__(			self					:						Dict						, __lowerCAmelCase					:						str						, __lowerCAmelCase					:						Dict=7						, __lowerCAmelCase					:						Any=3						, __lowerCAmelCase					:						List[str]=3_0						, __lowerCAmelCase					:						Union[str, Any]=4_0_0						, __lowerCAmelCase					:						Any=True						, __lowerCAmelCase					:						int=None						, __lowerCAmelCase					:						List[Any]=True						, __lowerCAmelCase					:						Any=[0.5, 0.5, 0.5]						, __lowerCAmelCase					:						Optional[int]=[0.5, 0.5, 0.5]						, __lowerCAmelCase					:						List[str]=True						, __lowerCAmelCase					:						Tuple=1 / 2_5_5						, __lowerCAmelCase					:						Union[str, Any]=True						, ):






         """simple docstring"""






         _lowerCamelCase						:    Any         =			size if size is not None else {'''shortest_edge''': 1_8, '''longest_edge''': 1_3_3_3}
         _lowerCamelCase						:    Optional[Any]         =			parent
         _lowerCamelCase						:    Optional[Any]         =			batch_size
         _lowerCamelCase						:    Union[str, Any]         =			num_channels
         _lowerCamelCase						:    str         =			min_resolution
         _lowerCamelCase						:    Optional[int]         =			max_resolution
         _lowerCamelCase						:    Dict         =			do_resize
         _lowerCamelCase						:    List[Any]         =			size
         _lowerCamelCase						:    Any         =			do_normalize
         _lowerCamelCase						:    List[str]         =			image_mean
         _lowerCamelCase						:    str         =			image_std
         _lowerCamelCase						:    Optional[Any]         =			do_rescale
         _lowerCamelCase						:    int         =			rescale_factor
         _lowerCamelCase						:    Any         =			do_pad




  def 						SCREAMING_SNAKE_CASE    (			self					:						Union[str, Any]		):






         """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 						SCREAMING_SNAKE_CASE    (			self					:						Any						, __lowerCAmelCase					:						Optional[int]						, __lowerCAmelCase					:						Any=False		):






         """simple docstring"""






         if not batched:
                _lowerCamelCase						:    Any         =			image_inputs[0]
                if isinstance(__lowerCAmelCase						, Image.Image		):
                       _lowerCamelCase						:    Tuple         =			image.size
                else:
                       _lowerCamelCase						:    Optional[Any]         =			image.shape[1], image.shape[2]
                if w < h:
                       _lowerCamelCase						:    str         =			int(self.size['''shortest_edge'''] * h / w		)
                       _lowerCamelCase						:    Union[str, Any]         =			self.size['''shortest_edge''']
                elif w > h:
                       _lowerCamelCase						:    Dict         =			self.size['''shortest_edge''']
                       _lowerCamelCase						:    Union[str, Any]         =			int(self.size['''shortest_edge'''] * w / h		)
                else:
                       _lowerCamelCase						:    str         =			self.size['''shortest_edge''']
                       _lowerCamelCase						:    Dict         =			self.size['''shortest_edge''']

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

         return expected_height, expected_width






@require_torch
@require_vision
class 	__snake_case	(     _lowercase  ,					unittest.TestCase):
  snake_case__    :       Tuple        =						DeformableDetrImageProcessor if is_vision_available() else None




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """simple docstring"""






         _lowerCamelCase						:    str         =			DeformableDetrImageProcessingTester(self		)




  @property
  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """simple docstring"""






         return self.image_processor_tester.prepare_image_processor_dict()




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]		):






         """simple docstring"""






         _lowerCamelCase						:    int         =			self.image_processing_class(**self.image_processor_dict		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''image_mean'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''image_std'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''do_normalize'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''do_resize'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''do_rescale'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''do_pad'''		)		)
         self.assertTrue(hasattr(__lowerCAmelCase						, '''size'''		)		)




  def 						SCREAMING_SNAKE_CASE    (			self					:						Union[str, Any]		):






         """simple docstring"""






         _lowerCamelCase						:    List[str]         =			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						, __lowerCAmelCase		)

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




  def 						SCREAMING_SNAKE_CASE    (			self					:						Dict		):






         """simple docstring"""






         pass




  def 						SCREAMING_SNAKE_CASE    (			self					:						Any		):






         """simple docstring"""






         _lowerCamelCase						:    str         =			self.image_processing_class(**self.image_processor_dict		)
         # create random PIL images
         _lowerCamelCase						:    Dict         =			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						:    List[str]         =			image_processing(image_inputs[0]						, return_tensors='''pt'''		).pixel_values

         _lowerCamelCase						:    Dict         =			self.image_processor_tester.get_expected_values(__lowerCAmelCase		)

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

         # Test batched
         _lowerCamelCase						:    Optional[Any]         =			self.image_processor_tester.get_expected_values(__lowerCAmelCase						, batched=__lowerCAmelCase		)

         _lowerCamelCase						:    str         =			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,
                 expected_height,
                 expected_width,
             )						, )




  def 						SCREAMING_SNAKE_CASE    (			self					:						Dict		):






         """simple docstring"""






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

         _lowerCamelCase						:    List[Any]         =			self.image_processor_tester.get_expected_values(__lowerCAmelCase		)

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

         # Test batched
         _lowerCamelCase						:    Dict         =			image_processing(__lowerCAmelCase						, return_tensors='''pt'''		).pixel_values

         _lowerCamelCase						:    int         =			self.image_processor_tester.get_expected_values(__lowerCAmelCase						, batched=__lowerCAmelCase		)

         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					:						List[Any]		):






         """simple docstring"""






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

         _lowerCamelCase						:    str         =			self.image_processor_tester.get_expected_values(__lowerCAmelCase		)

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

         # Test batched
         _lowerCamelCase						:    Optional[Any]         =			image_processing(__lowerCAmelCase						, return_tensors='''pt'''		).pixel_values

         _lowerCamelCase						:    Optional[int]         =			self.image_processor_tester.get_expected_values(__lowerCAmelCase						, batched=__lowerCAmelCase		)

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






         """simple docstring"""






         _lowerCamelCase						:    Optional[Any]         =			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
         with open('''./tests/fixtures/tests_samples/COCO/coco_annotations.txt'''						, '''r'''		) as f:
                _lowerCamelCase						:    List[str]         =			json.loads(f.read()		)

         _lowerCamelCase						:    Tuple         =			{'''image_id''': 3_9_7_6_9, '''annotations''': target}

         # encode them
         _lowerCamelCase						:    Union[str, Any]         =			DeformableDetrImageProcessor()
         _lowerCamelCase						:    List[Any]         =			image_processing(images=__lowerCAmelCase						, annotations=__lowerCAmelCase						, return_tensors='''pt'''		)

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

         _lowerCamelCase						:    List[Any]         =			torch.tensor([0.27_96, 0.31_38, 0.34_81]		)
         self.assertTrue(torch.allclose(encoding['''pixel_values'''][0, 0, 0, :3]						, __lowerCAmelCase						, atol=1E-4		)		)

         # verify area
         _lowerCamelCase						:    Optional[int]         =			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''']						, __lowerCAmelCase		)		)
         # verify boxes
         _lowerCamelCase						:    Dict         =			torch.Size([6, 4]		)
         self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape						, __lowerCAmelCase		)
         _lowerCamelCase						:    str         =			torch.tensor([0.55_03, 0.27_65, 0.06_04, 0.22_15]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]						, __lowerCAmelCase						, atol=1E-3		)		)
         # verify image_id
         _lowerCamelCase						:    Optional[int]         =			torch.tensor([3_9_7_6_9]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']						, __lowerCAmelCase		)		)
         # verify is_crowd
         _lowerCamelCase						:    Dict         =			torch.tensor([0, 0, 0, 0, 0, 0]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']						, __lowerCAmelCase		)		)
         # verify class_labels
         _lowerCamelCase						:    Union[str, Any]         =			torch.tensor([7_5, 7_5, 6_3, 6_5, 1_7, 1_7]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']						, __lowerCAmelCase		)		)
         # verify orig_size
         _lowerCamelCase						:    Dict         =			torch.tensor([4_8_0, 6_4_0]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']						, __lowerCAmelCase		)		)
         # verify size
         _lowerCamelCase						:    Optional[int]         =			torch.tensor([8_0_0, 1_0_6_6]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']						, __lowerCAmelCase		)		)




  @slow
  def 						SCREAMING_SNAKE_CASE    (			self					:						Optional[int]		):






         """simple docstring"""






         _lowerCamelCase						:    Optional[Any]         =			Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''		)
         with open('''./tests/fixtures/tests_samples/COCO/coco_panoptic_annotations.txt'''						, '''r'''		) as f:
                _lowerCamelCase						:    Dict         =			json.loads(f.read()		)

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

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

         # encode them
         _lowerCamelCase						:    Any         =			DeformableDetrImageProcessor(format='''coco_panoptic'''		)
         _lowerCamelCase						:    List[Any]         =			image_processing(images=__lowerCAmelCase						, annotations=__lowerCAmelCase						, masks_path=__lowerCAmelCase						, return_tensors='''pt'''		)

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

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

         # verify area
         _lowerCamelCase						:    Union[str, Any]         =			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''']						, __lowerCAmelCase		)		)
         # verify boxes
         _lowerCamelCase						:    List[Any]         =			torch.Size([6, 4]		)
         self.assertEqual(encoding['''labels'''][0]['''boxes'''].shape						, __lowerCAmelCase		)
         _lowerCamelCase						:    Union[str, Any]         =			torch.tensor([0.26_25, 0.54_37, 0.46_88, 0.86_25]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''boxes'''][0]						, __lowerCAmelCase						, atol=1E-3		)		)
         # verify image_id
         _lowerCamelCase						:    List[Any]         =			torch.tensor([3_9_7_6_9]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''image_id''']						, __lowerCAmelCase		)		)
         # verify is_crowd
         _lowerCamelCase						:    Dict         =			torch.tensor([0, 0, 0, 0, 0, 0]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''iscrowd''']						, __lowerCAmelCase		)		)
         # verify class_labels
         _lowerCamelCase						:    Tuple         =			torch.tensor([1_7, 1_7, 6_3, 7_5, 7_5, 9_3]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''class_labels''']						, __lowerCAmelCase		)		)
         # verify masks
         _lowerCamelCase						:    List[str]         =			8_2_2_8_7_3
         self.assertEqual(encoding['''labels'''][0]['''masks'''].sum().item()						, __lowerCAmelCase		)
         # verify orig_size
         _lowerCamelCase						:    int         =			torch.tensor([4_8_0, 6_4_0]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''orig_size''']						, __lowerCAmelCase		)		)
         # verify size
         _lowerCamelCase						:    Dict         =			torch.tensor([8_0_0, 1_0_6_6]		)
         self.assertTrue(torch.allclose(encoding['''labels'''][0]['''size''']						, __lowerCAmelCase		)		)







"""simple docstring"""






def 	snake_case_  (				A_ :		int						):


       '''simple docstring'''





       return 1 if digit in (0, 1) else (digit * factorial(digit - 1						))






def 	snake_case_  (				A_ :		int						):


       '''simple docstring'''





       _lowerCamelCase						:    str         =			0
       _lowerCamelCase						:    Any         =			number
       while duplicate > 0:
              _lowerCamelCase      ,   _lowerCamelCase						:    Union[str, Any]         =			divmod(A_,    10						)
              fact_sum += factorial(A_						)
       return fact_sum == number


if __name__ == "__main__":
   print('''Program to check whether a number is a Krisnamurthy Number or not.''')
   lowerCAmelCase__      =    int(input('''Enter number: ''').strip())
   print(
       F"""{number} is {"" if krishnamurthy(number) else "not "}a Krishnamurthy Number."""
   )


