




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_video_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import VideoMAEImageProcessor







class __snake_case     (     unittest.TestCase						):







   def __init__( self						:		List[str]   ,		_snake_case						:		Dict   ,		_snake_case						:		str=7   ,		_snake_case						:		Union[str, Any]=3   ,		_snake_case						:		Tuple=10   ,		_snake_case						:		Optional[Any]=18   ,		_snake_case						:		str=30   ,		_snake_case						:		Any=400   ,		_snake_case						:		Dict=True   ,		_snake_case						:		Optional[int]=None   ,		_snake_case						:		Optional[int]=True   ,		_snake_case						:		Union[str, Any]=[0.5, 0.5, 0.5]   ,		_snake_case						:		int=[0.5, 0.5, 0.5]   ,		_snake_case						:		List[str]=None   ,		):

        """simple docstring"""


        UpperCAmelCase_		=				size if size is not None else {'''shortest_edge''': 18}
        UpperCAmelCase_		=				crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}

        UpperCAmelCase_		=				parent
        UpperCAmelCase_		=				batch_size
        UpperCAmelCase_		=				num_channels
        UpperCAmelCase_		=				num_frames
        UpperCAmelCase_		=				image_size
        UpperCAmelCase_		=				min_resolution
        UpperCAmelCase_		=				max_resolution
        UpperCAmelCase_		=				do_resize
        UpperCAmelCase_		=				size
        UpperCAmelCase_		=				do_normalize
        UpperCAmelCase_		=				image_mean
        UpperCAmelCase_		=				image_std
        UpperCAmelCase_		=				crop_size







   def lowerCamelCase		( self						:		Union[str, Any]):

        """simple docstring"""


        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_size": self.crop_size,
        }







@require_torch
@require_vision
class __snake_case     (     a					,    unittest.TestCase						):
   UpperCAmelCase__    :       str		=    VideoMAEImageProcessor if is_vision_available() else None







   def lowerCamelCase		( self						:		List[str]):

        """simple docstring"""


        UpperCAmelCase_		=				VideoMAEImageProcessingTester(self)







   @property
   def lowerCamelCase		( self						:		str):

        """simple docstring"""


        return self.image_processor_tester.prepare_image_processor_dict()







   def lowerCamelCase		( self						:		Optional[int]):

        """simple docstring"""


        UpperCAmelCase_		=				self.image_processing_class(**self.image_processor_dict)
        self.assertTrue(hasattr(_snake_case   ,		'''image_mean'''))
        self.assertTrue(hasattr(_snake_case   ,		'''image_std'''))
        self.assertTrue(hasattr(_snake_case   ,		'''do_normalize'''))
        self.assertTrue(hasattr(_snake_case   ,		'''do_resize'''))
        self.assertTrue(hasattr(_snake_case   ,		'''do_center_crop'''))
        self.assertTrue(hasattr(_snake_case   ,		'''size'''))







   def lowerCamelCase		( self						:		int):

        """simple docstring"""


        UpperCAmelCase_		=				self.image_processing_class.from_dict(self.image_processor_dict)
        self.assertEqual(image_processor.size   ,		{'''shortest_edge''': 18})
        self.assertEqual(image_processor.crop_size   ,		{'''height''': 18, '''width''': 18})

        UpperCAmelCase_		=				self.image_processing_class.from_dict(self.image_processor_dict   ,		size=42   ,		crop_size=84)
        self.assertEqual(image_processor.size   ,		{'''shortest_edge''': 42})
        self.assertEqual(image_processor.crop_size   ,		{'''height''': 84, '''width''': 84})







   def lowerCamelCase		( self						:		List[str]):

        """simple docstring"""


        pass







   def lowerCamelCase		( self						:		str):

        """simple docstring"""


        UpperCAmelCase_		=				self.image_processing_class(**self.image_processor_dict)
        # create random PIL videos
        UpperCAmelCase_		=				prepare_video_inputs(self.image_processor_tester   ,		equal_resolution=_snake_case)
        for video in video_inputs:
             self.assertIsInstance(_snake_case   ,		_snake_case)
             self.assertIsInstance(video[0]   ,		Image.Image)

        # Test not batched input
        UpperCAmelCase_		=				image_processing(video_inputs[0]   ,		return_tensors='''pt''').pixel_values
        self.assertEqual(
            encoded_videos.shape   ,		(
                1,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['''height'''],
                self.image_processor_tester.crop_size['''width'''],
            )   ,		)

        # Test batched
        UpperCAmelCase_		=				image_processing(_snake_case   ,		return_tensors='''pt''').pixel_values
        self.assertEqual(
            encoded_videos.shape   ,		(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['''height'''],
                self.image_processor_tester.crop_size['''width'''],
            )   ,		)







   def lowerCamelCase		( self						:		Tuple):

        """simple docstring"""


        UpperCAmelCase_		=				self.image_processing_class(**self.image_processor_dict)
        # create random numpy tensors
        UpperCAmelCase_		=				prepare_video_inputs(self.image_processor_tester   ,		equal_resolution=_snake_case   ,		numpify=_snake_case)
        for video in video_inputs:
             self.assertIsInstance(_snake_case   ,		_snake_case)
             self.assertIsInstance(video[0]   ,		np.ndarray)

        # Test not batched input
        UpperCAmelCase_		=				image_processing(video_inputs[0]   ,		return_tensors='''pt''').pixel_values
        self.assertEqual(
            encoded_videos.shape   ,		(
                1,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['''height'''],
                self.image_processor_tester.crop_size['''width'''],
            )   ,		)

        # Test batched
        UpperCAmelCase_		=				image_processing(_snake_case   ,		return_tensors='''pt''').pixel_values
        self.assertEqual(
            encoded_videos.shape   ,		(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_frames,
                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]):

        """simple docstring"""


        UpperCAmelCase_		=				self.image_processing_class(**self.image_processor_dict)
        # create random PyTorch tensors
        UpperCAmelCase_		=				prepare_video_inputs(self.image_processor_tester   ,		equal_resolution=_snake_case   ,		torchify=_snake_case)
        for video in video_inputs:
             self.assertIsInstance(_snake_case   ,		_snake_case)
             self.assertIsInstance(video[0]   ,		torch.Tensor)

        # Test not batched input
        UpperCAmelCase_		=				image_processing(video_inputs[0]   ,		return_tensors='''pt''').pixel_values
        self.assertEqual(
            encoded_videos.shape   ,		(
                1,
                self.image_processor_tester.num_frames,
                self.image_processor_tester.num_channels,
                self.image_processor_tester.crop_size['''height'''],
                self.image_processor_tester.crop_size['''width'''],
            )   ,		)

        # Test batched
        UpperCAmelCase_		=				image_processing(_snake_case   ,		return_tensors='''pt''').pixel_values
        self.assertEqual(
            encoded_videos.shape   ,		(
                self.image_processor_tester.batch_size,
                self.image_processor_tester.num_frames,
                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_levit import LevitImageProcessor


snake_case_					:					Dict       						=			logging.get_logger(__name__)







class __snake_case     (     a						):







   def __init__( self						:		Union[str, Any]   ,		*_snake_case						:		int   ,		**_snake_case						:		List[str]):

        """simple docstring"""


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






