



"""simple docstring"""

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, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_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_						:    Tuple				=      logging.get_logger(__name__)
class     lowerCAmelCase__						(	_lowerCamelCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		List[Any]  						= ['''pixel_values''']





	def __init__(      self				:       Optional[int]     ,       _SCREAMING_SNAKE_CASE				:       bool = True     ,       _SCREAMING_SNAKE_CASE				:       Dict[str, int] = None     ,       _SCREAMING_SNAKE_CASE				:       PILImageResampling = PIL.Image.BICUBIC     ,       _SCREAMING_SNAKE_CASE				:       bool = True     ,       _SCREAMING_SNAKE_CASE				:       Dict[str, int] = None     ,       _SCREAMING_SNAKE_CASE				:       Union[int, float] = 1 / 255     ,       _SCREAMING_SNAKE_CASE				:       bool = True     ,       _SCREAMING_SNAKE_CASE				:       bool = True     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[float, List[float]]] = None     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[float, List[float]]] = None     ,       **_SCREAMING_SNAKE_CASE				:       List[str]     ,       )						->	None:





					"""simple docstring"""


					super().__init__(**_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     size if size is not None else {'height': 256, 'width': 256}
					SCREAMING_SNAKE_CASE						:							List[Any]							=     get_size_dict(_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							List[Any]							=     crop_size if crop_size is not None else {'height': 224, 'width': 224}
					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     get_size_dict(_SCREAMING_SNAKE_CASE     ,       param_name='crop_size'    )

					SCREAMING_SNAKE_CASE						:							int							=     do_resize
					SCREAMING_SNAKE_CASE						:							List[str]							=     size
					SCREAMING_SNAKE_CASE						:							int							=     resample
					SCREAMING_SNAKE_CASE						:							str							=     do_center_crop
					SCREAMING_SNAKE_CASE						:							Dict							=     crop_size
					SCREAMING_SNAKE_CASE						:							List[Any]							=     do_rescale
					SCREAMING_SNAKE_CASE						:							List[str]							=     rescale_factor
					SCREAMING_SNAKE_CASE						:							int							=     do_normalize
					SCREAMING_SNAKE_CASE						:							Any							=     image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
					SCREAMING_SNAKE_CASE						:							Any							=     image_std if image_std is not None else IMAGENET_STANDARD_STD





	def 			_lowerCAmelCase     (      self				:       Optional[int]     ,       _SCREAMING_SNAKE_CASE				:       np.ndarray     ,       _SCREAMING_SNAKE_CASE				:       Dict[str, int]     ,       _SCREAMING_SNAKE_CASE				:       PILImageResampling = PIL.Image.BICUBIC     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[str, ChannelDimension]] = None     ,       **_SCREAMING_SNAKE_CASE				:       int     ,       )						->	np.ndarray:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Tuple							=     get_size_dict(_SCREAMING_SNAKE_CASE    )
					if "height" not in size or "width" not in size:
									raise ValueError(f"""The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"""    )
					return resize(
					    _SCREAMING_SNAKE_CASE     ,       size=(size['height'], size['width'])     ,       resample=_SCREAMING_SNAKE_CASE     ,       data_format=_SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       np.ndarray     ,       _SCREAMING_SNAKE_CASE				:       Dict[str, int]     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[str, ChannelDimension]] = None     ,       **_SCREAMING_SNAKE_CASE				:       Any     ,       )						->	np.ndarray:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							str							=     get_size_dict(_SCREAMING_SNAKE_CASE    )
					if "height" not in size or "width" not in size:
									raise ValueError(f"""The size dictionary must have keys 'height' and 'width'. Got {size.keys()}"""    )
					return center_crop(_SCREAMING_SNAKE_CASE     ,       size=(size['height'], size['width'])     ,       data_format=_SCREAMING_SNAKE_CASE     ,       **_SCREAMING_SNAKE_CASE    )





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





					"""simple docstring"""


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





	def 			_lowerCAmelCase     (      self				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       np.ndarray     ,       _SCREAMING_SNAKE_CASE				:       Union[float, List[float]]     ,       _SCREAMING_SNAKE_CASE				:       Union[float, List[float]]     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[str, ChannelDimension]] = None     ,       **_SCREAMING_SNAKE_CASE				:       Tuple     ,       )						->	np.ndarray:





					"""simple docstring"""


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







	def 			_lowerCAmelCase     (      self				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       ImageInput     ,       _SCREAMING_SNAKE_CASE				:       bool = None     ,       _SCREAMING_SNAKE_CASE				:       Dict[str, int] = None     ,       _SCREAMING_SNAKE_CASE				:       int=None     ,       _SCREAMING_SNAKE_CASE				:       bool = None     ,       _SCREAMING_SNAKE_CASE				:       Dict[str, int] = None     ,       _SCREAMING_SNAKE_CASE				:       bool = None     ,       _SCREAMING_SNAKE_CASE				:       float = None     ,       _SCREAMING_SNAKE_CASE				:       bool = None     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[float, List[float]]] = None     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[float, List[float]]] = None     ,       _SCREAMING_SNAKE_CASE				:       Optional[Union[str, TensorType]] = None     ,       _SCREAMING_SNAKE_CASE				:       ChannelDimension = ChannelDimension.FIRST     ,       **_SCREAMING_SNAKE_CASE				:       List[Any]     ,       )						->	PIL.Image.Image:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[int]							=     do_resize if do_resize is not None else self.do_resize
					SCREAMING_SNAKE_CASE						:							List[str]							=     resample if resample is not None else self.resample
					SCREAMING_SNAKE_CASE						:							int							=     do_center_crop if do_center_crop is not None else self.do_center_crop
					SCREAMING_SNAKE_CASE						:							List[str]							=     do_rescale if do_rescale is not None else self.do_rescale
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     rescale_factor if rescale_factor is not None else self.rescale_factor
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     do_normalize if do_normalize is not None else self.do_normalize
					SCREAMING_SNAKE_CASE						:							List[Any]							=     image_mean if image_mean is not None else self.image_mean
					SCREAMING_SNAKE_CASE						:							List[Any]							=     image_std if image_std is not None else self.image_std

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     size if size is not None else self.size
					SCREAMING_SNAKE_CASE						:							str							=     get_size_dict(_SCREAMING_SNAKE_CASE    )
					SCREAMING_SNAKE_CASE						:							Any							=     crop_size if crop_size is not None else self.crop_size
					SCREAMING_SNAKE_CASE						:							Tuple							=     get_size_dict(_SCREAMING_SNAKE_CASE     ,       param_name='crop_size'    )

					SCREAMING_SNAKE_CASE						:							List[str]							=     make_list_of_images(_SCREAMING_SNAKE_CASE    )

					if not valid_images(_SCREAMING_SNAKE_CASE    ):
									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_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.'    )

					# All transformations expect numpy arrays.
					SCREAMING_SNAKE_CASE						:							Optional[int]							=     [to_numpy_array(_SCREAMING_SNAKE_CASE    ) for image in images]

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

					if do_center_crop:
									SCREAMING_SNAKE_CASE						:							int							=     [self.center_crop(image=_SCREAMING_SNAKE_CASE     ,       size=_SCREAMING_SNAKE_CASE    ) for image in images]

					if do_rescale:
									SCREAMING_SNAKE_CASE						:							Optional[Any]							=     [self.rescale(image=_SCREAMING_SNAKE_CASE     ,       scale=_SCREAMING_SNAKE_CASE    ) for image in images]

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

					SCREAMING_SNAKE_CASE						:							List[Any]							=     [to_channel_dimension_format(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ) for image in images]

					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     {'pixel_values': images}
					return BatchFeature(data=_SCREAMING_SNAKE_CASE     ,       tensor_type=_SCREAMING_SNAKE_CASE    )










"""simple docstring"""

from typing import Dict, List, Optional

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


A_						:    Tuple				=      logging.get_logger(__name__)


A_						:    int				=      {
    'nielsr/canine-s': 2048,
}

# Unicode defines 1,114,112 total “codepoints”
A_						:    List[Any]				=      111_4112

# 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_						:    Optional[Any]				=      0

A_						:    int				=      0xE000
A_						:    Any				=      0xE001
A_						:    List[Any]				=      0xE002
A_						:    Optional[Any]				=      0xE003
A_						:    int				=      0xE004

# Maps special codepoints to human-readable names.
A_						:    Dict[int, str]				=      {
    # 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_						:    Dict[str, int]				=      {name: codepoint for codepoint, name in SPECIAL_CODEPOINTS.items()}
class     lowerCAmelCase__						(	_lowerCamelCase ):


	'''simple docstring'''







	_SCREAMING_SNAKE_CASE	:		List[Any]  						= PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES





	def __init__(      self				:       int     ,       _SCREAMING_SNAKE_CASE				:       Any=chr(_SCREAMING_SNAKE_CASE    )     ,       _SCREAMING_SNAKE_CASE				:       int=chr(_SCREAMING_SNAKE_CASE    )     ,       _SCREAMING_SNAKE_CASE				:       Union[str, Any]=chr(_SCREAMING_SNAKE_CASE    )     ,       _SCREAMING_SNAKE_CASE				:       Tuple=chr(_SCREAMING_SNAKE_CASE    )     ,       _SCREAMING_SNAKE_CASE				:       int=chr(_SCREAMING_SNAKE_CASE    )     ,       _SCREAMING_SNAKE_CASE				:       Any=chr(_SCREAMING_SNAKE_CASE    )     ,       _SCREAMING_SNAKE_CASE				:       Optional[Any]=False     ,       _SCREAMING_SNAKE_CASE				:       List[Any]=2_048     ,       **_SCREAMING_SNAKE_CASE				:       Tuple     ,       )						->	List[Any]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     AddedToken(_SCREAMING_SNAKE_CASE     ,       lstrip=_SCREAMING_SNAKE_CASE     ,       rstrip=_SCREAMING_SNAKE_CASE    ) if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ) else bos_token
					SCREAMING_SNAKE_CASE						:							Tuple							=     AddedToken(_SCREAMING_SNAKE_CASE     ,       lstrip=_SCREAMING_SNAKE_CASE     ,       rstrip=_SCREAMING_SNAKE_CASE    ) if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ) else eos_token
					SCREAMING_SNAKE_CASE						:							Any							=     AddedToken(_SCREAMING_SNAKE_CASE     ,       lstrip=_SCREAMING_SNAKE_CASE     ,       rstrip=_SCREAMING_SNAKE_CASE    ) if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ) else sep_token
					SCREAMING_SNAKE_CASE						:							int							=     AddedToken(_SCREAMING_SNAKE_CASE     ,       lstrip=_SCREAMING_SNAKE_CASE     ,       rstrip=_SCREAMING_SNAKE_CASE    ) if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ) else cls_token
					SCREAMING_SNAKE_CASE						:							Dict							=     AddedToken(_SCREAMING_SNAKE_CASE     ,       lstrip=_SCREAMING_SNAKE_CASE     ,       rstrip=_SCREAMING_SNAKE_CASE    ) if isinstance(_SCREAMING_SNAKE_CASE     ,       _SCREAMING_SNAKE_CASE    ) else pad_token

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

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

					# Creates a mapping for looking up the IDs of special symbols.
					SCREAMING_SNAKE_CASE						:							Dict[str, int]							=     {}
					for codepoint, name in SPECIAL_CODEPOINTS.items():
									SCREAMING_SNAKE_CASE						:							str							=     codepoint

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

					SCREAMING_SNAKE_CASE						:							Dict							=     UNICODE_VOCAB_SIZE
					SCREAMING_SNAKE_CASE						:							List[str]							=     len(self._special_codepoints    )





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





					"""simple docstring"""


					return self._unicode_vocab_size





	def 			_lowerCAmelCase     (      self				:       Union[str, Any]     ,       _SCREAMING_SNAKE_CASE				:       str    )						->	List[str]:





					"""simple docstring"""


					return list(_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       int     ,       _SCREAMING_SNAKE_CASE				:       str    )						->	int:





					"""simple docstring"""


					try:
									return ord(_SCREAMING_SNAKE_CASE    )
					except TypeError:
									raise ValueError(f"""invalid token: '{token}'"""    )





	def 			_lowerCAmelCase     (      self				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       int    )						->	str:





					"""simple docstring"""


					try:
									if index in SPECIAL_CODEPOINTS:
													return SPECIAL_CODEPOINTS[index]
									return chr(_SCREAMING_SNAKE_CASE    )
					except TypeError:
									raise ValueError(f"""invalid id: {index}"""    )





	def 			_lowerCAmelCase     (      self				:       Optional[Any]     ,       _SCREAMING_SNAKE_CASE				:       Tuple    )						->	List[str]:





					"""simple docstring"""


					return "".join(_SCREAMING_SNAKE_CASE    )





	def 			_lowerCAmelCase     (      self				:       Dict     ,       _SCREAMING_SNAKE_CASE				:       List[int]     ,       _SCREAMING_SNAKE_CASE				:       Optional[List[int]] = None    )						->	List[int]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							List[str]							=     [self.sep_token_id]
					SCREAMING_SNAKE_CASE						:							Tuple							=     [self.cls_token_id]

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





	def 			_lowerCAmelCase     (      self				:       int     ,       _SCREAMING_SNAKE_CASE				:       List[int]     ,       _SCREAMING_SNAKE_CASE				:       Optional[List[int]] = None     ,       _SCREAMING_SNAKE_CASE				:       bool = False    )						->	List[int]:





					"""simple docstring"""


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

					SCREAMING_SNAKE_CASE						:							int							=     [1] + ([0] * len(_SCREAMING_SNAKE_CASE    )) + [1]
					if token_ids_a is not None:
									result += ([0] * len(_SCREAMING_SNAKE_CASE    )) + [1]
					return result





	def 			_lowerCAmelCase     (      self				:       int     ,       _SCREAMING_SNAKE_CASE				:       List[int]     ,       _SCREAMING_SNAKE_CASE				:       Optional[List[int]] = None    )						->	List[int]:





					"""simple docstring"""


					SCREAMING_SNAKE_CASE						:							Optional[Any]							=     [self.sep_token_id]
					SCREAMING_SNAKE_CASE						:							Dict							=     [self.cls_token_id]

					SCREAMING_SNAKE_CASE						:							Union[str, Any]							=     len(cls + token_ids_a + sep    ) * [0]
					if token_ids_a is not None:
									result += len(token_ids_a + sep    ) * [1]
					return result







	def 			_lowerCAmelCase     (      self				:       Tuple     ,       _SCREAMING_SNAKE_CASE				:       str     ,       _SCREAMING_SNAKE_CASE				:       Optional[str] = None    )						->	Any:





					"""simple docstring"""


					return ()





