




"""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 ConvNextImageProcessor

class    __lowercase							(      unittest.TestCase						):


				'''simple docstring'''


				def __init__( self :  Optional[int]   ,SCREAMING_SNAKE_CASE_ :  Union[str, Any]   ,SCREAMING_SNAKE_CASE_ :  Any=7   ,SCREAMING_SNAKE_CASE_ :  Any=3   ,SCREAMING_SNAKE_CASE_ :  List[Any]=1_8   ,SCREAMING_SNAKE_CASE_ :  Optional[Any]=3_0   ,SCREAMING_SNAKE_CASE_ :  int=4_0_0   ,SCREAMING_SNAKE_CASE_ :  Dict=True   ,SCREAMING_SNAKE_CASE_ :  Any=None   ,SCREAMING_SNAKE_CASE_ :  Union[str, Any]=0.875   ,SCREAMING_SNAKE_CASE_ :  Optional[int]=True   ,SCREAMING_SNAKE_CASE_ :  int=[0.5, 0.5, 0.5]   ,SCREAMING_SNAKE_CASE_ :  Union[str, Any]=[0.5, 0.5, 0.5]   ,):
										snake_case__							:       int				      =       size if size is not None else {'''shortest_edge''': 2_0}
										snake_case__							:       Union[str, Any]				      =       parent
										snake_case__							:       str				      =       batch_size
										snake_case__							:       str				      =       num_channels
										snake_case__							:       Optional[int]				      =       image_size
										snake_case__							:       List[Any]				      =       min_resolution
										snake_case__							:       Tuple				      =       max_resolution
										snake_case__							:       str				      =       do_resize
										snake_case__							:       Dict				      =       size
										snake_case__							:       Any				      =       crop_pct
										snake_case__							:       Union[str, Any]				      =       do_normalize
										snake_case__							:       str				      =       image_mean
										snake_case__							:       Any				      =       image_std





				def    _lowerCamelCase       ( self :  Tuple   ):
										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "crop_pct": self.crop_pct,
										}







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


				'''simple docstring'''


				_lowerCAmelCase						      =ConvNextImageProcessor if is_vision_available() else None

				def    _lowerCamelCase       ( self :  int   ):
										snake_case__							:       List[Any]				      =       ConvNextImageProcessingTester(self   )

				@property
				def    _lowerCamelCase       ( self :  Optional[Any]   ):
										return self.image_processor_tester.prepare_image_processor_dict()

				def    _lowerCamelCase       ( self :  Any   ):
										snake_case__							:       Union[str, Any]				      =       self.image_processing_class(**self.image_processor_dict   )
										self.assertTrue(hasattr(lowercase_   ,'''do_resize'''   )   )
										self.assertTrue(hasattr(lowercase_   ,'''size'''   )   )
										self.assertTrue(hasattr(lowercase_   ,'''crop_pct'''   )   )
										self.assertTrue(hasattr(lowercase_   ,'''do_normalize'''   )   )
										self.assertTrue(hasattr(lowercase_   ,'''image_mean'''   )   )
										self.assertTrue(hasattr(lowercase_   ,'''image_std'''   )   )

				def    _lowerCamelCase       ( self :  Optional[int]   ):
										snake_case__							:       Optional[int]				      =       self.image_processing_class.from_dict(self.image_processor_dict   )
										self.assertEqual(image_processor.size   ,{'''shortest_edge''': 2_0}   )

										snake_case__							:       Any				      =       self.image_processing_class.from_dict(self.image_processor_dict   ,size=4_2   )
										self.assertEqual(image_processor.size   ,{'''shortest_edge''': 4_2}   )

				def    _lowerCamelCase       ( self :  List[Any]   ):
										pass

				def    _lowerCamelCase       ( self :  int   ):
										snake_case__							:       Tuple				      =       self.image_processing_class(**self.image_processor_dict   )
										# create random PIL images
										snake_case__							:       Any				      =       prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase_   )
										for image in image_inputs:
																self.assertIsInstance(lowercase_   ,Image.Image   )

										# Test not batched input
										snake_case__							:       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.size['''shortest_edge'''],
										        self.image_processor_tester.size['''shortest_edge'''],
										    )   ,)

										# Test batched
										snake_case__							:       Optional[Any]				      =       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.size['''shortest_edge'''],
										        self.image_processor_tester.size['''shortest_edge'''],
										    )   ,)

				def    _lowerCamelCase       ( self :  List[Any]   ):
										snake_case__							:       Union[str, Any]				      =       self.image_processing_class(**self.image_processor_dict   )
										# create random numpy tensors
										snake_case__							:       List[Any]				      =       prepare_image_inputs(self.image_processor_tester   ,equal_resolution=lowercase_   ,numpify=lowercase_   )
										for image in image_inputs:
																self.assertIsInstance(lowercase_   ,np.ndarray   )

										# Test not batched input
										snake_case__							:       str				      =       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.size['''shortest_edge'''],
										        self.image_processor_tester.size['''shortest_edge'''],
										    )   ,)

										# Test batched
										snake_case__							:       str				      =       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.size['''shortest_edge'''],
										        self.image_processor_tester.size['''shortest_edge'''],
										    )   ,)





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

										# 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.size['''shortest_edge'''],
										        self.image_processor_tester.size['''shortest_edge'''],
										    )   ,)

										# Test batched
										snake_case__							:       Optional[int]				      =       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.size['''shortest_edge'''],
										        self.image_processor_tester.size['''shortest_edge'''],
										    )   ,)





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_						)

