





"""simple docstring"""







from typing import TYPE_CHECKING

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


SCREAMING_SNAKE_CASE_      =					{
    'configuration_deberta_v2': ['DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'DebertaV2Config', 'DebertaV2OnnxConfig'],
    'tokenization_deberta_v2': ['DebertaV2Tokenizer'],
}

try:
  if not is_tokenizers_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE_      =					['DebertaV2TokenizerFast']

try:
  if not is_tf_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE_      =					[
      'TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST',
      'TFDebertaV2ForMaskedLM',
      'TFDebertaV2ForQuestionAnswering',
      'TFDebertaV2ForSequenceClassification',
      'TFDebertaV2ForTokenClassification',
      'TFDebertaV2Model',
      'TFDebertaV2PreTrainedModel',
  ]

try:
  if not is_torch_available():
    raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
  pass
else:
  SCREAMING_SNAKE_CASE_      =					[
      'DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST',
      'DebertaV2ForMaskedLM',
      'DebertaV2ForMultipleChoice',
      'DebertaV2ForQuestionAnswering',
      'DebertaV2ForSequenceClassification',
      'DebertaV2ForTokenClassification',
      'DebertaV2Model',
      'DebertaV2PreTrainedModel',
  ]


if TYPE_CHECKING:
  from .configuration_deberta_va import (
      DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP,
      DebertaVaConfig,
      DebertaVaOnnxConfig,
  )
  from .tokenization_deberta_va import DebertaVaTokenizer

  try:
    if not is_tokenizers_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .tokenization_deberta_va_fast import DebertaVaTokenizerFast

  try:
    if not is_tf_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_tf_deberta_va import (
        TF_DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
        TFDebertaVaForMaskedLM,
        TFDebertaVaForQuestionAnswering,
        TFDebertaVaForSequenceClassification,
        TFDebertaVaForTokenClassification,
        TFDebertaVaModel,
        TFDebertaVaPreTrainedModel,
    )

  try:
    if not is_torch_available():
      raise OptionalDependencyNotAvailable()
  except OptionalDependencyNotAvailable:
    pass
  else:
    from .modeling_deberta_va import (
        DEBERTA_V2_PRETRAINED_MODEL_ARCHIVE_LIST,
        DebertaVaForMaskedLM,
        DebertaVaForMultipleChoice,
        DebertaVaForQuestionAnswering,
        DebertaVaForSequenceClassification,
        DebertaVaForTokenClassification,
        DebertaVaModel,
        DebertaVaPreTrainedModel,
    )

else:
  import sys

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





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







   """simple docstring"""




   def __init__(		self					,				lowerCamelCase_					,				lowerCamelCase_=7					,				lowerCamelCase_=3					,				lowerCamelCase_=1_0					,				lowerCamelCase_=1_8					,				lowerCamelCase_=3_0					,				lowerCamelCase_=4_0_0					,				lowerCamelCase_=True					,				lowerCamelCase_=None					,				lowerCamelCase_=True					,				lowerCamelCase_=[0.5, 0.5, 0.5]					,				lowerCamelCase_=[0.5, 0.5, 0.5]					,				lowerCamelCase_=None					,				)							->      Optional[Any]:
       UpperCamelCase										=  size if size is not None else {'''shortest_edge''': 1_8}
       UpperCamelCase										=  crop_size if crop_size is not None else {'''height''': 1_8, '''width''': 1_8}

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

@require_torch
@require_vision
class 							snake_case_ (				lowerCamelCase_  ,   unittest.TestCase ):







   """simple docstring"""




   A_										=					VideoMAEImageProcessor if is_vision_available() else None







   def      UpperCAmelCase__ (		self)							->      Optional[Any]:
       UpperCamelCase										=  VideoMAEImageProcessingTester(self)







   @property
   def      UpperCAmelCase__ (		self)							->      Optional[int]:
       return self.image_processor_tester.prepare_image_processor_dict()







   def      UpperCAmelCase__ (		self)							->      List[Any]:
       UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
       self.assertTrue(hasattr(lowerCamelCase_					,				'''image_mean'''))
       self.assertTrue(hasattr(lowerCamelCase_					,				'''image_std'''))
       self.assertTrue(hasattr(lowerCamelCase_					,				'''do_normalize'''))
       self.assertTrue(hasattr(lowerCamelCase_					,				'''do_resize'''))
       self.assertTrue(hasattr(lowerCamelCase_					,				'''do_center_crop'''))
       self.assertTrue(hasattr(lowerCamelCase_					,				'''size'''))







   def      UpperCAmelCase__ (		self)							->      Dict:
       UpperCamelCase										=  self.image_processing_class.from_dict(self.image_processor_dict)
       self.assertEqual(image_processor.size					,				{'''shortest_edge''': 1_8})
       self.assertEqual(image_processor.crop_size					,				{'''height''': 1_8, '''width''': 1_8})

       UpperCamelCase										=  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      UpperCAmelCase__ (		self)							->      List[str]:
       pass







   def      UpperCAmelCase__ (		self)							->      Dict:
       # Initialize image_processing
       UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
       # create random PIL videos
       UpperCamelCase										=  prepare_video_inputs(self.image_processor_tester					,				equal_resolution=lowerCamelCase_)
       for video in video_inputs:
           self.assertIsInstance(lowerCamelCase_					,				lowerCamelCase_)
           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(lowerCamelCase_					,				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      UpperCAmelCase__ (		self)							->      Dict:
       # Initialize image_processing
       UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
       # create random numpy tensors
       UpperCamelCase										=  prepare_video_inputs(self.image_processor_tester					,				equal_resolution=lowerCamelCase_					,				numpify=lowerCamelCase_)
       for video in video_inputs:
           self.assertIsInstance(lowerCamelCase_					,				lowerCamelCase_)
           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(lowerCamelCase_					,				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      UpperCAmelCase__ (		self)							->      Optional[int]:
       # Initialize image_processing
       UpperCamelCase										=  self.image_processing_class(**self.image_processor_dict)
       # create random PyTorch tensors
       UpperCamelCase										=  prepare_video_inputs(self.image_processor_tester					,				equal_resolution=lowerCamelCase_					,				torchify=lowerCamelCase_)
       for video in video_inputs:
           self.assertIsInstance(lowerCamelCase_					,				lowerCamelCase_)
           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(lowerCamelCase_					,				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'''],
           )					,				)