



import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin



class       UpperCAmelCase__(							lowerCamelCase	):

   '''simple docstring'''




   A    :  List[str]       				=    ["image_processor", "tokenizer"]
   A    :  List[Any]       				=    "AutoImageProcessor"
   A    :  Dict       				=    "AutoTokenizer"


   def __init__(						self  :			Tuple			,				lowerCAmelCase  :			List[Any]=None			,				lowerCAmelCase  :			Union[str, Any]=None			,				**lowerCAmelCase  :			Dict)	->				List[Any]:




         """simple docstring"""

         lowercase__     =  None
         if "feature_extractor" in kwargs:
               warnings.warn(
                   'The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`'
                   ' instead.'			,				lowerCAmelCase			,				)
               lowercase__     =  kwargs.pop('feature_extractor')

         lowercase__     =  image_processor if image_processor is not None else feature_extractor
         if image_processor is None:
               raise ValueError('You need to specify an `image_processor`.')
         if tokenizer is None:
               raise ValueError('You need to specify a `tokenizer`.')

         super().__init__(lowerCAmelCase			,				lowerCAmelCase)
         lowercase__     =  self.image_processor
         lowercase__     =  False


   def __call__(						self  :			Any			,				*lowerCAmelCase  :			Dict			,				**lowerCAmelCase  :			Union[str, Any])	->				Tuple:




         """simple docstring"""

         if self._in_target_context_manager:
               return self.current_processor(*lowerCAmelCase			,				**lowerCAmelCase)

         lowercase__     =  kwargs.pop('images'			,				lowerCAmelCase)
         lowercase__     =  kwargs.pop('text'			,				lowerCAmelCase)
         if len(lowerCAmelCase) > 0:
               lowercase__     =  args[0]
               lowercase__     =  args[1:]

         if images is None and text is None:
               raise ValueError('You need to specify either an `images` or `text` input to process.')

         if images is not None:
               lowercase__     =  self.image_processor(lowerCAmelCase			,				*lowerCAmelCase			,				**lowerCAmelCase)
         if text is not None:
               lowercase__     =  self.tokenizer(lowerCAmelCase			,				**lowerCAmelCase)

         if text is None:
               return inputs
         elif images is None:
               return encodings
         else:
               lowercase__     =  encodings['input_ids']
               return inputs


   def 			UpperCAmelCase		(						self  :			Tuple			,				*lowerCAmelCase  :			int			,				**lowerCAmelCase  :			Any)	->				str:




         """simple docstring"""

         return self.tokenizer.batch_decode(*lowerCAmelCase			,				**lowerCAmelCase)


   def 			UpperCAmelCase		(						self  :			str			,				*lowerCAmelCase  :			List[str]			,				**lowerCAmelCase  :			Any)	->				Dict:




         """simple docstring"""

         return self.tokenizer.decode(*lowerCAmelCase			,				**lowerCAmelCase)


   @contextmanager
   def 			UpperCAmelCase		(						self  :			List[str])	->				Optional[Any]:




         """simple docstring"""

         warnings.warn(
             '`as_target_processor` is deprecated and will be removed in v5 of Transformers. You can process your '
             'labels by using the argument `text` of the regular `__call__` method (either in the same call as '
             'your images inputs, or in a separate call.')
         lowercase__     =  True
         lowercase__     =  self.tokenizer
         yield
         lowercase__     =  self.image_processor
         lowercase__     =  False


   def 			UpperCAmelCase		(						self  :			Optional[int]			,				lowerCAmelCase  :			Dict			,				lowerCAmelCase  :			Tuple=False			,				lowerCAmelCase  :			int=None)	->				Optional[Any]:




         """simple docstring"""

         if added_vocab is None:
               lowercase__     =  self.tokenizer.get_added_vocab()

         lowercase__     =  {}

         while tokens:
               lowercase__     =  re.search(R'<s_(.*?)>'			,				lowerCAmelCase			,				re.IGNORECASE)
               if start_token is None:
                     break
               lowercase__     =  start_token.group(1)
               lowercase__     =  re.search(Rf'''</s_{key}>'''			,				lowerCAmelCase			,				re.IGNORECASE)
               lowercase__     =  start_token.group()
               if end_token is None:
                     lowercase__     =  tokens.replace(lowerCAmelCase			,				'')
               else:
                     lowercase__     =  end_token.group()
                     lowercase__     =  re.escape(lowerCAmelCase)
                     lowercase__     =  re.escape(lowerCAmelCase)
                     lowercase__     =  re.search(f'''{start_token_escaped}(.*?){end_token_escaped}'''			,				lowerCAmelCase			,				re.IGNORECASE)
                     if content is not None:
                           lowercase__     =  content.group(1).strip()
                           if r"<s_" in content and r"</s_" in content:  # non-leaf node
                                 lowercase__     =  self.tokenajson(lowerCAmelCase			,				is_inner_value=lowerCAmelCase			,				added_vocab=lowerCAmelCase)
                                 if value:
                                       if len(lowerCAmelCase) == 1:
                                             lowercase__     =  value[0]
                                       lowercase__     =  value
                           else:  # leaf nodes
                                 lowercase__     =  []
                                 for leaf in content.split(R'<sep/>'):
                                       lowercase__     =  leaf.strip()
                                       if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                                             lowercase__     =  leaf[1:-2]  # for categorical special tokens
                                       output[key].append(lowerCAmelCase)
                                 if len(output[key]) == 1:
                                       lowercase__     =  output[key][0]

                     lowercase__     =  tokens[tokens.find(lowerCAmelCase) + len(lowerCAmelCase) :].strip()
                     if tokens[:6] == r"<sep/>":  # non-leaf nodes
                           return [output] + self.tokenajson(tokens[6:]			,				is_inner_value=lowerCAmelCase			,				added_vocab=lowerCAmelCase)

         if len(lowerCAmelCase):
               return [output] if is_inner_value else output
         else:
               return [] if is_inner_value else {"text_sequence": tokens}


   @property
   def 			UpperCAmelCase		(						self  :			Optional[int])	->				List[Any]:




         """simple docstring"""

         warnings.warn(
             '`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead.'			,				lowerCAmelCase			,				)
         return self.image_processor_class



   @property
   def 			UpperCAmelCase		(						self  :			Any)	->				List[str]:




         """simple docstring"""

         warnings.warn(
             '`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead.'			,				lowerCAmelCase			,				)
         return self.image_processor





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


a__      :				List[str]   	=			logging.get_logger(__name__)

a__      :				List[Any]   	=			{
    "microsoft/focalnet-tiny": "https://huggingface.co/microsoft/focalnet-tiny/resolve/main/config.json",
}



class       UpperCAmelCase__(							lowerCamelCase     ,							lowerCamelCase	):

   '''simple docstring'''




   A    :  List[str]       				=    "focalnet"


   def __init__(						self  :			Dict			,				lowerCAmelCase  :			Union[str, Any]=2_24			,				lowerCAmelCase  :			List[str]=4			,				lowerCAmelCase  :			int=3			,				lowerCAmelCase  :			Union[str, Any]=96			,				lowerCAmelCase  :			List[Any]=False			,				lowerCAmelCase  :			int=[1_92, 3_84, 7_68, 7_68]			,				lowerCAmelCase  :			str=[2, 2, 6, 2]			,				lowerCAmelCase  :			Tuple=[2, 2, 2, 2]			,				lowerCAmelCase  :			Optional[Any]=[3, 3, 3, 3]			,				lowerCAmelCase  :			int="gelu"			,				lowerCAmelCase  :			Any=4.0			,				lowerCAmelCase  :			List[str]=0.0			,				lowerCAmelCase  :			Union[str, Any]=0.1			,				lowerCAmelCase  :			Union[str, Any]=False			,				lowerCAmelCase  :			Tuple=1E-4			,				lowerCAmelCase  :			List[Any]=False			,				lowerCAmelCase  :			Optional[int]=False			,				lowerCAmelCase  :			List[str]=False			,				lowerCAmelCase  :			str=0.02			,				lowerCAmelCase  :			Optional[int]=1E-5			,				lowerCAmelCase  :			List[Any]=32			,				lowerCAmelCase  :			List[Any]=None			,				lowerCAmelCase  :			Union[str, Any]=None			,				**lowerCAmelCase  :			str			,				)	->				List[str]:




         """simple docstring"""

         super().__init__(**lowerCAmelCase)

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