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




  def __init__(     self				:Union[str, Any] ,						_SCREAMING_SNAKE_CASE				:List[Any] ,						_SCREAMING_SNAKE_CASE				:Optional[Any]=7 ,						_SCREAMING_SNAKE_CASE				:str=3 ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=1_8 ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=3_0 ,						_SCREAMING_SNAKE_CASE				:Dict=4_0_0 ,						_SCREAMING_SNAKE_CASE				:Any=True ,						_SCREAMING_SNAKE_CASE				:Optional[int]=None ,						_SCREAMING_SNAKE_CASE				:Union[str, Any]=True ,						_SCREAMING_SNAKE_CASE				:Tuple=None ,						_SCREAMING_SNAKE_CASE				:List[str]=True ,						_SCREAMING_SNAKE_CASE				:Optional[Any]=[0.48145466, 0.4578275, 0.40821073] ,						_SCREAMING_SNAKE_CASE				:Any=[0.26862954, 0.26130258, 0.27577711] ,						_SCREAMING_SNAKE_CASE				:int=True ,						)				-> int:






        '''simple docstring'''






        UpperCamelCase_    :  Dict				    =    parent
        UpperCamelCase_    :  str				    =    batch_size
        UpperCamelCase_    :  Optional[Any]				    =    num_channels
        UpperCamelCase_    :  List[Any]				    =    image_size
        UpperCamelCase_    :  Tuple				    =    min_resolution
        UpperCamelCase_    :  str				    =    max_resolution
        UpperCamelCase_    :  List[Any]				    =    do_resize
        UpperCamelCase_    :  int				    =    size if size is not None else {"""height""": 1_8, """width""": 1_8}
        UpperCamelCase_    :  List[str]				    =    do_center_crop
        UpperCamelCase_    :  List[Any]				    =    crop_size if crop_size is not None else {"""height""": 1_8, """width""": 1_8}
        UpperCamelCase_    :  Union[str, Any]				    =    do_normalize
        UpperCamelCase_    :  Optional[Any]				    =    image_mean
        UpperCamelCase_    :  str				    =    image_std
        UpperCamelCase_    :  Optional[Any]				    =    do_convert_rgb





  def   _snake_case  (     self				:Tuple)				-> List[str]:






        '''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 						__snake_case (						_a				, unittest.TestCase  ):
  a_        =				OwlViTImageProcessor if is_vision_available() else None




  def   _snake_case  (     self				:Optional[Any])				-> Any:






        '''simple docstring'''






        UpperCamelCase_    :  Optional[int]				    =    OwlViTImageProcessingTester(self)




  @property
  def   _snake_case  (     self				:Dict)				-> str:






        '''simple docstring'''






        return self.image_processor_tester.prepare_image_processor_dict()




  def   _snake_case  (     self				:List[Any])				-> Tuple:






        '''simple docstring'''






        UpperCamelCase_    :  List[Any]				    =    self.image_processing_class(**self.image_processor_dict)
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""do_resize"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""size"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""do_center_crop"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""center_crop"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""do_normalize"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""image_mean"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""image_std"""))
        self.assertTrue(hasattr(_SCREAMING_SNAKE_CASE ,						"""do_convert_rgb"""))




  def   _snake_case  (     self				:Any)				-> int:






        '''simple docstring'''






        UpperCamelCase_    :  Dict				    =    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_    :  int				    =    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   _snake_case  (     self				:List[str])				-> List[Any]:






        '''simple docstring'''






        UpperCamelCase_    :  Tuple				    =    self.image_processing_class(**self.image_processor_dict)
        # create random PIL images
        UpperCamelCase_    :  Optional[int]				    =    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
        UpperCamelCase_    :  Dict				    =    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_    :  Optional[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,
                self.image_processor_tester.crop_size["""height"""],
                self.image_processor_tester.crop_size["""width"""],
            ) ,						)




  def   _snake_case  (     self				:Dict)				-> List[str]:






        '''simple docstring'''






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





  def   _snake_case  (     self				:Union[str, Any])				-> Union[str, Any]:






        '''simple docstring'''






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






'''simple docstring'''


import warnings

from .generation import GenerationMixin




class 						__snake_case (						_a  ):
		# warning at import time
		warnings.warn(
		    "Importing `GenerationMixin` from `src/transformers/generation_utils.py` is deprecated and will "
		    "be removed in Transformers v5. Import as `from transformers import GenerationMixin` instead."				, _a				, )




