code: 
  
  
  
  
  
  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 				_lowerCamelCase (    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				,						)       ->   str:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				str        =       parent
          __snake_case   :				List[Any]        =       batch_size
          __snake_case   :				List[str]        =       num_channels
          __snake_case   :				Union[str, Any]        =       image_size
          __snake_case   :				Tuple        =       min_resolution
          __snake_case   :				Tuple        =       max_resolution
          __snake_case   :				Tuple        =       do_resize
          __snake_case   :				Dict        =       size if size is not None else {"height": 18, "width": 18}
          __snake_case   :				List[Any]        =       do_center_crop
          __snake_case   :				List[Any]        =       crop_size if crop_size is not None else {"height": 18, "width": 18}
          __snake_case   :				Tuple        =       do_normalize
          __snake_case   :				Optional[Any]        =       image_mean
          __snake_case   :				List[Any]        =       image_std
          __snake_case   :				int        =       do_convert_rgb
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   Optional[Any]:
  
  
  
  
  
  
          '''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 				_lowerCamelCase (    a ,   unittest.TestCase    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        UpperCAmelCase_						:      Tuple       =OwlViTImageProcessor if is_vision_available() else None
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   Dict:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Any        =       OwlViTImageProcessingTester(self   )
  
  
  
  
  
  
  
        @property
        def 						UpperCAmelCase		( self   )       ->   Dict:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return self.image_processor_tester.prepare_image_processor_dict()
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self   )       ->   Any:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Optional[Any]        =       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 						UpperCAmelCase		( self   )       ->   Dict:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Optional[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}   )
  
          __snake_case   :				Any        =       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 						UpperCAmelCase		( self   )       ->   str:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Dict        =       self.image_processing_class(**self.image_processor_dict   )
          # create random PIL images
          __snake_case   :				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
          __snake_case   :				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
          __snake_case   :				int        =       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 						UpperCAmelCase		( self   )       ->   List[str]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				List[str]        =       self.image_processing_class(**self.image_processor_dict   )
          # create random numpy tensors
          __snake_case   :				int        =       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
          __snake_case   :				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
          __snake_case   :				int        =       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 						UpperCAmelCase		( self   )       ->   Tuple:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				List[str]        =       self.image_processing_class(**self.image_processor_dict   )
          # create random PyTorch tensors
          __snake_case   :				Optional[Any]        =       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
          __snake_case   :				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
          __snake_case   :				Dict        =       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"],
              )				,						)
  
  
style_context: 
  
  
  
  
  
  from __future__ import annotations
  
  from collections.abc import Callable
  from typing import Generic, TypeVar
  
  _UpperCamelCase       = TypeVar('''T''')
  _UpperCamelCase       = TypeVar('''U''')
  
  
  
  
  class 				_lowerCamelCase (    Generic[T, U]    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def __init__( self				,						UpperCAmelCase				,						UpperCAmelCase   )       ->   Dict:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Any        =       key
          __snake_case   :				Tuple        =       val
          __snake_case   :				int        =       0
          __snake_case   :				DoubleLinkedListNode[T, U] | None        =       None
          __snake_case   :				DoubleLinkedListNode[T, U] | None        =       None
  
  
  
  
  
  
  
        def __repr__( self   )       ->   str:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return "Node: key: {}, val: {}, freq: {}, has next: {}, has prev: {}".format(
              self.key				,						self.val				,						self.freq				,						self.next is not None				,						self.prev is not None   )
  
  
  
  
  class 				_lowerCamelCase (    Generic[T, U]    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        def __init__( self   )       ->   None:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				DoubleLinkedListNode[T, U]        =       DoubleLinkedListNode(UpperCAmelCase				,						UpperCAmelCase   )
          __snake_case   :				DoubleLinkedListNode[T, U]        =       DoubleLinkedListNode(UpperCAmelCase				,						UpperCAmelCase   )
          __snake_case    ,   __snake_case   :				Any        =       self.rear, self.head
  
  
  
  
  
  
  
        def __repr__( self   )       ->   str:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Union[str, Any]        =       ["DoubleLinkedList"]
          __snake_case   :				List[Any]        =       self.head
          while node.next is not None:
            rep.append(str(UpperCAmelCase   )   )
            __snake_case   :				List[Any]        =       node.next
          rep.append(str(self.rear   )   )
          return ",\n    ".join(UpperCAmelCase   )
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self				,						UpperCAmelCase   )       ->   None:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				Dict        =       self.rear.prev
  
          # All nodes other than self.head are guaranteed to have non-None previous
          assert previous is not None
  
          __snake_case   :				int        =       node
          __snake_case   :				List[str]        =       previous
          __snake_case   :				Optional[int]        =       node
          __snake_case   :				int        =       self.rear
          node.freq += 1
          self._position_node(UpperCAmelCase   )
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self				,						UpperCAmelCase   )       ->   None:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          while node.prev is not None and node.prev.freq > node.freq:
            # swap node with previous node
            __snake_case   :				List[Any]        =       node.prev
  
            __snake_case   :				Dict        =       previous_node.prev
            __snake_case   :				Union[str, Any]        =       node.prev
            __snake_case   :				Union[str, Any]        =       previous_node
            __snake_case   :				int        =       node
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self				,						UpperCAmelCase   )       ->   DoubleLinkedListNode[T, U] | None:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          if node.prev is None or node.next is None:
            return None
  
          __snake_case   :				Optional[int]        =       node.next
          __snake_case   :				Optional[Any]        =       node.prev
          __snake_case   :				Optional[int]        =       None
          __snake_case   :				Any        =       None
          return node
  
  
  
  
  class 				_lowerCamelCase (    Generic[T, U]    ):
  
  
  
        """simple docstring"""
  
  
  
  
  
  
        UpperCAmelCase_						:      dict[Callable[[T], U], LFUCache[T, U]]       ={}
  
  
  
  
  
  
  
        def __init__( self				,						UpperCAmelCase   )       ->   Tuple:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          __snake_case   :				DoubleLinkedList[T, U]        =       DoubleLinkedList()
          __snake_case   :				str        =       capacity
          __snake_case   :				str        =       0
          __snake_case   :				Optional[int]        =       0
          __snake_case   :				Any        =       0
          __snake_case   :				dict[T, DoubleLinkedListNode[T, U]]        =       {}
  
  
  
  
  
  
  
        def __repr__( self   )       ->   str:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return (
              F"""CacheInfo(hits={self.hits}, misses={self.miss}, """
              F"""capacity={self.capacity}, current_size={self.num_keys})"""
          )
  
  
  
  
  
  
  
        def __contains__( self				,						UpperCAmelCase   )       ->   bool:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          return key in self.cache
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self				,						UpperCAmelCase   )       ->   U | None:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          if key in self.cache:
            self.hits += 1
            __snake_case   :				DoubleLinkedListNode[T, U]        =       self.cache[key]
            __snake_case   :				Union[str, Any]        =       self.list.remove(self.cache[key]   )
            assert node == value_node
  
            # node is guaranteed not None because it is in self.cache
            assert node is not None
            self.list.add(UpperCAmelCase   )
            return node.val
          self.miss += 1
          return None
  
  
  
  
  
  
  
        def 						UpperCAmelCase		( self				,						UpperCAmelCase				,						UpperCAmelCase   )       ->   None:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          if key not in self.cache:
            if self.num_keys >= self.capacity:
              # delete first node when over capacity
              __snake_case   :				Optional[Any]        =       self.list.head.next
  
              # guaranteed to have a non-None first node when num_keys > 0
              # explain to type checker via assertions
              assert first_node is not None
              assert first_node.key is not None
              assert self.list.remove(UpperCAmelCase   ) is not None
              # first_node guaranteed to be in list
  
              del self.cache[first_node.key]
              self.num_keys -= 1
            __snake_case   :				Union[str, Any]        =       DoubleLinkedListNode(UpperCAmelCase				,						UpperCAmelCase   )
            self.list.add(self.cache[key]   )
            self.num_keys += 1
  
          else:
            __snake_case   :				Union[str, Any]        =       self.list.remove(self.cache[key]   )
            assert node is not None  # node guaranteed to be in list
            __snake_case   :				Optional[Any]        =       value
            self.list.add(UpperCAmelCase   )
  
  
  
  
  
  
  
        @classmethod
        def 						UpperCAmelCase		( cls				,						UpperCAmelCase = 128   )       ->   Callable[[Callable[[T], U]], Callable[..., U]]:
  
  
  
  
  
  
          '''simple docstring'''
  
  
  
  
  
  
          def cache_decorator_inner(UpperCAmelCase   ) -> Callable[..., U]:
            def cache_decorator_wrapper(*UpperCAmelCase   ) -> U:
              if func not in cls.decorator_function_to_instance_map:
                __snake_case   :				str        =       LFUCache(UpperCAmelCase   )
  
              __snake_case   :				Dict        =       cls.decorator_function_to_instance_map[func].get(args[0]   )
              if result is None:
                __snake_case   :				Optional[int]        =       func(*UpperCAmelCase   )
                cls.decorator_function_to_instance_map[func].put(args[0]				,						UpperCAmelCase   )
              return result
  
            def cache_info() -> LFUCache[T, U]:
              return cls.decorator_function_to_instance_map[func]
  
            setattr(UpperCAmelCase				,						"cache_info"				,						UpperCAmelCase   )  # noqa: B010
  
            return cache_decorator_wrapper
  
          return cache_decorator_inner
  
  
  if __name__ == "__main__":
       import doctest
  
       doctest.testmod()
  
  