


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


     """simple docstring"""






     def __init__(				self     :		int							, snake_case     :		Tuple							, snake_case     :		Optional[Any]=7							, snake_case     :		Any=3							, snake_case     :		Optional[Any]=18							, snake_case     :		str=30							, snake_case     :		Optional[Any]=400							, snake_case     :		List[Any]=True							, snake_case     :		List[Any]=None							, snake_case     :		List[Any]=True							, snake_case     :		int=None							, snake_case     :		Union[str, Any]=True							, snake_case     :		Optional[int]=[0.48_145_466, 0.4_578_275, 0.40_821_073]							, snake_case     :		int=[0.26_862_954, 0.26_130_258, 0.27_577_711]							, snake_case     :		List[Any]=True							, )						->							Any:
          __UpperCAmelCase	: List[str]  							=			parent
          __UpperCAmelCase	: Optional[Any]  							=			batch_size
          __UpperCAmelCase	: str  							=			num_channels
          __UpperCAmelCase	: Union[str, Any]  							=			image_size
          __UpperCAmelCase	: int  							=			min_resolution
          __UpperCAmelCase	: Tuple  							=			max_resolution
          __UpperCAmelCase	: Optional[Any]  							=			do_resize
          __UpperCAmelCase	: int  							=			size if size is not None else {'''height''': 18, '''width''': 18}
          __UpperCAmelCase	: Any  							=			do_center_crop
          __UpperCAmelCase	: Union[str, Any]  							=			crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
          __UpperCAmelCase	: Any  							=			do_normalize
          __UpperCAmelCase	: int  							=			image_mean
          __UpperCAmelCase	: List[str]  							=			image_std
          __UpperCAmelCase	: List[str]  							=			do_convert_rgb






     def  lowerCamelCase__ (				self     :		str			)						->							Union[str, Any]:
          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 	a				(		UpperCamelCase__	,  unittest.TestCase       ):


     """simple docstring"""






     SCREAMING_SNAKE_CASE       : int							   =   OwlViTImageProcessor if is_vision_available() else None

     def  lowerCamelCase__ (				self     :		Union[str, Any]			)						->							Dict:
          __UpperCAmelCase	: str  							=			OwlViTImageProcessingTester(self			)

     @property
     def  lowerCamelCase__ (				self     :		Any			)						->							Union[str, Any]:
          return self.image_processor_tester.prepare_image_processor_dict()

     def  lowerCamelCase__ (				self     :		Optional[Any]			)						->							str:
          __UpperCAmelCase	: int  							=			self.image_processing_class(**self.image_processor_dict			)
          self.assertTrue(hasattr(snake_case							, '''do_resize'''			)			)
          self.assertTrue(hasattr(snake_case							, '''size'''			)			)
          self.assertTrue(hasattr(snake_case							, '''do_center_crop'''			)			)
          self.assertTrue(hasattr(snake_case							, '''center_crop'''			)			)
          self.assertTrue(hasattr(snake_case							, '''do_normalize'''			)			)
          self.assertTrue(hasattr(snake_case							, '''image_mean'''			)			)
          self.assertTrue(hasattr(snake_case							, '''image_std'''			)			)
          self.assertTrue(hasattr(snake_case							, '''do_convert_rgb'''			)			)

     def  lowerCamelCase__ (				self     :		Optional[int]			)						->							List[Any]:
          __UpperCAmelCase	: int  							=			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}			)

          __UpperCAmelCase	: Union[str, 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  lowerCamelCase__ (				self     :		Optional[Any]			)						->							Dict:
          __UpperCAmelCase	: Dict  							=			self.image_processing_class(**self.image_processor_dict			)
          # create random PIL images
          __UpperCAmelCase	: List[str]  							=			prepare_image_inputs(self.image_processor_tester							, equal_resolution=snake_case			)

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

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

          # 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	: Any  							=			image_processing(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  lowerCamelCase__ (				self     :		str			)						->							Tuple:
          __UpperCAmelCase	: List[str]  							=			self.image_processing_class(**self.image_processor_dict			)
          # create random PyTorch tensors
          __UpperCAmelCase	: str  							=			prepare_image_inputs(self.image_processor_tester							, equal_resolution=snake_case							, torchify=snake_case			)
          for image in image_inputs:
               self.assertIsInstance(snake_case							, torch.Tensor			)

          # Test not batched input
          __UpperCAmelCase	: 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
          __UpperCAmelCase	: Tuple  							=			image_processing(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'''],
              )							, )





import warnings

from ...utils import logging
from .image_processing_mobilenet_va import MobileNetVaImageProcessor


lowercase__      :			Union[str, Any]           =					logging.get_logger(__name__)




class 			a__       (					UpperCamelCase__      ):







     def __init__(	self  ,		*A  ,		**A )  ->    None:



          '''simple docstring'''



          warnings.warn(
              "The class MobileNetV2FeatureExtractor is deprecated and will be removed in version 5 of Transformers."
              " Please use MobileNetV2ImageProcessor instead."  ,		A  ,		)
          super().__init__(*A  ,		**A )

