
from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


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


if is_vision_available():
   import PIL






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    Union[str, Any] 				=    ['''pixel_values''']


   def __init__(					self     :							Any			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							Dict[str, int] = None			,			lowerCAmelCase_     :							PILImageResampling = PILImageResampling.BICUBIC			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							Dict[str, int] = None			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							Union[int, float] = 1 / 2_5_5			,			lowerCAmelCase_     :							bool = True			,			lowerCAmelCase_     :							Optional[Union[float, List[float]]] = None			,			lowerCAmelCase_     :							Optional[Union[float, List[float]]] = None			,			lowerCAmelCase_     :							bool = True			,			**lowerCAmelCase_     :							int			,			):

      """simple docstring"""
      super().__init__(**lowerCAmelCase_     )
      _A:  Dict					=       size if size is not None else {'''shortest_edge''': 2_2_4}
      _A:  Tuple					=       get_size_dict(lowerCAmelCase_			,			default_to_square=lowerCAmelCase_     )
      _A:  Optional[int]					=       crop_size if crop_size is not None else {'''height''': 2_2_4, '''width''': 2_2_4}
      _A:  List[str]					=       get_size_dict(lowerCAmelCase_			,			default_to_square=lowerCAmelCase_			,			param_name='''crop_size'''     )

      _A:  List[str]					=       do_resize
      _A:  Optional[int]					=       size
      _A:  Optional[Any]					=       resample
      _A:  Tuple					=       do_center_crop
      _A:  str					=       crop_size
      _A:  str					=       do_rescale
      _A:  Optional[int]					=       rescale_factor
      _A:  int					=       do_normalize
      _A:  List[Any]					=       image_mean if image_mean is not None else OPENAI_CLIP_MEAN
      _A:  str					=       image_std if image_std is not None else OPENAI_CLIP_STD
      _A:  Dict					=       do_convert_rgb


   def  __magic_name__				(					self     :							Dict			,			lowerCAmelCase_     :							np.ndarray			,			lowerCAmelCase_     :							Dict[str, int]			,			lowerCAmelCase_     :							PILImageResampling = PILImageResampling.BICUBIC			,			lowerCAmelCase_     :							Optional[Union[str, ChannelDimension]] = None			,			**lowerCAmelCase_     :							Tuple			,			):

      """simple docstring"""
      _A:  int					=       get_size_dict(lowerCAmelCase_			,			default_to_square=lowerCAmelCase_     )
      if "shortest_edge" not in size:
         raise ValueError(F"""The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}"""     )
      _A:  Dict					=       get_resize_output_image_size(lowerCAmelCase_			,			size=size['''shortest_edge''']			,			default_to_square=lowerCAmelCase_     )
      return resize(lowerCAmelCase_			,			size=lowerCAmelCase_			,			resample=lowerCAmelCase_			,			data_format=lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							str			,			lowerCAmelCase_     :							np.ndarray			,			lowerCAmelCase_     :							Dict[str, int]			,			lowerCAmelCase_     :							Optional[Union[str, ChannelDimension]] = None			,			**lowerCAmelCase_     :							List[str]			,			):

      """simple docstring"""
      _A:  str					=       get_size_dict(lowerCAmelCase_     )
      if "height" not in size or "width" not in size:
         raise ValueError(F"""The `size` parameter must contain the keys (height, width). Got {size.keys()}"""     )
      return center_crop(lowerCAmelCase_			,			size=(size['''height'''], size['''width'''])			,			data_format=lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Optional[int]			,			lowerCAmelCase_     :							np.ndarray			,			lowerCAmelCase_     :							Union[int, float]			,			lowerCAmelCase_     :							Optional[Union[str, ChannelDimension]] = None			,			**lowerCAmelCase_     :							Optional[Any]			,			):

      """simple docstring"""
      return rescale(lowerCAmelCase_			,			scale=lowerCAmelCase_			,			data_format=lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Union[str, Any]			,			lowerCAmelCase_     :							np.ndarray			,			lowerCAmelCase_     :							Union[float, List[float]]			,			lowerCAmelCase_     :							Union[float, List[float]]			,			lowerCAmelCase_     :							Optional[Union[str, ChannelDimension]] = None			,			**lowerCAmelCase_     :							Dict			,			):

      """simple docstring"""
      return normalize(lowerCAmelCase_			,			mean=lowerCAmelCase_			,			std=lowerCAmelCase_			,			data_format=lowerCAmelCase_			,			**lowerCAmelCase_     )


   def  __magic_name__				(					self     :							Tuple			,			lowerCAmelCase_     :							ImageInput			,			lowerCAmelCase_     :							bool = None			,			lowerCAmelCase_     :							Dict[str, int] = None			,			lowerCAmelCase_     :							PILImageResampling = None			,			lowerCAmelCase_     :							bool = None			,			lowerCAmelCase_     :							int = None			,			lowerCAmelCase_     :							bool = None			,			lowerCAmelCase_     :							float = None			,			lowerCAmelCase_     :							bool = None			,			lowerCAmelCase_     :							Optional[Union[float, List[float]]] = None			,			lowerCAmelCase_     :							Optional[Union[float, List[float]]] = None			,			lowerCAmelCase_     :							bool = None			,			lowerCAmelCase_     :							Optional[Union[str, TensorType]] = None			,			lowerCAmelCase_     :							Optional[ChannelDimension] = ChannelDimension.FIRST			,			**lowerCAmelCase_     :							Optional[int]			,			):

      """simple docstring"""
      _A:  Tuple					=       do_resize if do_resize is not None else self.do_resize
      _A:  Union[str, Any]					=       size if size is not None else self.size
      _A:  Dict					=       get_size_dict(lowerCAmelCase_			,			param_name='''size'''			,			default_to_square=lowerCAmelCase_     )
      _A:  Any					=       resample if resample is not None else self.resample
      _A:  Tuple					=       do_center_crop if do_center_crop is not None else self.do_center_crop
      _A:  List[Any]					=       crop_size if crop_size is not None else self.crop_size
      _A:  Union[str, Any]					=       get_size_dict(lowerCAmelCase_			,			param_name='''crop_size'''			,			default_to_square=lowerCAmelCase_     )
      _A:  Union[str, Any]					=       do_rescale if do_rescale is not None else self.do_rescale
      _A:  Union[str, Any]					=       rescale_factor if rescale_factor is not None else self.rescale_factor
      _A:  Dict					=       do_normalize if do_normalize is not None else self.do_normalize
      _A:  Optional[Any]					=       image_mean if image_mean is not None else self.image_mean
      _A:  int					=       image_std if image_std is not None else self.image_std
      _A:  Dict					=       do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

      _A:  List[str]					=       make_list_of_images(lowerCAmelCase_     )

      if not valid_images(lowerCAmelCase_     ):
         raise ValueError(
             '''Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '''
             '''torch.Tensor, tf.Tensor or jax.ndarray.'''     )

      if do_resize and size is None:
         raise ValueError('''Size must be specified if do_resize is True.'''     )

      if do_center_crop and crop_size is None:
         raise ValueError('''Crop size must be specified if do_center_crop is True.'''     )

      if do_rescale and rescale_factor is None:
         raise ValueError('''Rescale factor must be specified if do_rescale is True.'''     )

      if do_normalize and (image_mean is None or image_std is None):
         raise ValueError('''Image mean and std must be specified if do_normalize is True.'''     )

      # PIL RGBA images are converted to RGB
      if do_convert_rgb:
         _A:  Union[str, Any]					=       [convert_to_rgb(lowerCAmelCase_     ) for image in images]

      # All transformations expect numpy arrays.
      _A:  List[str]					=       [to_numpy_array(lowerCAmelCase_     ) for image in images]

      if do_resize:
         _A:  Tuple					=       [self.resize(image=lowerCAmelCase_			,			size=lowerCAmelCase_			,			resample=lowerCAmelCase_     ) for image in images]

      if do_center_crop:
         _A:  Union[str, Any]					=       [self.center_crop(image=lowerCAmelCase_			,			size=lowerCAmelCase_     ) for image in images]

      if do_rescale:
         _A:  List[Any]					=       [self.rescale(image=lowerCAmelCase_			,			scale=lowerCAmelCase_     ) for image in images]

      if do_normalize:
         _A:  Dict					=       [self.normalize(image=lowerCAmelCase_			,			mean=lowerCAmelCase_			,			std=lowerCAmelCase_     ) for image in images]

      _A:  Union[str, Any]					=       [to_channel_dimension_format(lowerCAmelCase_			,			lowerCAmelCase_     ) for image in images]

      _A:  List[str]					=       {'''pixel_values''': images}
      return BatchFeature(data=lowerCAmelCase_			,			tensor_type=lowerCAmelCase_     )





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_convbert import ConvBertTokenizer


UpperCAmelCase__		:     Optional[Any]     			=      logging.get_logger(__name__)

UpperCAmelCase__		:     Dict     			=      {'vocab_file': 'vocab.txt'}

UpperCAmelCase__		:     List[Any]     			=      {
    'vocab_file': {
        'YituTech/conv-bert-base': 'https://huggingface.co/YituTech/conv-bert-base/resolve/main/vocab.txt',
        'YituTech/conv-bert-medium-small': (
            'https://huggingface.co/YituTech/conv-bert-medium-small/resolve/main/vocab.txt'
        ),
        'YituTech/conv-bert-small': 'https://huggingface.co/YituTech/conv-bert-small/resolve/main/vocab.txt',
    }
}

UpperCAmelCase__		:     Union[str, Any]     			=      {
    'YituTech/conv-bert-base': 512,
    'YituTech/conv-bert-medium-small': 512,
    'YituTech/conv-bert-small': 512,
}


UpperCAmelCase__		:     Dict     			=      {
    'YituTech/conv-bert-base': {'do_lower_case': True},
    'YituTech/conv-bert-medium-small': {'do_lower_case': True},
    'YituTech/conv-bert-small': {'do_lower_case': True},
}






class UpperCAmelCase   (						SCREAMING_SNAKE_CASE__   ):





   '''simple docstring'''
   __UpperCamelCase		:    Any 				=    VOCAB_FILES_NAMES
   __UpperCamelCase		:    Tuple 				=    PRETRAINED_VOCAB_FILES_MAP
   __UpperCamelCase		:    str 				=    PRETRAINED_INIT_CONFIGURATION
   __UpperCamelCase		:    int 				=    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
   __UpperCamelCase		:    int 				=    ConvBertTokenizer


   def __init__(					self     :							Tuple			,			lowerCAmelCase_     :							int=None			,			lowerCAmelCase_     :							List[Any]=None			,			lowerCAmelCase_     :							Optional[Any]=True			,			lowerCAmelCase_     :							List[Any]="[UNK]"			,			lowerCAmelCase_     :							Optional[Any]="[SEP]"			,			lowerCAmelCase_     :							Optional[Any]="[PAD]"			,			lowerCAmelCase_     :							List[Any]="[CLS]"			,			lowerCAmelCase_     :							Optional[int]="[MASK]"			,			lowerCAmelCase_     :							Any=True			,			lowerCAmelCase_     :							List[str]=None			,			**lowerCAmelCase_     :							List[Any]			,			):

      """simple docstring"""
      super().__init__(
          lowerCAmelCase_			,			tokenizer_file=lowerCAmelCase_			,			do_lower_case=lowerCAmelCase_			,			unk_token=lowerCAmelCase_			,			sep_token=lowerCAmelCase_			,			pad_token=lowerCAmelCase_			,			cls_token=lowerCAmelCase_			,			mask_token=lowerCAmelCase_			,			tokenize_chinese_chars=lowerCAmelCase_			,			strip_accents=lowerCAmelCase_			,			**lowerCAmelCase_			,			)

      _A:  List[Any]					=       json.loads(self.backend_tokenizer.normalizer.__getstate__()     )
      if (
          normalizer_state.get('''lowercase'''			,			lowerCAmelCase_     ) != do_lower_case
          or normalizer_state.get('''strip_accents'''			,			lowerCAmelCase_     ) != strip_accents
          or normalizer_state.get('''handle_chinese_chars'''			,			lowerCAmelCase_     ) != tokenize_chinese_chars
      ):
         _A:  List[str]					=       getattr(lowerCAmelCase_			,			normalizer_state.pop('''type'''     )     )
         _A:  List[Any]					=       do_lower_case
         _A:  Optional[Any]					=       strip_accents
         _A:  Union[str, Any]					=       tokenize_chinese_chars
         _A:  Optional[int]					=       normalizer_class(**lowerCAmelCase_     )

      _A:  Optional[Any]					=       do_lower_case


   def  __magic_name__				(					self     :							str			,			lowerCAmelCase_     :							Tuple			,			lowerCAmelCase_     :							Union[str, Any]=None     ):

      """simple docstring"""
      _A:  Dict					=       [self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
         output += token_ids_a + [self.sep_token_id]

      return output


   def  __magic_name__				(					self     :							Union[str, Any]			,			lowerCAmelCase_     :							List[int]			,			lowerCAmelCase_     :							Optional[List[int]] = None     ):

      """simple docstring"""
      _A:  Any					=       [self.sep_token_id]
      _A:  int					=       [self.cls_token_id]
      if token_ids_a is None:
         return len(cls + token_ids_a + sep     ) * [0]
      return len(cls + token_ids_a + sep     ) * [0] + len(token_ids_a + sep     ) * [1]


   def  __magic_name__				(					self     :							int			,			lowerCAmelCase_     :							str			,			lowerCAmelCase_     :							Optional[str] = None     ):

      """simple docstring"""
      _A:  str					=       self._tokenizer.model.save(lowerCAmelCase_			,			name=lowerCAmelCase_     )
      return tuple(lowerCAmelCase_     )



