

'''simple docstring'''



import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import is_speech_available, is_vision_available
from transformers.testing_utils import require_torch


if is_vision_available():
     from transformers import TvltImageProcessor

if is_speech_available():
     from transformers import TvltFeatureExtractor

from transformers import TvltProcessor



@require_torch
class 				_snake_case					(   unittest.TestCase			):

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							"""ZinengTang/tvlt-base"""
      lowerCAmelCase 						=							tempfile.mkdtemp()

  def   _SCREAMING_SNAKE_CASE				(				self      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      return TvltImageProcessor.from_pretrained(self.checkpoint      , **_A	)

  def   _SCREAMING_SNAKE_CASE				(				self      , **_SCREAMING_SNAKE_CASE	):





      '''simple docstring'''

      return TvltFeatureExtractor.from_pretrained(self.checkpoint      , **_A	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      shutil.rmtree(self.tmpdirname	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.get_image_processor()
      lowerCAmelCase 						=							self.get_feature_extractor()

      lowerCAmelCase 						=							TvltProcessor(image_processor=_A      , feature_extractor=_A	)
      processor.save_pretrained(self.tmpdirname	)
      lowerCAmelCase 						=							TvltProcessor.from_pretrained(self.tmpdirname	)

      self.assertIsInstance(processor.feature_extractor      , _A	)
      self.assertIsInstance(processor.image_processor      , _A	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.get_image_processor()
      lowerCAmelCase 						=							self.get_feature_extractor()

      lowerCAmelCase 						=							TvltProcessor(image_processor=_A      , feature_extractor=_A	)

      lowerCAmelCase 						=							np.ones([1_20_00]	)

      lowerCAmelCase 						=							feature_extractor(_A      , return_tensors='np'	)
      lowerCAmelCase 						=							processor(audio=_A      , return_tensors='np'	)

      for key in audio_dict.keys():
          self.assertAlmostEqual(audio_dict[key].sum()      , input_processor[key].sum()      , delta=1e-2	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.get_image_processor()
      lowerCAmelCase 						=							self.get_feature_extractor()

      lowerCAmelCase 						=							TvltProcessor(image_processor=_A      , feature_extractor=_A	)

      lowerCAmelCase 						=							np.ones([3, 2_24, 2_24]	)

      lowerCAmelCase 						=							image_processor(_A      , return_tensors='np'	)
      lowerCAmelCase 						=							processor(images=_A      , return_tensors='np'	)

      for key in image_dict.keys():
          self.assertAlmostEqual(image_dict[key].sum()      , input_processor[key].sum()      , delta=1e-2	)

  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.get_image_processor()
      lowerCAmelCase 						=							self.get_feature_extractor()

      lowerCAmelCase 						=							TvltProcessor(image_processor=_A      , feature_extractor=_A	)

      lowerCAmelCase 						=							np.ones([1_20_00]	)
      lowerCAmelCase 						=							np.ones([3, 2_24, 2_24]	)

      lowerCAmelCase 						=							processor(audio=_A      , images=_A	)

      self.assertListEqual(list(inputs.keys()	)      , ['audio_values', 'audio_mask', 'pixel_values', 'pixel_mask']	)

      # test if it raises when no input is passed
      with pytest.raises(_A	):
          processor()


  def   _SCREAMING_SNAKE_CASE				(				self	):





      '''simple docstring'''

      lowerCAmelCase 						=							self.get_image_processor()
      lowerCAmelCase 						=							self.get_feature_extractor()

      lowerCAmelCase 						=							TvltProcessor(image_processor=_A      , feature_extractor=_A	)

      self.assertListEqual(
          processor.model_input_names      , image_processor.model_input_names + feature_extractor.model_input_names      , msg='`processor` and `image_processor`+`feature_extractor` model input names do not match'      , )












"""simple docstring"""


from typing import TYPE_CHECKING

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


__magic_name__       :					int						=			{
    """configuration_data2vec_audio""": ["""DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP""", """Data2VecAudioConfig"""],
    """configuration_data2vec_text""": [
        """DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """Data2VecTextConfig""",
        """Data2VecTextOnnxConfig""",
    ],
    """configuration_data2vec_vision""": [
        """DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """Data2VecVisionConfig""",
        """Data2VecVisionOnnxConfig""",
    ],
}

try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__magic_name__       :					List[Any]						=			[
		    """DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """Data2VecAudioForAudioFrameClassification""",
		    """Data2VecAudioForCTC""",
		    """Data2VecAudioForSequenceClassification""",
		    """Data2VecAudioForXVector""",
		    """Data2VecAudioModel""",
		    """Data2VecAudioPreTrainedModel""",
		]
		__magic_name__       :					Optional[int]						=			[
		    """DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """Data2VecTextForCausalLM""",
		    """Data2VecTextForMaskedLM""",
		    """Data2VecTextForMultipleChoice""",
		    """Data2VecTextForQuestionAnswering""",
		    """Data2VecTextForSequenceClassification""",
		    """Data2VecTextForTokenClassification""",
		    """Data2VecTextModel""",
		    """Data2VecTextPreTrainedModel""",
		]
		__magic_name__       :					str						=			[
		    """DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST""",
		    """Data2VecVisionForImageClassification""",
		    """Data2VecVisionForMaskedImageModeling""",
		    """Data2VecVisionForSemanticSegmentation""",
		    """Data2VecVisionModel""",
		    """Data2VecVisionPreTrainedModel""",
		]

if is_tf_available():
		__magic_name__       :					Optional[Any]						=			[
		    """TFData2VecVisionForImageClassification""",
		    """TFData2VecVisionForSemanticSegmentation""",
		    """TFData2VecVisionModel""",
		    """TFData2VecVisionPreTrainedModel""",
		]

if TYPE_CHECKING:
		from .configuration_dataavec_audio import DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP, DataaVecAudioConfig
		from .configuration_dataavec_text import (
		    DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    DataaVecTextConfig,
		    DataaVecTextOnnxConfig,
		)
		from .configuration_dataavec_vision import (
		    DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP,
		    DataaVecVisionConfig,
		    DataaVecVisionOnnxConfig,
		)

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_dataavec_audio import (
				    DATA2VEC_AUDIO_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DataaVecAudioForAudioFrameClassification,
				    DataaVecAudioForCTC,
				    DataaVecAudioForSequenceClassification,
				    DataaVecAudioForXVector,
				    DataaVecAudioModel,
				    DataaVecAudioPreTrainedModel,
				)
				from .modeling_dataavec_text import (
				    DATA2VEC_TEXT_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DataaVecTextForCausalLM,
				    DataaVecTextForMaskedLM,
				    DataaVecTextForMultipleChoice,
				    DataaVecTextForQuestionAnswering,
				    DataaVecTextForSequenceClassification,
				    DataaVecTextForTokenClassification,
				    DataaVecTextModel,
				    DataaVecTextPreTrainedModel,
				)
				from .modeling_dataavec_vision import (
				    DATA2VEC_VISION_PRETRAINED_MODEL_ARCHIVE_LIST,
				    DataaVecVisionForImageClassification,
				    DataaVecVisionForMaskedImageModeling,
				    DataaVecVisionForSemanticSegmentation,
				    DataaVecVisionModel,
				    DataaVecVisionPreTrainedModel,
				)
		if is_tf_available():
				from .modeling_tf_dataavec_vision import (
				    TFDataaVecVisionForImageClassification,
				    TFDataaVecVisionForSemanticSegmentation,
				    TFDataaVecVisionModel,
				    TFDataaVecVisionPreTrainedModel,
				)

else:
		import sys

		__magic_name__       :					Optional[Any]						=			_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)



