"""simple docstring"""






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 					UpperCAmelCase		(unittest.TestCase						):



    """simple docstring"""

    def __init__(     self					,    _UpperCAmelCase					,    _UpperCAmelCase=7					,    _UpperCAmelCase=3					,    _UpperCAmelCase=18					,    _UpperCAmelCase=30					,    _UpperCAmelCase=400					,    _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					,    ):
       lowercase__:     Optional[int]      =   parent
       lowercase__:     Any      =   batch_size
       lowercase__:     List[str]      =   num_channels
       lowercase__:     Optional[Any]      =   image_size
       lowercase__:     Tuple      =   min_resolution
       lowercase__:     Any      =   max_resolution
       lowercase__:     Dict      =   do_resize
       lowercase__:     Dict      =   size if size is not None else {'''height''': 18, '''width''': 18}
       lowercase__:     Dict      =   do_center_crop
       lowercase__:     Optional[int]      =   crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
       lowercase__:     int      =   do_normalize
       lowercase__:     List[str]      =   image_mean
       lowercase__:     Union[str, Any]      =   image_std
       lowercase__:     Optional[Any]      =   do_convert_rgb






    def _snake_case    (     self							):
       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 					UpperCAmelCase		(__UpperCAmelCase					,unittest.TestCase						):



    """simple docstring"""

    _UpperCAmelCase			:Tuple							=				OwlViTImageProcessor if is_vision_available() else None






    def _snake_case    (     self							):
       lowercase__:     Any      =   OwlViTImageProcessingTester(self							)






    @property
    def _snake_case    (     self							):
       return self.image_processor_tester.prepare_image_processor_dict()






    def _snake_case    (     self							):
       lowercase__:     Optional[int]      =   self.image_processing_class(**self.image_processor_dict							)
       self.assertTrue(hasattr(lowercase_					,    '''do_resize'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''size'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''do_center_crop'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''center_crop'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''do_normalize'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''image_mean'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''image_std'''							)							)
       self.assertTrue(hasattr(lowercase_					,    '''do_convert_rgb'''							)							)






    def _snake_case    (     self							):
       lowercase__:     List[Any]      =   self.image_processing_class.from_dict(self.image_processor_dict							)
       self.assertEqual(image_processor.size					,    {'''height''': 18, '''width''': 18}							)
       self.assertEqual(image_processor.crop_size					,    {'''height''': 18, '''width''': 18}							)

       lowercase__:     str      =   self.image_processing_class.from_dict(self.image_processor_dict					,    size=42					,    crop_size=84							)
       self.assertEqual(image_processor.size					,    {'''height''': 42, '''width''': 42}							)
       self.assertEqual(image_processor.crop_size					,    {'''height''': 84, '''width''': 84}							)






    def _snake_case    (     self							):
       lowercase__:     Tuple      =   self.image_processing_class(**self.image_processor_dict							)
       # create random PIL images
       lowercase__:     Tuple      =   prepare_image_inputs(self.image_processor_tester					,    equal_resolution=lowercase_							)

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

       # Test not batched input
       lowercase__:     Optional[int]      =   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
       lowercase__:     Any      =   image_processing(lowercase_					,    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 _snake_case    (     self							):
       lowercase__:     Optional[int]      =   self.image_processing_class(**self.image_processor_dict							)
       # create random numpy tensors
       lowercase__:     Tuple      =   prepare_image_inputs(self.image_processor_tester					,    equal_resolution=lowercase_					,    numpify=lowercase_							)
       for image in image_inputs:
          self.assertIsInstance(lowercase_					,    np.ndarray							)

       # Test not batched input
       lowercase__:     List[str]      =   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
       lowercase__:     List[Any]      =   image_processing(lowercase_					,    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 _snake_case    (     self							):
       lowercase__:     Optional[Any]      =   self.image_processing_class(**self.image_processor_dict							)
       # create random PyTorch tensors
       lowercase__:     List[Any]      =   prepare_image_inputs(self.image_processor_tester					,    equal_resolution=lowercase_					,    torchify=lowercase_							)
       for image in image_inputs:
          self.assertIsInstance(lowercase_					,    torch.Tensor							)

       # Test not batched input
       lowercase__:     List[str]      =   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
       lowercase__:     Any      =   image_processing(lowercase_					,    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'''],
           )					,    )

"""simple docstring"""






def SCREAMING_SNAKE_CASE__    (     __UpperCAmelCase				)						->						int:
   if not isinstance(__UpperCAmelCase ,					__UpperCAmelCase				):
      lowercase__:     Optional[int]      =   F"""Input value of [number={number}] must be an integer"""
      raise TypeError(__UpperCAmelCase				)
   if number < 1:
      raise ValueError('''Input must be a positive integer'''				)
   return number * (2 * number - 1)


if __name__ == "__main__":
       import doctest

       doctest.testmod()
