



'''simple docstring'''





import re
import warnings
from contextlib import contextmanager

from ...processing_utils import ProcessorMixin






class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  __lowercase							:				int           =				['''image_processor''', '''tokenizer''']
  __lowercase							:				str           =				'''AutoImageProcessor'''
  __lowercase							:				Any           =				'''AutoTokenizer'''




  def __init__(   self  ,__UpperCAmelCase=None  ,__UpperCAmelCase=None  ,**__UpperCAmelCase				)   ->		str:
      lowerCAmelCase__			:  Tuple											= None
      if "feature_extractor" in kwargs:
          warnings.warn(
              """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
              """ instead."""  ,__UpperCAmelCase  ,)
          lowerCAmelCase__			:  str											= kwargs.pop("""feature_extractor"""				)

      lowerCAmelCase__			:  str											= 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__(__UpperCAmelCase  ,__UpperCAmelCase				)
      lowerCAmelCase__			:  int											= self.image_processor
      lowerCAmelCase__			:  List[Any]											= False




  def __call__(   self  ,*__UpperCAmelCase  ,**__UpperCAmelCase				)   ->		Union[str, Any]:
      # For backward compatibility
      if self._in_target_context_manager:
          return self.current_processor(*__UpperCAmelCase  ,**__UpperCAmelCase				)

      lowerCAmelCase__			:  Any											= kwargs.pop("""images"""  ,__UpperCAmelCase				)
      lowerCAmelCase__			:  Any											= kwargs.pop("""text"""  ,__UpperCAmelCase				)
      if len(__UpperCAmelCase				) > 0:
          lowerCAmelCase__			:  Any											= args[0]
          lowerCAmelCase__			:  Optional[int]											= 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:
          lowerCAmelCase__			:  Union[str, Any]											= self.image_processor(__UpperCAmelCase  ,*__UpperCAmelCase  ,**__UpperCAmelCase				)
      if text is not None:
          lowerCAmelCase__			:  Dict											= self.tokenizer(__UpperCAmelCase  ,**__UpperCAmelCase				)

      if text is None:
          return inputs
      elif images is None:
          return encodings
      else:
          lowerCAmelCase__			:  List[str]											= encodings["""input_ids"""]
          return inputs




  def 							UpperCAmelCase_     (   self  ,*__UpperCAmelCase  ,**__UpperCAmelCase				)   ->		Optional[Any]:
      return self.tokenizer.batch_decode(*__UpperCAmelCase  ,**__UpperCAmelCase				)




  def 							UpperCAmelCase_     (   self  ,*__UpperCAmelCase  ,**__UpperCAmelCase				)   ->		List[str]:
      return self.tokenizer.decode(*__UpperCAmelCase  ,**__UpperCAmelCase				)




  @contextmanager
  def 							UpperCAmelCase_     (   self				)   ->		str:
      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."""				)
      lowerCAmelCase__			:  Tuple											= True
      lowerCAmelCase__			:  List[Any]											= self.tokenizer
      yield
      lowerCAmelCase__			:  Dict											= self.image_processor
      lowerCAmelCase__			:  str											= False




  def 							UpperCAmelCase_     (   self  ,__UpperCAmelCase  ,__UpperCAmelCase=False  ,__UpperCAmelCase=None				)   ->		Union[str, Any]:
      if added_vocab is None:
          lowerCAmelCase__			:  List[Any]											= self.tokenizer.get_added_vocab()

      lowerCAmelCase__			:  Any											= {}

      while tokens:
          lowerCAmelCase__			:  Dict											= re.search(R"""<s_(.*?)>"""  ,__UpperCAmelCase  ,re.IGNORECASE				)
          if start_token is None:
              break
          lowerCAmelCase__			:  Optional[Any]											= start_token.group(1				)
          lowerCAmelCase__			:  Any											= re.search(RF"""</s_{key}>"""  ,__UpperCAmelCase  ,re.IGNORECASE				)
          lowerCAmelCase__			:  Union[str, Any]											= start_token.group()
          if end_token is None:
              lowerCAmelCase__			:  Tuple											= tokens.replace(__UpperCAmelCase  ,""""""				)
          else:
              lowerCAmelCase__			:  int											= end_token.group()
              lowerCAmelCase__			:  List[str]											= re.escape(__UpperCAmelCase				)
              lowerCAmelCase__			:  List[str]											= re.escape(__UpperCAmelCase				)
              lowerCAmelCase__			:  Union[str, Any]											= re.search(F"""{start_token_escaped}(.*?){end_token_escaped}"""  ,__UpperCAmelCase  ,re.IGNORECASE				)
              if content is not None:
                  lowerCAmelCase__			:  Any											= content.group(1				).strip()
                  if r"<s_" in content and r"</s_" in content:  # non-leaf node
                      lowerCAmelCase__			:  Any											= self.tokenajson(__UpperCAmelCase  ,is_inner_value=__UpperCAmelCase  ,added_vocab=__UpperCAmelCase				)
                      if value:
                          if len(__UpperCAmelCase				) == 1:
                              lowerCAmelCase__			:  int											= value[0]
                          lowerCAmelCase__			:  Dict											= value
                  else:  # leaf nodes
                      lowerCAmelCase__			:  Dict											= []
                      for leaf in content.split(R"""<sep/>"""				):
                          lowerCAmelCase__			:  str											= leaf.strip()
                          if leaf in added_vocab and leaf[0] == "<" and leaf[-2:] == "/>":
                              lowerCAmelCase__			:  List[Any]											= leaf[1:-2]  # for categorical special tokens
                          output[key].append(__UpperCAmelCase				)
                      if len(output[key]				) == 1:
                          lowerCAmelCase__			:  int											= output[key][0]

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

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




  @property
  def 							UpperCAmelCase_     (   self				)   ->		List[str]:
      warnings.warn(
          """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""  ,__UpperCAmelCase  ,)
      return self.image_processor_class






  @property
  def 							UpperCAmelCase_     (   self				)   ->		int:
      warnings.warn(
          """`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."""  ,__UpperCAmelCase  ,)
      return self.image_processor







'''simple docstring'''





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


_lowerCAmelCase										=     logging.get_logger(__name__)

_lowerCAmelCase										=     {
    '''facebook/convnextv2-tiny-1k-224''': '''https://huggingface.co/facebook/convnextv2-tiny-1k-224/resolve/main/config.json''',
}






class 	lowerCAmelCase_(    SCREAMING_SNAKE_CASE_						,			SCREAMING_SNAKE_CASE_					):
  '''simple docstring'''




  __lowercase							:				Tuple           =				'''convnextv2'''




  def __init__(   self  ,__UpperCAmelCase=3  ,__UpperCAmelCase=4  ,__UpperCAmelCase=4  ,__UpperCAmelCase=None  ,__UpperCAmelCase=None  ,__UpperCAmelCase="gelu"  ,__UpperCAmelCase=0.0_2  ,__UpperCAmelCase=1E-12  ,__UpperCAmelCase=0.0  ,__UpperCAmelCase=224  ,__UpperCAmelCase=None  ,__UpperCAmelCase=None  ,**__UpperCAmelCase  ,)   ->		Union[str, Any]:
      super().__init__(**__UpperCAmelCase				)

      lowerCAmelCase__			:  int											= num_channels
      lowerCAmelCase__			:  List[Any]											= patch_size
      lowerCAmelCase__			:  Union[str, Any]											= num_stages
      lowerCAmelCase__			:  Tuple											= [96, 192, 384, 768] if hidden_sizes is None else hidden_sizes
      lowerCAmelCase__			:  str											= [3, 3, 9, 3] if depths is None else depths
      lowerCAmelCase__			:  Optional[Any]											= hidden_act
      lowerCAmelCase__			:  str											= initializer_range
      lowerCAmelCase__			:  List[str]											= layer_norm_eps
      lowerCAmelCase__			:  Dict											= drop_path_rate
      lowerCAmelCase__			:  int											= image_size
      lowerCAmelCase__			:  int											= ["""stem"""] + [F"""stage{idx}""" for idx in range(1  ,len(self.depths				) + 1				)]
      lowerCAmelCase__				,       lowerCAmelCase__			:  Tuple											= get_aligned_output_features_output_indices(
          out_features=__UpperCAmelCase  ,out_indices=__UpperCAmelCase  ,stage_names=self.stage_names				)


