


import unittest

import numpy as np

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 OwlViTImageProcessor

class 		lowercase_       (       unittest.TestCase				):

 def __init__(      self     ,	__UpperCamelCase     ,	__UpperCamelCase=7     ,	__UpperCamelCase=3     ,	__UpperCamelCase=1_8     ,	__UpperCamelCase=3_0     ,	__UpperCamelCase=4_0_0     ,	__UpperCamelCase=True     ,	__UpperCamelCase=None     ,	__UpperCamelCase=True     ,	__UpperCamelCase=None     ,	__UpperCamelCase=True     ,	__UpperCamelCase=[0.48_145_466, 0.4_578_275, 0.40_821_073]     ,	__UpperCamelCase=[0.26_862_954, 0.26_130_258, 0.27_577_711]     ,	__UpperCamelCase=True     ,	):




        """simple docstring"""


        UpperCamelCase_							       =       parent
        UpperCamelCase_							       =       batch_size
        UpperCamelCase_							       =       num_channels
        UpperCamelCase_							       =       image_size
        UpperCamelCase_							       =       min_resolution
        UpperCamelCase_							       =       max_resolution
        UpperCamelCase_							       =       do_resize
        UpperCamelCase_							       =       size if size is not None else {"height": 1_8, "width": 1_8}
        UpperCamelCase_							       =       do_center_crop
        UpperCamelCase_							       =       crop_size if crop_size is not None else {"height": 1_8, "width": 1_8}
        UpperCamelCase_							       =       do_normalize
        UpperCamelCase_							       =       image_mean
        UpperCamelCase_							       =       image_std
        UpperCamelCase_							       =       do_convert_rgb

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        return {
            "do_resize": self.do_resize,
            "size": self.size,
            "do_center_crop": self.do_center_crop,
            "crop_size": self.crop_size,
            "do_normalize": self.do_normalize,
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_convert_rgb": self.do_convert_rgb,
        }



@require_torch
@require_vision
class 		lowercase_       (       __SCREAMING_SNAKE_CASE							,	unittest.TestCase				):
 A__						:				int         =    OwlViTImageProcessor if is_vision_available() else None

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        UpperCamelCase_							       =       OwlViTImageProcessingTester(self     )

 @property
 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        return self.image_processor_tester.prepare_image_processor_dict()

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        UpperCamelCase_							       =       self.image_processing_class(**self.image_processor_dict     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""do_resize"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""size"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""do_center_crop"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""center_crop"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""do_normalize"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""image_mean"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""image_std"""     )     )
        self.assertTrue(hasattr(__lowerCamelCase     ,	"""do_convert_rgb"""     )     )

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        UpperCamelCase_							       =       self.image_processing_class.from_dict(self.image_processor_dict     )
        self.assertEqual(image_processor.size     ,	{"""height""": 1_8, """width""": 1_8}     )
        self.assertEqual(image_processor.crop_size     ,	{"""height""": 1_8, """width""": 1_8}     )

        UpperCamelCase_							       =       self.image_processing_class.from_dict(self.image_processor_dict     ,	size=4_2     ,	crop_size=8_4     )
        self.assertEqual(image_processor.size     ,	{"""height""": 4_2, """width""": 4_2}     )
        self.assertEqual(image_processor.crop_size     ,	{"""height""": 8_4, """width""": 8_4}     )

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        UpperCamelCase_							       =       self.image_processing_class(**self.image_processor_dict     )
        # create random PIL images
        UpperCamelCase_							       =       prepare_image_inputs(self.image_processor_tester     ,	equal_resolution=__lowerCamelCase     )

        for image in image_inputs:
               self.assertIsInstance(__lowerCamelCase     ,	Image.Image     )

        # Test not batched input
        UpperCamelCase_							       =       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.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )     ,	)

        # Test batched
        UpperCamelCase_							       =       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.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )     ,	)

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        UpperCamelCase_							       =       self.image_processing_class(**self.image_processor_dict     )
        # create random numpy tensors
        UpperCamelCase_							       =       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
        UpperCamelCase_							       =       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.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )     ,	)

        # Test batched
        UpperCamelCase_							       =       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.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )     ,	)

 def lowerCamelCase_				(      self     ):




        """simple docstring"""


        UpperCamelCase_							       =       self.image_processing_class(**self.image_processor_dict     )
        # create random PyTorch tensors
        UpperCamelCase_							       =       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
        UpperCamelCase_							       =       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.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )     ,	)

        # Test batched
        UpperCamelCase_							       =       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.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            )     ,	)





def 				lowerCamelCase__				(						a__  :  int     )		->	str:
       UpperCamelCase_							       =       1
       UpperCamelCase_							       =       0
       UpperCamelCase_							       =       1
       UpperCamelCase_							       =       1
       UpperCamelCase_							       =       3
       UpperCamelCase_							       =       3
       UpperCamelCase_							       =       limit
       UpperCamelCase_							       =       0

       UpperCamelCase_							       =       """"""
       while counter != decimal + 1:
              if 4 * q + r - t < n * t:
                     result += str(a__     )
                     if counter == 0:
                            result += "."

                     if decimal == counter:
                            break

                     counter += 1
                     UpperCamelCase_							       =       10 * (r - n * t)
                     UpperCamelCase_							       =       ((10 * (3 * q + r)) // t) - 10 * n
                     q *= 10
                     UpperCamelCase_							       =       nr
              else:
                     UpperCamelCase_							       =       (2 * q + r) * l
                     UpperCamelCase_							       =       (q * (7 * k) + 2 + (r * l)) // (t * l)
                     q *= k
                     t *= l
                     l += 2
                     k += 1
                     UpperCamelCase_							       =       nn
                     UpperCamelCase_							       =       nr
       return result




def 				lowerCamelCase__				(						)		->	None:
       print(f'''{calculate_pi(50     ) = }'''     )
       import doctest

       doctest.testmod()


if __name__ == "__main__":
      main()



