



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 MobileNetVaImageProcessor



class 		_lowercase		(							unittest.TestCase						):

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


    """simple docstring"""






    a							=		size if size is not None else {"shortest_edge": 20}
    a							=		crop_size if crop_size is not None else {"height": 18, "width": 18}
    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




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


    """simple docstring"""






    return {
        "do_resize": self.do_resize,
        "size": self.size,
        "do_center_crop": self.do_center_crop,
        "crop_size": self.crop_size,
    }



@require_torch
@require_vision
class 		_lowercase		(							UpperCAmelCase__, unittest.TestCase						):
   _UpperCAmelCase  						=      MobileNetVaImageProcessor if is_vision_available() else None

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


    """simple docstring"""






    a							=		MobileNetVaImageProcessingTester(self				)

   @property
   def 		A				(   self      :							List[str]				)							->					List[str]:


    """simple docstring"""






    return self.image_processor_tester.prepare_image_processor_dict()

   def 		A				(   self      :							Optional[int]				)							->					Union[str, Any]:


    """simple docstring"""






    a							=		self.image_processing_class(**self.image_processor_dict				)
    self.assertTrue(hasattr(__lowerCAmelCase				, "do_resize"				)				)
    self.assertTrue(hasattr(__lowerCAmelCase				, "size"				)				)
    self.assertTrue(hasattr(__lowerCAmelCase				, "do_center_crop"				)				)
    self.assertTrue(hasattr(__lowerCAmelCase				, "center_crop"				)				)

   def 		A				(   self      :							List[str]				)							->					Dict:


    """simple docstring"""






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

    a							=		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 		A				(   self      :							Dict				)							->					Tuple:


    """simple docstring"""






    pass

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


    """simple docstring"""






    a							=		self.image_processing_class(**self.image_processor_dict				)
    # create random PIL images
    a							=		prepare_image_inputs(self.image_processor_tester				, equal_resolution=__lowerCAmelCase				)
    for image in image_inputs:
     self.assertIsInstance(__lowerCAmelCase				, 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(__lowerCAmelCase				, 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 		A				(   self      :							List[Any]				)							->					Dict:


    """simple docstring"""






    a							=		self.image_processing_class(**self.image_processor_dict				)
    # create random numpy tensors
    a							=		prepare_image_inputs(self.image_processor_tester				, equal_resolution=__lowerCAmelCase				, numpify=__lowerCAmelCase				)
    for image in image_inputs:
     self.assertIsInstance(__lowerCAmelCase				, 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(__lowerCAmelCase				, 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 		A				(   self      :							Tuple				)							->					Tuple:


    """simple docstring"""






    a							=		self.image_processing_class(**self.image_processor_dict				)
    # create random PyTorch tensors
    a							=		prepare_image_inputs(self.image_processor_tester				, equal_resolution=__lowerCAmelCase				, torchify=__lowerCAmelCase				)
    for image in image_inputs:
     self.assertIsInstance(__lowerCAmelCase				, 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(__lowerCAmelCase				, 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"],
        )				, )






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


A_		:  Any										=  {
    '''configuration_videomae''': ['''VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''VideoMAEConfig'''],
}

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A_		:  List[Any]										=  [
         '''VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST''',
         '''VideoMAEForPreTraining''',
         '''VideoMAEModel''',
         '''VideoMAEPreTrainedModel''',
         '''VideoMAEForVideoClassification''',
     ]

try:
     if not is_vision_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     A_		:  str										=  ['''VideoMAEFeatureExtractor''']
     A_		:  Union[str, Any]										=  ['''VideoMAEImageProcessor''']

if TYPE_CHECKING:
     from .configuration_videomae import VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP, VideoMAEConfig

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_videomae import (
              VIDEOMAE_PRETRAINED_MODEL_ARCHIVE_LIST,
              VideoMAEForPreTraining,
              VideoMAEForVideoClassification,
              VideoMAEModel,
              VideoMAEPreTrainedModel,
          )

     try:
          if not is_vision_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .feature_extraction_videomae import VideoMAEFeatureExtractor
          from .image_processing_videomae import VideoMAEImageProcessor

else:
     import sys

     A_		:  Dict										=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

