

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 CLIPImageProcessor


class 					A		(				unittest.TestCase					):







    """simple docstring"""





    def __init__( self					:			List[Any],lowercase_					:			int,lowercase_					:			Union[str, Any]=7,lowercase_					:			Dict=3,lowercase_					:			int=1_8,lowercase_					:			Optional[Any]=3_0,lowercase_					:			Dict=4_0_0,lowercase_					:			Optional[Any]=True,lowercase_					:			str=None,lowercase_					:			List[str]=True,lowercase_					:			Tuple=None,lowercase_					:			List[str]=True,lowercase_					:			Optional[Any]=[0.48_145_466, 0.4_578_275, 0.40_821_073],lowercase_					:			Any=[0.26_862_954, 0.26_130_258, 0.27_577_711],lowercase_					:			Optional[int]=True,)->       Tuple:





        '''simple docstring'''







        A__        =  size if size is not None else {'shortest_edge': 2_0}
        A__        =  crop_size if crop_size is not None else {'height': 1_8, 'width': 1_8}
        A__        =  parent
        A__        =  batch_size
        A__        =  num_channels
        A__        =  image_size
        A__        =  min_resolution
        A__        =  max_resolution
        A__        =  do_resize
        A__        =  size
        A__        =  do_center_crop
        A__        =  crop_size
        A__        =  do_normalize
        A__        =  image_mean
        A__        =  image_std
        A__        =  do_convert_rgb


    def 		snake_case__	( self					:			str						)->       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,
        }


    def 		snake_case__	( self					:			Tuple,lowercase_					:			Optional[Any]=False,lowercase_					:			Tuple=False,lowercase_					:			Dict=False						)->       Dict:





        '''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(
                        2_5_5,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(2_5_5,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(lowercase_,0,-1						)						) for x in image_inputs]

        if torchify:
            A__        =  [torch.from_numpy(lowercase_						) for x in image_inputs]

        return image_inputs




@require_torch
@require_vision
class 					A		(				_UpperCAmelCase       ,				unittest.TestCase					):







    """simple docstring"""





    lowerCamelCase						      =				CLIPImageProcessor if is_vision_available() else None


    def 		snake_case__	( self					:			Any						)->       List[str]:





        '''simple docstring'''







        A__        =  CLIPImageProcessingTester(self						)


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





        '''simple docstring'''







        return self.image_processor_tester.prepare_image_processor_dict()


    def 		snake_case__	( self					:			int						)->       Optional[Any]:





        '''simple docstring'''







        A__        =  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					:			Dict						)->       Dict:





        '''simple docstring'''







        A__        =  self.image_processing_class.from_dict(self.image_processor_dict						)
        self.assertEqual(image_processor.size,{'shortest_edge': 2_0}						)
        self.assertEqual(image_processor.crop_size,{'height': 1_8, 'width': 1_8}						)

        A__        =  self.image_processing_class.from_dict(self.image_processor_dict,size=4_2,crop_size=8_4						)
        self.assertEqual(image_processor.size,{'shortest_edge': 4_2}						)
        self.assertEqual(image_processor.crop_size,{'height': 8_4, 'width': 8_4}						)


    def 		snake_case__	( self					:			Any						)->       Any:





        '''simple docstring'''







        pass


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





        '''simple docstring'''







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

        # Test not batched input
        A__        =  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
        A__        =  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					:			Optional[Any]						)->       str:





        '''simple docstring'''







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

        # Test not batched input
        A__        =  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
        A__        =  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					:			Dict						)->       Dict:





        '''simple docstring'''







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

        # Test not batched input
        A__        =  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
        A__        =  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'],
            ),)




@require_torch
@require_vision
class 					A		(				_UpperCAmelCase       ,				unittest.TestCase					):







    """simple docstring"""





    lowerCamelCase						      =				CLIPImageProcessor if is_vision_available() else None


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





        '''simple docstring'''







        A__        =  CLIPImageProcessingTester(self,num_channels=4						)
        A__        =  3


    @property
    def 		snake_case__	( self					:			Union[str, Any]						)->       Union[str, Any]:





        '''simple docstring'''







        return self.image_processor_tester.prepare_image_processor_dict()


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





        '''simple docstring'''







        A__        =  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					:			Optional[int]						)->       Optional[int]:





        '''simple docstring'''







        pass


    def 		snake_case__	( self					:			Dict						)->       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=lowercase_						)
        for image in image_inputs:
            self.assertIsInstance(lowercase_,Image.Image						)

        # Test not batched input
        A__        =  image_processing(image_inputs[0],return_tensors='pt'						).pixel_values
        self.assertEqual(
            encoded_images.shape,(
                1,
                self.expected_encoded_image_num_channels,
                self.image_processor_tester.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            ),)

        # Test batched
        A__        =  image_processing(lowercase_,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.crop_size['height'],
                self.image_processor_tester.crop_size['width'],
            ),)




import warnings

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


lowercase_									=    logging.get_logger(__name__)


class 					A		(				_UpperCAmelCase					):







    """simple docstring"""





    def __init__( self					:			str,*lowercase_					:			List[Any],**lowercase_					:			Dict						)->       None:





        '''simple docstring'''







        warnings.warn(
            'The class MobileNetV1FeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
            ' Please use MobileNetV1ImageProcessor instead.',lowercase_,)
        super().__init__(*lowercase_,**lowercase_						)

