'''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 convert_to_rgb, 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


if is_vision_available():
						import PIL


__lowercase        =    logging.get_logger(__name__)






class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






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



			def __init__(  self			,       __lowerCAmelCase = True			,       __lowerCAmelCase = None			,       __lowerCAmelCase = PILImageResampling.BICUBIC			,       __lowerCAmelCase = True			,       __lowerCAmelCase = 1 / 255			,       __lowerCAmelCase = True			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = True			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					super().__init__(**__lowerCAmelCase)
					lowerCAmelCase     =    size if size is not None else {"""height""": 384, """width""": 384}
					lowerCAmelCase     =    get_size_dict(__lowerCAmelCase			,       default_to_square=__lowerCAmelCase)

					lowerCAmelCase     =    do_resize
					lowerCAmelCase     =    size
					lowerCAmelCase     =    resample
					lowerCAmelCase     =    do_rescale
					lowerCAmelCase     =    rescale_factor
					lowerCAmelCase     =    do_normalize
					lowerCAmelCase     =    image_mean if image_mean is not None else OPENAI_CLIP_MEAN
					lowerCAmelCase     =    image_std if image_std is not None else OPENAI_CLIP_STD
					lowerCAmelCase     =    do_convert_rgb



			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase			,       __lowerCAmelCase = PILImageResampling.BICUBIC			,       __lowerCAmelCase = None			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					lowerCAmelCase     =    get_size_dict(__lowerCAmelCase			,       default_to_square=__lowerCAmelCase)
					if "height" not in size or "width" not in size:
							raise ValueError(f"The `size` dictionary must contain the keys `height` and `width`. Got {size.keys()}")
					lowerCAmelCase     =    (size["""height"""], size["""width"""])
					return resize(__lowerCAmelCase			,       size=__lowerCAmelCase			,       resample=__lowerCAmelCase			,       data_format=__lowerCAmelCase			,       **__lowerCAmelCase)



			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase			,       __lowerCAmelCase = None			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


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



			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase			,       __lowerCAmelCase			,       __lowerCAmelCase = None			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


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







			def 				a_			(  self			,       __lowerCAmelCase			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = ChannelDimension.FIRST			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					lowerCAmelCase     =    do_resize if do_resize is not None else self.do_resize
					lowerCAmelCase     =    resample if resample is not None else self.resample
					lowerCAmelCase     =    do_rescale if do_rescale is not None else self.do_rescale
					lowerCAmelCase     =    rescale_factor if rescale_factor is not None else self.rescale_factor
					lowerCAmelCase     =    do_normalize if do_normalize is not None else self.do_normalize
					lowerCAmelCase     =    image_mean if image_mean is not None else self.image_mean
					lowerCAmelCase     =    image_std if image_std is not None else self.image_std
					lowerCAmelCase     =    do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

					lowerCAmelCase     =    size if size is not None else self.size
					lowerCAmelCase     =    get_size_dict(__lowerCAmelCase			,       default_to_square=__lowerCAmelCase)

					lowerCAmelCase     =    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 or resample is None:
							raise ValueError("""Size and resample must be specified if do_resize 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:
							lowerCAmelCase     =    [convert_to_rgb(__lowerCAmelCase) for image in images]

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

					if do_resize:
							lowerCAmelCase     =    [self.resize(image=__lowerCAmelCase			,       size=__lowerCAmelCase			,       resample=__lowerCAmelCase) for image in images]

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

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

					lowerCAmelCase     =    [to_channel_dimension_format(__lowerCAmelCase			,       __lowerCAmelCase) for image in images]

					lowerCAmelCase     =    BatchFeature(data={"""pixel_values""": images}			,       tensor_type=__lowerCAmelCase)

					return encoded_outputs





'''simple docstring'''




import warnings
from typing import List, Optional, Union

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType






class 							a__(   lowerCAmelCase__      ):


			'''simple docstring'''






			UpperCAmelCase_     :	str						=			['''image_processor''', '''tokenizer''']
			UpperCAmelCase_     :	str						=			'''ViltImageProcessor'''
			UpperCAmelCase_     :	Any						=			('''BertTokenizer''', '''BertTokenizerFast''')



			def __init__(  self			,       __lowerCAmelCase=None			,       __lowerCAmelCase=None			,       **__lowerCAmelCase):




					"""simple docstring"""


					lowerCAmelCase     =    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			,       )
							lowerCAmelCase     =    kwargs.pop("""feature_extractor""")

					lowerCAmelCase     =    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)
					lowerCAmelCase     =    self.image_processor



			def __call__(  self			,       __lowerCAmelCase			,       __lowerCAmelCase = None			,       __lowerCAmelCase = True			,       __lowerCAmelCase = False			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = 0			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = None			,       __lowerCAmelCase = False			,       __lowerCAmelCase = False			,       __lowerCAmelCase = False			,       __lowerCAmelCase = False			,       __lowerCAmelCase = True			,       __lowerCAmelCase = None			,       **__lowerCAmelCase			,       ):




					"""simple docstring"""


					lowerCAmelCase     =    self.tokenizer(
					    text=__lowerCAmelCase			,       add_special_tokens=__lowerCAmelCase			,       padding=__lowerCAmelCase			,       truncation=__lowerCAmelCase			,       max_length=__lowerCAmelCase			,       stride=__lowerCAmelCase			,       pad_to_multiple_of=__lowerCAmelCase			,       return_token_type_ids=__lowerCAmelCase			,       return_attention_mask=__lowerCAmelCase			,       return_overflowing_tokens=__lowerCAmelCase			,       return_special_tokens_mask=__lowerCAmelCase			,       return_offsets_mapping=__lowerCAmelCase			,       return_length=__lowerCAmelCase			,       verbose=__lowerCAmelCase			,       return_tensors=__lowerCAmelCase			,       **__lowerCAmelCase			,       )
					# add pixel_values + pixel_mask
					lowerCAmelCase     =    self.image_processor(__lowerCAmelCase			,       return_tensors=__lowerCAmelCase)
					encoding.update(__lowerCAmelCase)

					return encoding



			def 				a_			(  self			,       *__lowerCAmelCase			,       **__lowerCAmelCase):




					"""simple docstring"""


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



			def 				a_			(  self			,       *__lowerCAmelCase			,       **__lowerCAmelCase):




					"""simple docstring"""


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



			@property
			def 				a_			(  self):




					"""simple docstring"""


					lowerCAmelCase     =    self.tokenizer.model_input_names
					lowerCAmelCase     =    self.image_processor.model_input_names
					return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names))



			@property
			def 				a_			(  self):




					"""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 				a_			(  self):




					"""simple docstring"""


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




