

from typing import Dict, List, Optional

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


A__						=							logging.get_logger(__name__)


A__						=							{
    "nielsr/canine-s": 2048,
}

# Unicode defines 1,114,112 total “codepoints”
A__						=							1114112

# Below: Constants defining canonical codepoints for special, pseudo-characters.
# Copied from https://github.com/google-research/language/blob/master/language/canine/special_codepoints.py
A__						=							0

A__						=							0xE0_00
A__						=							0xE0_01
A__						=							0xE0_02
A__						=							0xE0_03
A__						=							0xE0_04

# Maps special codepoints to human-readable names.
A__						=							{
    # Special symbols are represented using codepoints values that are valid,
    # but designated as "Private Use", meaning that they will never be assigned
    # characters by the Unicode Consortium, and are thus safe for use here.
    #
    # NOTE: Do *NOT* add any sort of [UNK_CHAR] here. They are explicitly
    # excluded and should fail with a hard error.
    CLS: "[CLS]",
    SEP: "[SEP]",
    BOS: "[BOS]",
    MASK: "[MASK]",
    PAD: "[PAD]",
    RESERVED: "[RESERVED]",
}

# Maps special codepoint human-readable names to their codepoint values.
A__						=							{name: codepoint for codepoint, name in SPECIAL_CODEPOINTS.items()}

class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   List[Any]       				=  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES







	def __init__(   self: int  , __UpperCamelCase: List[str]=chr(__UpperCamelCase      )  , __UpperCamelCase: str=chr(__UpperCamelCase      )  , __UpperCamelCase: Optional[int]=chr(__UpperCamelCase      )  , __UpperCamelCase: Optional[Any]=chr(__UpperCamelCase      )  , __UpperCamelCase: List[str]=chr(__UpperCamelCase      )  , __UpperCamelCase: Tuple=chr(__UpperCamelCase      )  , __UpperCamelCase: Optional[int]=False  , __UpperCamelCase: Union[str, Any]=20_48  , **__UpperCamelCase: Any  , ):

						'''simple docstring'''





						__magic_name__							=    AddedToken(__UpperCamelCase  , lstrip=__UpperCamelCase  , rstrip=__UpperCamelCase      ) if isinstance(__UpperCamelCase  , __UpperCamelCase      ) else bos_token
						__magic_name__							=    AddedToken(__UpperCamelCase  , lstrip=__UpperCamelCase  , rstrip=__UpperCamelCase      ) if isinstance(__UpperCamelCase  , __UpperCamelCase      ) else eos_token
						__magic_name__							=    AddedToken(__UpperCamelCase  , lstrip=__UpperCamelCase  , rstrip=__UpperCamelCase      ) if isinstance(__UpperCamelCase  , __UpperCamelCase      ) else sep_token
						__magic_name__							=    AddedToken(__UpperCamelCase  , lstrip=__UpperCamelCase  , rstrip=__UpperCamelCase      ) if isinstance(__UpperCamelCase  , __UpperCamelCase      ) else cls_token
						__magic_name__							=    AddedToken(__UpperCamelCase  , lstrip=__UpperCamelCase  , rstrip=__UpperCamelCase      ) if isinstance(__UpperCamelCase  , __UpperCamelCase      ) else pad_token

						# Mask token behave like a normal word, i.e. include the space before it
						__magic_name__							=    AddedToken(__UpperCamelCase  , lstrip=__UpperCamelCase  , rstrip=__UpperCamelCase      ) if isinstance(__UpperCamelCase  , __UpperCamelCase      ) else mask_token

						super().__init__(
						    bos_token=__UpperCamelCase  , eos_token=__UpperCamelCase  , sep_token=__UpperCamelCase  , cls_token=__UpperCamelCase  , pad_token=__UpperCamelCase  , mask_token=__UpperCamelCase  , add_prefix_space=__UpperCamelCase  , model_max_length=__UpperCamelCase  , **__UpperCamelCase  , )

						# Creates a mapping for looking up the IDs of special symbols.
						__magic_name__							=    {}
						for codepoint, name in SPECIAL_CODEPOINTS.items():
											__magic_name__							=    codepoint

						# Creates a mapping for looking up the string forms of special symbol IDs.
						__magic_name__							=    {
						    codepoint: name for name, codepoint in self._special_codepoints.items()
						}

						__magic_name__							=    UNICODE_VOCAB_SIZE
						__magic_name__							=    len(self._special_codepoints      )







	@property
	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[Any]      ):

						'''simple docstring'''





						return self._unicode_vocab_size







	def 	_SCREAMING_SNAKE_CASE							(   self: Union[str, Any]  , __UpperCamelCase: str      ):

						'''simple docstring'''





						return list(__UpperCamelCase      )







	def 	_SCREAMING_SNAKE_CASE							(   self: Dict  , __UpperCamelCase: str      ):

						'''simple docstring'''





						try:
											return ord(__UpperCamelCase      )
						except TypeError:
											raise ValueError(F'invalid token: \'{token}\''      )







	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[Any]  , __UpperCamelCase: int      ):

						'''simple docstring'''





						try:
											if index in SPECIAL_CODEPOINTS:
																return SPECIAL_CODEPOINTS[index]
											return chr(__UpperCamelCase      )
						except TypeError:
											raise ValueError(F'invalid id: {index}'      )







	def 	_SCREAMING_SNAKE_CASE							(   self: int  , __UpperCamelCase: Optional[Any]      ):

						'''simple docstring'''





						return "".join(__UpperCamelCase      )







	def 	_SCREAMING_SNAKE_CASE							(   self: List[str]  , __UpperCamelCase: List[int]  , __UpperCamelCase: Optional[List[int]] = None      ):

						'''simple docstring'''





						__magic_name__							=    [self.sep_token_id]
						__magic_name__							=    [self.cls_token_id]

						__magic_name__							=    cls + token_ids_a + sep
						if token_ids_a is not None:
											result += token_ids_a + sep
						return result







	def 	_SCREAMING_SNAKE_CASE							(   self: Any  , __UpperCamelCase: List[int]  , __UpperCamelCase: Optional[List[int]] = None  , __UpperCamelCase: bool = False      ):

						'''simple docstring'''





						if already_has_special_tokens:
											return super().get_special_tokens_mask(
											    token_ids_a=__UpperCamelCase  , token_ids_a=__UpperCamelCase  , already_has_special_tokens=__UpperCamelCase      )

						__magic_name__							=    [1] + ([0] * len(__UpperCamelCase      )) + [1]
						if token_ids_a is not None:
											result += ([0] * len(__UpperCamelCase      )) + [1]
						return result







	def 	_SCREAMING_SNAKE_CASE							(   self: str  , __UpperCamelCase: List[int]  , __UpperCamelCase: Optional[List[int]] = None      ):

						'''simple docstring'''





						__magic_name__							=    [self.sep_token_id]
						__magic_name__							=    [self.cls_token_id]

						__magic_name__							=    len(cls + token_ids_a + sep      ) * [0]
						if token_ids_a is not None:
											result += len(token_ids_a + sep      ) * [1]
						return result







	def 	_SCREAMING_SNAKE_CASE							(   self: Optional[Any]  , __UpperCamelCase: str  , __UpperCamelCase: Optional[str] = None      ):

						'''simple docstring'''





						return ()







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,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
						import PIL


A__						=							logging.get_logger(__name__)

class 				__UpperCamelCase				(					SCREAMING_SNAKE_CASE			):
	_lowercase  :   Tuple       				=  ["pixel_values"]







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

						'''simple docstring'''





						super().__init__(**__UpperCamelCase      )
						__magic_name__							=    size if size is not None else {'shortest_edge': 2_24}
						__magic_name__							=    get_size_dict(__UpperCamelCase  , default_to_square=__UpperCamelCase      )
						__magic_name__							=    crop_size if crop_size is not None else {'height': 2_24, 'width': 2_24}
						__magic_name__							=    get_size_dict(__UpperCamelCase  , param_name='crop_size'      )

						__magic_name__							=    do_resize
						__magic_name__							=    size
						__magic_name__							=    crop_pct
						__magic_name__							=    resample
						__magic_name__							=    do_center_crop
						__magic_name__							=    crop_size
						__magic_name__							=    do_rescale
						__magic_name__							=    rescale_factor
						__magic_name__							=    do_normalize
						__magic_name__							=    image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
						__magic_name__							=    image_std if image_std is not None else IMAGENET_DEFAULT_STD







	def 	_SCREAMING_SNAKE_CASE							(   self: List[Any]  , __UpperCamelCase: np.ndarray  , __UpperCamelCase: Dict[str, int]  , __UpperCamelCase: Optional[float] = None  , __UpperCamelCase: PILImageResampling = PILImageResampling.BICUBIC  , __UpperCamelCase: Optional[Union[str, ChannelDimension]] = None  , **__UpperCamelCase: Optional[Any]  , ):

						'''simple docstring'''





						__magic_name__							=    get_size_dict(__UpperCamelCase  , default_to_square=__UpperCamelCase      )
						if "shortest_edge" not in size and ("height" not in size or "width" not in size):
											raise ValueError(F'size must contain \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'      )
						if crop_pct is not None:
											if "shortest_edge" in size:
																__magic_name__							=    int(size['shortest_edge'] / crop_pct      )
											elif "height" in size and "width" in size:
																if size["height"] == size["width"]:
																					__magic_name__							=    int(size['height'] / crop_pct      )
																else:
																					__magic_name__							=    (int(size['height'] / crop_pct      ), int(size['width'] / crop_pct      ))
											else:
																raise ValueError('Invalid size for resize: {}'.format(__UpperCamelCase      )      )

											__magic_name__							=    get_resize_output_image_size(__UpperCamelCase  , size=__UpperCamelCase  , default_to_square=__UpperCamelCase      )
						else:
											if "shortest_edge" in size:
																__magic_name__							=    get_resize_output_image_size(__UpperCamelCase  , size=size['shortest_edge']  , default_to_square=__UpperCamelCase      )
											elif "height" in size and "width" in size:
																__magic_name__							=    (size['height'], size['width'])
											else:
																raise ValueError('Invalid size for resize: {}'.format(__UpperCamelCase      )      )

						return resize(__UpperCamelCase  , size=__UpperCamelCase  , resample=__UpperCamelCase  , data_format=__UpperCamelCase  , **__UpperCamelCase      )







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

						'''simple docstring'''





						__magic_name__							=    get_size_dict(__UpperCamelCase      )
						if "height" not in size or "width" not in size:
											raise ValueError(F'size must contain \'height\' and \'width\' as keys. Got {size.keys()}'      )
						return center_crop(__UpperCamelCase  , size=(size['height'], size['width'])  , data_format=__UpperCamelCase  , **__UpperCamelCase      )







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

						'''simple docstring'''





						return rescale(__UpperCamelCase  , scale=__UpperCamelCase  , data_format=__UpperCamelCase  , **__UpperCamelCase      )







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

						'''simple docstring'''





						return normalize(__UpperCamelCase  , mean=__UpperCamelCase  , std=__UpperCamelCase  , data_format=__UpperCamelCase  , **__UpperCamelCase      )







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

						'''simple docstring'''





						__magic_name__							=    do_resize if do_resize is not None else self.do_resize
						__magic_name__							=    crop_pct if crop_pct is not None else self.crop_pct
						__magic_name__							=    resample if resample is not None else self.resample
						__magic_name__							=    do_center_crop if do_center_crop is not None else self.do_center_crop
						__magic_name__							=    do_rescale if do_rescale is not None else self.do_rescale
						__magic_name__							=    rescale_factor if rescale_factor is not None else self.rescale_factor
						__magic_name__							=    do_normalize if do_normalize is not None else self.do_normalize
						__magic_name__							=    image_mean if image_mean is not None else self.image_mean
						__magic_name__							=    image_std if image_std is not None else self.image_std

						__magic_name__							=    size if size is not None else self.size
						__magic_name__							=    get_size_dict(__UpperCamelCase  , default_to_square=__UpperCamelCase      )
						__magic_name__							=    crop_size if crop_size is not None else self.crop_size
						__magic_name__							=    get_size_dict(__UpperCamelCase  , param_name='crop_size'      )

						__magic_name__							=    make_list_of_images(__UpperCamelCase      )

						if not valid_images(__UpperCamelCase      ):
											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 or resample is None:
											raise ValueError('Size and resample must be specified if do_resize is True.'      )

						if do_center_crop and crop_pct is None:
											raise ValueError('Crop_pct 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.'      )

						# All transformations expect numpy arrays.
						__magic_name__							=    [to_numpy_array(__UpperCamelCase      ) for image in images]

						if do_resize:
											__magic_name__							=    [self.resize(image=__UpperCamelCase  , size=__UpperCamelCase  , crop_pct=__UpperCamelCase  , resample=__UpperCamelCase      ) for image in images]

						if do_center_crop:
											__magic_name__							=    [self.center_crop(image=__UpperCamelCase  , size=__UpperCamelCase      ) for image in images]

						if do_rescale:
											__magic_name__							=    [self.rescale(image=__UpperCamelCase  , scale=__UpperCamelCase      ) for image in images]

						if do_normalize:
											__magic_name__							=    [self.normalize(image=__UpperCamelCase  , mean=__UpperCamelCase  , std=__UpperCamelCase      ) for image in images]

						__magic_name__							=    [to_channel_dimension_format(__UpperCamelCase  , __UpperCamelCase      ) for image in images]

						__magic_name__							=    {'pixel_values': images}
						return BatchFeature(data=__UpperCamelCase  , tensor_type=__UpperCamelCase      )




