




from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ...utils.backbone_utils import BackboneConfigMixin, get_aligned_output_features_output_indices


UpperCamelCase								=	logging.get_logger(__name__)

UpperCamelCase								=	{
    'microsoft/focalnet-tiny': 'https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json',
}





class 					__lowerCamelCase			(       UpperCamelCase__      ,							UpperCamelCase__       ):




    """simple docstring"""

    snake_case__   = "focalnet"


    def __init__(			self	:	Optional[int]  ,      SCREAMING_SNAKE_CASE__	:	str=224  ,      SCREAMING_SNAKE_CASE__	:	str=4  ,      SCREAMING_SNAKE_CASE__	:	Optional[int]=3  ,      SCREAMING_SNAKE_CASE__	:	List[Any]=96  ,      SCREAMING_SNAKE_CASE__	:	Tuple=False  ,      SCREAMING_SNAKE_CASE__	:	Tuple=[192, 384, 768, 768]  ,      SCREAMING_SNAKE_CASE__	:	Dict=[2, 2, 6, 2]  ,      SCREAMING_SNAKE_CASE__	:	Optional[int]=[2, 2, 2, 2]  ,      SCREAMING_SNAKE_CASE__	:	Optional[int]=[3, 3, 3, 3]  ,      SCREAMING_SNAKE_CASE__	:	List[str]="gelu"  ,      SCREAMING_SNAKE_CASE__	:	List[Any]=4.0  ,      SCREAMING_SNAKE_CASE__	:	Any=0.0  ,      SCREAMING_SNAKE_CASE__	:	str=0.1  ,      SCREAMING_SNAKE_CASE__	:	int=False  ,      SCREAMING_SNAKE_CASE__	:	Optional[int]=1e-4  ,      SCREAMING_SNAKE_CASE__	:	Tuple=False  ,      SCREAMING_SNAKE_CASE__	:	List[str]=False  ,      SCREAMING_SNAKE_CASE__	:	List[Any]=False  ,      SCREAMING_SNAKE_CASE__	:	Dict=0.02  ,      SCREAMING_SNAKE_CASE__	:	Any=1e-5  ,      SCREAMING_SNAKE_CASE__	:	Any=32  ,      SCREAMING_SNAKE_CASE__	:	Dict=None  ,      SCREAMING_SNAKE_CASE__	:	Any=None  ,      **SCREAMING_SNAKE_CASE__	:	List[str]  ,      ) ->			str:
         super().__init__(**SCREAMING_SNAKE_CASE__  )

         lowerCAmelCase__            =					image_size
         lowerCAmelCase__            =					patch_size
         lowerCAmelCase__            =					num_channels
         lowerCAmelCase__            =					embed_dim
         lowerCAmelCase__            =					use_conv_embed
         lowerCAmelCase__            =					hidden_sizes
         lowerCAmelCase__            =					depths
         lowerCAmelCase__            =					focal_levels
         lowerCAmelCase__            =					focal_windows
         lowerCAmelCase__            =					hidden_act
         lowerCAmelCase__            =					mlp_ratio
         lowerCAmelCase__            =					hidden_dropout_prob
         lowerCAmelCase__            =					drop_path_rate
         lowerCAmelCase__            =					use_layerscale
         lowerCAmelCase__            =					layerscale_value
         lowerCAmelCase__            =					use_post_layernorm
         lowerCAmelCase__            =					use_post_layernorm_in_modulation
         lowerCAmelCase__            =					normalize_modulator
         lowerCAmelCase__            =					initializer_range
         lowerCAmelCase__            =					layer_norm_eps
         lowerCAmelCase__            =					encoder_stride
         lowerCAmelCase__            =					["stem"] + [f'stage{idx}' for idx in range(1  ,      len(self.depths  ) + 1  )]
         lowerCAmelCase__      ,						lowerCAmelCase__            =					get_aligned_output_features_output_indices(
             out_features=SCREAMING_SNAKE_CASE__  ,      out_indices=SCREAMING_SNAKE_CASE__  ,      stage_names=self.stage_names  )


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





     """simple docstring"""







     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Union[str, Any]:




           """simple docstring"""







           UpperCamelCase__     : int											=					'''ZinengTang/tvlt-base'''
           UpperCamelCase__     : Optional[Any]											=					tempfile.mkdtemp()






     def  __SCREAMING_SNAKE_CASE      (				self    ,    **__SCREAMING_SNAKE_CASE	)	-> Tuple:




           """simple docstring"""







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






     def  __SCREAMING_SNAKE_CASE      (				self    ,    **__SCREAMING_SNAKE_CASE	)	-> str:




           """simple docstring"""







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






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




           """simple docstring"""







           shutil.rmtree(self.tmpdirname	)






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> Any:




           """simple docstring"""







           UpperCamelCase__     : Optional[Any]											=					self.get_image_processor()
           UpperCamelCase__     : Tuple											=					self.get_feature_extractor()

           UpperCamelCase__     : Dict											=					TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE    ,    feature_extractor=__SCREAMING_SNAKE_CASE	)
           processor.save_pretrained(self.tmpdirname	)
           UpperCamelCase__     : Optional[Any]											=					TvltProcessor.from_pretrained(self.tmpdirname	)

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






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




           """simple docstring"""







           UpperCamelCase__     : Union[str, Any]											=					self.get_image_processor()
           UpperCamelCase__     : int											=					self.get_feature_extractor()

           UpperCamelCase__     : Union[str, Any]											=					TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE    ,    feature_extractor=__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : str											=					np.ones([1_2_0_0_0]	)

           UpperCamelCase__     : Dict											=					feature_extractor(__SCREAMING_SNAKE_CASE    ,    return_tensors='''np'''	)
           UpperCamelCase__     : Dict											=					processor(audio=__SCREAMING_SNAKE_CASE    ,    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	)	-> Optional[int]:




           """simple docstring"""







           UpperCamelCase__     : Tuple											=					self.get_image_processor()
           UpperCamelCase__     : Tuple											=					self.get_feature_extractor()

           UpperCamelCase__     : str											=					TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE    ,    feature_extractor=__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : List[Any]											=					np.ones([3, 2_2_4, 2_2_4]	)

           UpperCamelCase__     : Optional[int]											=					image_processor(__SCREAMING_SNAKE_CASE    ,    return_tensors='''np'''	)
           UpperCamelCase__     : Tuple											=					processor(images=__SCREAMING_SNAKE_CASE    ,    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	)	-> str:




           """simple docstring"""







           UpperCamelCase__     : List[str]											=					self.get_image_processor()
           UpperCamelCase__     : Optional[Any]											=					self.get_feature_extractor()

           UpperCamelCase__     : Union[str, Any]											=					TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE    ,    feature_extractor=__SCREAMING_SNAKE_CASE	)

           UpperCamelCase__     : Dict											=					np.ones([1_2_0_0_0]	)
           UpperCamelCase__     : str											=					np.ones([3, 2_2_4, 2_2_4]	)

           UpperCamelCase__     : List[Any]											=					processor(audio=__SCREAMING_SNAKE_CASE    ,    images=__SCREAMING_SNAKE_CASE	)

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






     def  __SCREAMING_SNAKE_CASE      (				self	)	-> List[Any]:




           """simple docstring"""







           UpperCamelCase__     : int											=					self.get_image_processor()
           UpperCamelCase__     : str											=					self.get_feature_extractor()

           UpperCamelCase__     : Dict											=					TvltProcessor(image_processor=__SCREAMING_SNAKE_CASE    ,    feature_extractor=__SCREAMING_SNAKE_CASE	)

           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'''    ,    )


