




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


if is_torch_available():
   import torch

if is_vision_available():
   from PIL import Image

   from transformers import BlipImageProcessor




class 			a__       (					unittest.TestCase      ):







     def __init__(	self  ,		A  ,		A=7  ,		A=3  ,		A=18  ,		A=30  ,		A=400  ,		A=True  ,		A=None  ,		A=True  ,		A=False  ,		A=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]  ,		A=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]  ,		A=True  ,		)  ->    Tuple:



          '''simple docstring'''



          a      =      size if size is not None else {"height": 20, "width": 20}
          a      =      parent
          a      =      batch_size
          a      =      num_channels
          a      =      image_size
          a      =      min_resolution
          a      =      max_resolution
          a      =      do_resize
          a      =      size
          a      =      do_normalize
          a      =      image_mean
          a      =      image_std
          a      =      do_pad
          a      =      do_convert_rgb







     def 			lowerCAmelCase_				(	self )  ->    Tuple:



          '''simple docstring'''



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







     def 			lowerCAmelCase_				(	self  ,		A=False  ,		A=False  ,		A=False )  ->    Optional[int]:



          '''simple docstring'''



          assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

          if equal_resolution:
               a      =      []
               for i in range(self.batch_size ):
                    image_inputs.append(
                        np.random.randint(
                            255  ,		size=(self.num_channels, self.max_resolution, self.max_resolution)  ,		dtype=np.uinta ) )
          else:
               a      =      []
               for i in range(self.batch_size ):
                    a  ,      a      =      np.random.choice(np.arange(self.min_resolution  ,		self.max_resolution )  ,		2 )
                    image_inputs.append(np.random.randint(255  ,		size=(self.num_channels, width, height)  ,		dtype=np.uinta ) )

          if not numpify and not torchify:
               # PIL expects the channel dimension as last dimension
               a      =      [Image.fromarray(np.moveaxis(A  ,		0  ,		-1 ) ) for x in image_inputs]

          if torchify:
               a      =      [torch.from_numpy(A ) for x in image_inputs]

          return image_inputs







@require_torch
@require_vision
class 			a__       (					UpperCamelCase__   ,					unittest.TestCase      ):
     a		:			Tuple							=	BlipImageProcessor if is_vision_available() else None







     def 			lowerCAmelCase_				(	self )  ->    Optional[int]:



          '''simple docstring'''



          a      =      BlipImageProcessingTester(self )







     @property
     def 			lowerCAmelCase_				(	self )  ->    List[Any]:



          '''simple docstring'''



          return self.image_processor_tester.prepare_image_processor_dict()







     def 			lowerCAmelCase_				(	self )  ->    str:



          '''simple docstring'''



          a      =      self.image_processing_class(**self.image_processor_dict )
          self.assertTrue(hasattr(A  ,		"do_resize" ) )
          self.assertTrue(hasattr(A  ,		"size" ) )
          self.assertTrue(hasattr(A  ,		"do_normalize" ) )
          self.assertTrue(hasattr(A  ,		"image_mean" ) )
          self.assertTrue(hasattr(A  ,		"image_std" ) )
          self.assertTrue(hasattr(A  ,		"do_convert_rgb" ) )







     def 			lowerCAmelCase_				(	self )  ->    str:



          '''simple docstring'''



          pass







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



          '''simple docstring'''



          a      =      self.image_processing_class(**self.image_processor_dict )
          # create random PIL images
          a      =      self.image_processor_tester.prepare_inputs(equal_resolution=A )
          for image in image_inputs:
               self.assertIsInstance(A  ,		Image.Image )

          # Test not batched input
          a      =      image_processor(image_inputs[0]  ,		return_tensors="pt" ).pixel_values
          self.assertEqual(
              encoded_images.shape  ,		(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)

          # Test batched
          a      =      image_processor(A  ,		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.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)







     def 			lowerCAmelCase_				(	self )  ->    int:



          '''simple docstring'''



          a      =      self.image_processing_class(**self.image_processor_dict )
          # create random numpy tensors
          a      =      self.image_processor_tester.prepare_inputs(equal_resolution=A  ,		numpify=A )
          for image in image_inputs:
               self.assertIsInstance(A  ,		np.ndarray )

          # Test not batched input
          a      =      image_processor(image_inputs[0]  ,		return_tensors="pt" ).pixel_values
          self.assertEqual(
              encoded_images.shape  ,		(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)

          # Test batched
          a      =      image_processor(A  ,		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.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)







     def 			lowerCAmelCase_				(	self )  ->    str:



          '''simple docstring'''



          a      =      self.image_processing_class(**self.image_processor_dict )
          # create random PyTorch tensors
          a      =      self.image_processor_tester.prepare_inputs(equal_resolution=A  ,		torchify=A )
          for image in image_inputs:
               self.assertIsInstance(A  ,		torch.Tensor )

          # Test not batched input
          a      =      image_processor(image_inputs[0]  ,		return_tensors="pt" ).pixel_values
          self.assertEqual(
              encoded_images.shape  ,		(
                  1,
                  self.image_processor_tester.num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)

          # Test batched
          a      =      image_processor(A  ,		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.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)







@require_torch
@require_vision
class 			a__       (					UpperCamelCase__   ,					unittest.TestCase      ):
     a		:			Optional[Any]							=	BlipImageProcessor if is_vision_available() else None







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



          '''simple docstring'''



          a      =      BlipImageProcessingTester(self  ,		num_channels=4 )
          a      =      3







     @property
     def 			lowerCAmelCase_				(	self )  ->    str:



          '''simple docstring'''



          return self.image_processor_tester.prepare_image_processor_dict()







     def 			lowerCAmelCase_				(	self )  ->    Any:



          '''simple docstring'''



          a      =      self.image_processing_class(**self.image_processor_dict )
          self.assertTrue(hasattr(A  ,		"do_resize" ) )
          self.assertTrue(hasattr(A  ,		"size" ) )
          self.assertTrue(hasattr(A  ,		"do_normalize" ) )
          self.assertTrue(hasattr(A  ,		"image_mean" ) )
          self.assertTrue(hasattr(A  ,		"image_std" ) )
          self.assertTrue(hasattr(A  ,		"do_convert_rgb" ) )







     def 			lowerCAmelCase_				(	self )  ->    List[str]:



          '''simple docstring'''



          pass







     def 			lowerCAmelCase_				(	self )  ->    List[Any]:



          '''simple docstring'''



          a      =      self.image_processing_class(**self.image_processor_dict )
          # create random PIL images
          a      =      self.image_processor_tester.prepare_inputs(equal_resolution=A )
          for image in image_inputs:
               self.assertIsInstance(A  ,		Image.Image )

          # Test not batched input
          a      =      image_processor(image_inputs[0]  ,		return_tensors="pt" ).pixel_values
          self.assertEqual(
              encoded_images.shape  ,		(
                  1,
                  self.expected_encoded_image_num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.size["width"],
              )  ,		)

          # Test batched
          a      =      image_processor(A  ,		return_tensors="pt" ).pixel_values
          self.assertEqual(
              encoded_images.shape  ,		(
                  self.image_processor_tester.batch_size,
                  self.expected_encoded_image_num_channels,
                  self.image_processor_tester.size["height"],
                  self.image_processor_tester.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 )

