



"""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    lowercase__     (					unittest.TestCase   ):







       '''simple docstring'''


       def   lowercase__       (							self    :						str					)				->		Optional[Any]:


             '''simple docstring'''




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



       def   lowercase__       (							self    :						Any	,       **_UpperCAmelCase    :						Dict					)				->		Tuple:


             '''simple docstring'''




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



       def   lowercase__       (							self    :						Optional[Any]	,       **_UpperCAmelCase    :						Union[str, Any]					)				->		int:


             '''simple docstring'''




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



       def   lowercase__       (							self    :						str					)				->		List[str]:


             '''simple docstring'''




             shutil.rmtree(self.tmpdirname					)



       def   lowercase__       (							self    :						List[str]					)				->		Any:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.get_image_processor()
             UpperCAmelCase_    				=							self.get_feature_extractor()

             UpperCAmelCase_    				=							TvltProcessor(image_processor=_UpperCAmelCase	,       feature_extractor=_UpperCAmelCase					)
             processor.save_pretrained(self.tmpdirname					)
             UpperCAmelCase_    				=							TvltProcessor.from_pretrained(self.tmpdirname					)

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



       def   lowercase__       (							self    :						int					)				->		Tuple:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.get_image_processor()
             UpperCAmelCase_    				=							self.get_feature_extractor()

             UpperCAmelCase_    				=							TvltProcessor(image_processor=_UpperCAmelCase	,       feature_extractor=_UpperCAmelCase					)

             UpperCAmelCase_    				=							np.ones([12000]					)

             UpperCAmelCase_    				=							feature_extractor(_UpperCAmelCase	,       return_tensors="np"					)
             UpperCAmelCase_    				=							processor(audio=_UpperCAmelCase	,       return_tensors="np"					)

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



       def   lowercase__       (							self    :						Dict					)				->		Any:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.get_image_processor()
             UpperCAmelCase_    				=							self.get_feature_extractor()

             UpperCAmelCase_    				=							TvltProcessor(image_processor=_UpperCAmelCase	,       feature_extractor=_UpperCAmelCase					)

             UpperCAmelCase_    				=							np.ones([3, 224, 224]					)

             UpperCAmelCase_    				=							image_processor(_UpperCAmelCase	,       return_tensors="np"					)
             UpperCAmelCase_    				=							processor(images=_UpperCAmelCase	,       return_tensors="np"					)

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



       def   lowercase__       (							self    :						Tuple					)				->		List[Any]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.get_image_processor()
             UpperCAmelCase_    				=							self.get_feature_extractor()

             UpperCAmelCase_    				=							TvltProcessor(image_processor=_UpperCAmelCase	,       feature_extractor=_UpperCAmelCase					)

             UpperCAmelCase_    				=							np.ones([12000]					)
             UpperCAmelCase_    				=							np.ones([3, 224, 224]					)

             UpperCAmelCase_    				=							processor(audio=_UpperCAmelCase	,       images=_UpperCAmelCase					)

             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(_UpperCAmelCase					):
                   processor()







       def   lowercase__       (							self    :						str					)				->		Optional[int]:


             '''simple docstring'''




             UpperCAmelCase_    				=							self.get_image_processor()
             UpperCAmelCase_    				=							self.get_feature_extractor()

             UpperCAmelCase_    				=							TvltProcessor(image_processor=_UpperCAmelCase	,       feature_extractor=_UpperCAmelCase					)

             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 collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


lowerCamelCase      =		logging.get_logger(__name__)

lowerCamelCase      =		{
    """google/mobilenet_v1_1.0_224""": """https://huggingface.co/google/mobilenet_v1_1.0_224/resolve/main/config.json""",
    """google/mobilenet_v1_0.75_192""": """https://huggingface.co/google/mobilenet_v1_0.75_192/resolve/main/config.json""",
    # See all MobileNetV1 models at https://huggingface.co/models?filter=mobilenet_v1
}
class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  '''mobilenet_v1'''



       def __init__(							self    :						Tuple	,       _UpperCAmelCase    :						int=3	,       _UpperCAmelCase    :						Union[str, Any]=224	,       _UpperCAmelCase    :						Any=1.0	,       _UpperCAmelCase    :						Any=8	,       _UpperCAmelCase    :						List[Any]="relu6"	,       _UpperCAmelCase    :						List[str]=True	,       _UpperCAmelCase    :						Dict=0.999	,       _UpperCAmelCase    :						List[Any]=0.02	,       _UpperCAmelCase    :						List[Any]=0.001	,       **_UpperCAmelCase    :						str	,       )				->		Optional[int]:


             '''simple docstring'''




             super().__init__(**_UpperCAmelCase					)

             if depth_multiplier <= 0:
                   raise ValueError("depth_multiplier must be greater than zero."					)

             UpperCAmelCase_    				=							num_channels
             UpperCAmelCase_    				=							image_size
             UpperCAmelCase_    				=							depth_multiplier
             UpperCAmelCase_    				=							min_depth
             UpperCAmelCase_    				=							hidden_act
             UpperCAmelCase_    				=							tf_padding
             UpperCAmelCase_    				=							classifier_dropout_prob
             UpperCAmelCase_    				=							initializer_range
             UpperCAmelCase_    				=							layer_norm_eps



class    lowercase__     (					SCREAMING_SNAKE_CASE   ):







       '''simple docstring'''


       UpperCamelCase		=  version.parse('''1.11'''   )



       @property
       def   lowercase__       (							self    :						List[Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             return OrderedDict([("pixel_values", {0: "batch"})]					)



       @property
       def   lowercase__       (							self    :						List[Any]					)				->		Mapping[str, Mapping[int, str]]:


             '''simple docstring'''




             if self.task == "image-classification":
                   return OrderedDict([("logits", {0: "batch"})]					)
             else:
                   return OrderedDict([("last_hidden_state", {0: "batch"}), ("pooler_output", {0: "batch"})]					)







       @property
       def   lowercase__       (							self    :						Tuple					)				->		float:


             '''simple docstring'''




             return 1e-4




