





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 VivitImageProcessor

class    lowerCAmelCase							(					unittest.TestCase			):
 def __init__(      self  :      List[Any]			,     UpperCAmelCase  :      int			,     UpperCAmelCase  :      Any=7			,     UpperCAmelCase  :      Dict=3			,     UpperCAmelCase  :      Optional[int]=10			,     UpperCAmelCase  :      List[Any]=18			,     UpperCAmelCase  :      Dict=30			,     UpperCAmelCase  :      List[str]=400			,     UpperCAmelCase  :      Optional[int]=True			,     UpperCAmelCase  :      str=None			,     UpperCAmelCase  :      List[Any]=True			,     UpperCAmelCase  :      List[str]=[0.5, 0.5, 0.5]			,     UpperCAmelCase  :      Optional[int]=[0.5, 0.5, 0.5]			,     UpperCAmelCase  :      List[str]=None			,     )			->	Any:
     lowerCamelCase__    :      Any					 =		size if size is not None else {'shortest_edge': 18}
     lowerCamelCase__    :      List[Any]					 =		crop_size if crop_size is not None else {'height': 18, 'width': 18}

     lowerCamelCase__    :      Tuple					 =		parent
     lowerCamelCase__    :      List[Any]					 =		batch_size
     lowerCamelCase__    :      Dict					 =		num_channels
     lowerCamelCase__    :      Union[str, Any]					 =		num_frames
     lowerCamelCase__    :      Any					 =		image_size
     lowerCamelCase__    :      int					 =		min_resolution
     lowerCamelCase__    :      Tuple					 =		max_resolution
     lowerCamelCase__    :      List[str]					 =		do_resize
     lowerCamelCase__    :      List[str]					 =		size
     lowerCamelCase__    :      Union[str, Any]					 =		do_normalize
     lowerCamelCase__    :      List[str]					 =		image_mean
     lowerCamelCase__    :      Tuple					 =		image_std
     lowerCamelCase__    :      Tuple					 =		crop_size







 def      A_	(      self  :      Tuple	)			->	List[Any]:
     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    lowerCAmelCase							(					__UpperCamelCase,  unittest.TestCase			):
 UpperCAmelCase__													=		VivitImageProcessor if is_vision_available() else None
 def      A_	(      self  :      Optional[Any]	)			->	Union[str, Any]:
     lowerCamelCase__    :      Optional[int]					 =		VivitImageProcessingTester(self	)
 @property
 def      A_	(      self  :      int	)			->	Union[str, Any]:
     return self.image_processor_tester.prepare_image_processor_dict()
 def      A_	(      self  :      Dict	)			->	Any:
     lowerCamelCase__    :      Optional[int]					 =		self.image_processing_class(**self.image_processor_dict	)
     self.assertTrue(hasattr(UpperCAmelCase			,     'image_mean'	)	)
     self.assertTrue(hasattr(UpperCAmelCase			,     'image_std'	)	)
     self.assertTrue(hasattr(UpperCAmelCase			,     'do_normalize'	)	)
     self.assertTrue(hasattr(UpperCAmelCase			,     'do_resize'	)	)
     self.assertTrue(hasattr(UpperCAmelCase			,     'do_center_crop'	)	)
     self.assertTrue(hasattr(UpperCAmelCase			,     'size'	)	)
 def      A_	(      self  :      Dict	)			->	Optional[Any]:
     lowerCamelCase__    :      Optional[int]					 =		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}	)

     lowerCamelCase__    :      Union[str, Any]					 =		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  :      List[Any]	)			->	Optional[int]:
     # Initialize image_processing
     lowerCamelCase__    :      Tuple					 =		self.image_processing_class(**self.image_processor_dict	)
     # create random PIL videos
     lowerCamelCase__    :      List[Any]					 =		prepare_video_inputs(self.image_processor_tester			,     equal_resolution=UpperCAmelCase	)
     for video in video_inputs:
         self.assertIsInstance(UpperCAmelCase			,     UpperCAmelCase	)
         self.assertIsInstance(video[0]			,     Image.Image	)

     # Test not batched input
     lowerCamelCase__    :      str					 =		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
     lowerCamelCase__    :      Optional[int]					 =		image_processing(UpperCAmelCase			,     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      A_	(      self  :      int	)			->	Union[str, Any]:
     # Initialize image_processing
     lowerCamelCase__    :      List[Any]					 =		self.image_processing_class(**self.image_processor_dict	)
     # create random numpy tensors
     lowerCamelCase__    :      List[str]					 =		prepare_video_inputs(self.image_processor_tester			,     equal_resolution=UpperCAmelCase			,     numpify=UpperCAmelCase	)
     for video in video_inputs:
         self.assertIsInstance(UpperCAmelCase			,     UpperCAmelCase	)
         self.assertIsInstance(video[0]			,     np.ndarray	)

     # Test not batched input
     lowerCamelCase__    :      Any					 =		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
     lowerCamelCase__    :      Tuple					 =		image_processing(UpperCAmelCase			,     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      A_	(      self  :      Dict	)			->	Optional[int]:
     # Initialize image_processing
     lowerCamelCase__    :      Optional[Any]					 =		self.image_processing_class(**self.image_processor_dict	)
     # create random PyTorch tensors
     lowerCamelCase__    :      Union[str, Any]					 =		prepare_video_inputs(self.image_processor_tester			,     equal_resolution=UpperCAmelCase			,     torchify=UpperCAmelCase	)
     for video in video_inputs:
         self.assertIsInstance(UpperCAmelCase			,     UpperCAmelCase	)
         self.assertIsInstance(video[0]			,     torch.Tensor	)

     # Test not batched input
     lowerCamelCase__    :      Union[str, Any]					 =		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
     lowerCamelCase__    :      Tuple					 =		image_processing(UpperCAmelCase			,     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'],
         )			,     )













"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tokenizers_available,
    is_torch_available,
    is_vision_available,
)


_snake_case          =   {
    'configuration_perceiver': ['PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP', 'PerceiverConfig', 'PerceiverOnnxConfig'],
    'tokenization_perceiver': ['PerceiverTokenizer'],
}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case          =   ['PerceiverFeatureExtractor']
 _snake_case          =   ['PerceiverImageProcessor']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case          =   [
     'PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST',
     'PerceiverForImageClassificationConvProcessing',
     'PerceiverForImageClassificationFourier',
     'PerceiverForImageClassificationLearned',
     'PerceiverForMaskedLM',
     'PerceiverForMultimodalAutoencoding',
     'PerceiverForOpticalFlow',
     'PerceiverForSequenceClassification',
     'PerceiverLayer',
     'PerceiverModel',
     'PerceiverPreTrainedModel',
 ]


if TYPE_CHECKING:
 from .configuration_perceiver import PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP, PerceiverConfig, PerceiverOnnxConfig
 from .tokenization_perceiver import PerceiverTokenizer

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .feature_extraction_perceiver import PerceiverFeatureExtractor
  from .image_processing_perceiver import PerceiverImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_perceiver import (
      PERCEIVER_PRETRAINED_MODEL_ARCHIVE_LIST,
      PerceiverForImageClassificationConvProcessing,
      PerceiverForImageClassificationFourier,
      PerceiverForImageClassificationLearned,
      PerceiverForMaskedLM,
      PerceiverForMultimodalAutoencoding,
      PerceiverForOpticalFlow,
      PerceiverForSequenceClassification,
      PerceiverLayer,
      PerceiverModel,
      PerceiverPreTrainedModel,
  )

else:
 import sys

 _snake_case          =   _LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

