
from typing import Dict, List, Optional, Union

import numpy as np

from transformers.utils import is_vision_available
from transformers.utils.generic import TensorType

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_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_valid_image,
    to_numpy_array,
    valid_images,
)
from ...utils import logging


if is_vision_available():
		import PIL

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




def 			_SCREAMING_SNAKE_CASE      (	_lowerCamelCase				:    Tuple)      ->					List[List[ImageInput]]:






							'''simple docstring'''





							if isinstance(_lowerCamelCase		,						(list, tuple)) and isinstance(videos[0]		,						(list, tuple)) and is_valid_image(videos[0][0]):
														return videos

							elif isinstance(_lowerCamelCase		,						(list, tuple)) and is_valid_image(videos[0]):
														return [videos]

							elif is_valid_image(_lowerCamelCase):
														return [[videos]]

							raise ValueError(F'Could not make batched video from {videos}')




class 				lowerCamelCase__							(       __lowercase):




	'''simple docstring'''




	_A			=  ['pixel_values']







	def __init__(      self	:List[str]  ,     a	:bool = True  ,     a	:Dict[str, int] = None  ,     a	:PILImageResampling = PILImageResampling.BILINEAR  ,     a	:bool = True  ,     a	:Dict[str, int] = None  ,     a	:bool = True  ,     a	:Union[int, float] = 1 / 2_5_5  ,     a	:bool = True  ,     a	:bool = True  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     **a	:Tuple  ,     )	->				None:
								super().__init__(**a		)
								__UpperCamelCase			:     int         =      size if size is not None else {"shortest_edge": 2_5_6}
								__UpperCamelCase			:     Optional[int]         =      get_size_dict(a  ,     default_to_square=a		)
								__UpperCamelCase			:     Tuple         =      crop_size if crop_size is not None else {"height": 2_2_4, "width": 2_2_4}
								__UpperCamelCase			:     Optional[int]         =      get_size_dict(a  ,     param_name="crop_size"		)

								__UpperCamelCase			:     List[Any]         =      do_resize
								__UpperCamelCase			:     str         =      size
								__UpperCamelCase			:     Optional[int]         =      do_center_crop
								__UpperCamelCase			:     Union[str, Any]         =      crop_size
								__UpperCamelCase			:     Tuple         =      resample
								__UpperCamelCase			:     Union[str, Any]         =      do_rescale
								__UpperCamelCase			:     List[Any]         =      rescale_factor
								__UpperCamelCase			:     Dict         =      offset
								__UpperCamelCase			:     Any         =      do_normalize
								__UpperCamelCase			:     str         =      image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
								__UpperCamelCase			:     Union[str, Any]         =      image_std if image_std is not None else IMAGENET_STANDARD_STD







	def      _lowerCamelCase       (      self	:str  ,     a	:np.ndarray  ,     a	:Dict[str, int]  ,     a	:PILImageResampling = PILImageResampling.BILINEAR  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:List[str]  ,     )	->				np.ndarray:
								__UpperCamelCase			:     Optional[int]         =      get_size_dict(a  ,     default_to_square=a		)
								if "shortest_edge" in size:
															__UpperCamelCase			:     List[Any]         =      get_resize_output_image_size(a  ,     size["shortest_edge"]  ,     default_to_square=a		)
								elif "height" in size and "width" in size:
															__UpperCamelCase			:     Tuple         =      (size["height"], size["width"])
								else:
															raise ValueError(f'Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'		)
								return resize(a  ,     size=a  ,     resample=a  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:List[str]  ,     a	:np.ndarray  ,     a	:Dict[str, int]  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:Union[str, Any]  ,     )	->				np.ndarray:
								__UpperCamelCase			:     Optional[Any]         =      get_size_dict(a		)
								if "height" not in size or "width" not in size:
															raise ValueError(f'Size must have \'height\' and \'width\' as keys. Got {size.keys()}'		)
								return center_crop(a  ,     size=(size["height"], size["width"])  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:List[str]  ,     a	:np.ndarray  ,     a	:Union[int, float]  ,     a	:bool = True  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:int  ,     )	->				List[str]:
								__UpperCamelCase			:     str         =      image.astype(np.floataa		)
								if offset:
															__UpperCamelCase			:     Dict         =      image - (scale / 2)
								return rescale(a  ,     scale=a  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:int  ,     a	:np.ndarray  ,     a	:Union[float, List[float]]  ,     a	:Union[float, List[float]]  ,     a	:Optional[Union[str, ChannelDimension]] = None  ,     **a	:Tuple  ,     )	->				np.ndarray:
								return normalize(a  ,     mean=a  ,     std=a  ,     data_format=a  ,     **a		)







	def      _lowerCamelCase       (      self	:Dict  ,     a	:ImageInput  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:PILImageResampling = None  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:bool = None  ,     a	:float = None  ,     a	:bool = None  ,     a	:bool = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[ChannelDimension] = ChannelDimension.FIRST  ,     )	->				np.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."		)

								if offset and not do_rescale:
															raise ValueError("For offset, do_rescale must also be set to True."		)

								# All transformations expect numpy arrays.
								__UpperCamelCase			:     List[str]         =      to_numpy_array(a		)

								if do_resize:
															__UpperCamelCase			:     str         =      self.resize(image=a  ,     size=a  ,     resample=a		)

								if do_center_crop:
															__UpperCamelCase			:     List[Any]         =      self.center_crop(a  ,     size=a		)

								if do_rescale:
															__UpperCamelCase			:     Any         =      self.rescale(image=a  ,     scale=a  ,     offset=a		)

								if do_normalize:
															__UpperCamelCase			:     Optional[int]         =      self.normalize(image=a  ,     mean=a  ,     std=a		)

								__UpperCamelCase			:     List[Any]         =      to_channel_dimension_format(a  ,     a		)
								return image







	def      _lowerCamelCase       (      self	:Any  ,     a	:ImageInput  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:PILImageResampling = None  ,     a	:bool = None  ,     a	:Dict[str, int] = None  ,     a	:bool = None  ,     a	:float = None  ,     a	:bool = None  ,     a	:bool = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[float, List[float]]] = None  ,     a	:Optional[Union[str, TensorType]] = None  ,     a	:ChannelDimension = ChannelDimension.FIRST  ,     **a	:Optional[int]  ,     )	->				PIL.Image.Image:
								__UpperCamelCase			:     Tuple         =      do_resize if do_resize is not None else self.do_resize
								__UpperCamelCase			:     Optional[Any]         =      resample if resample is not None else self.resample
								__UpperCamelCase			:     str         =      do_center_crop if do_center_crop is not None else self.do_center_crop
								__UpperCamelCase			:     Tuple         =      do_rescale if do_rescale is not None else self.do_rescale
								__UpperCamelCase			:     int         =      rescale_factor if rescale_factor is not None else self.rescale_factor
								__UpperCamelCase			:     int         =      offset if offset is not None else self.offset
								__UpperCamelCase			:     List[str]         =      do_normalize if do_normalize is not None else self.do_normalize
								__UpperCamelCase			:     Union[str, Any]         =      image_mean if image_mean is not None else self.image_mean
								__UpperCamelCase			:     List[Any]         =      image_std if image_std is not None else self.image_std

								__UpperCamelCase			:     Union[str, Any]         =      size if size is not None else self.size
								__UpperCamelCase			:     int         =      get_size_dict(a  ,     default_to_square=a		)
								__UpperCamelCase			:     Tuple         =      crop_size if crop_size is not None else self.crop_size
								__UpperCamelCase			:     int         =      get_size_dict(a  ,     param_name="crop_size"		)

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

								__UpperCamelCase			:     str         =      make_batched(a		)

								__UpperCamelCase			:     Optional[Any]         =      [
								    [
								        self._preprocess_image(
								            image=a  ,     do_resize=a  ,     size=a  ,     resample=a  ,     do_center_crop=a  ,     crop_size=a  ,     do_rescale=a  ,     rescale_factor=a  ,     offset=a  ,     do_normalize=a  ,     image_mean=a  ,     image_std=a  ,     data_format=a  ,     )
								        for img in video
								    ]
								    for video in videos
								]

								__UpperCamelCase			:     int         =      {"pixel_values": videos}
								return BatchFeature(data=a  ,     tensor_type=a		)

import re
import string

import numpy as np

import datasets


lowercase						:      List[str]									= '\nReturns the rate at which the input predicted strings exactly match their references, ignoring any strings input as part of the regexes_to_ignore list.\n'

lowercase						:      List[str]									= '\nArgs:\n    predictions: List of predicted texts.\n    references: List of reference texts.\n    regexes_to_ignore: List, defaults to None. Regex expressions of characters to\n        ignore when calculating the exact matches. Note: these regexes are removed\n        from the input data before the changes based on the options below (e.g. ignore_case,\n        ignore_punctuation, ignore_numbers) are applied.\n    ignore_case: Boolean, defaults to False. If true, turns everything\n        to lowercase so that capitalization differences are ignored.\n    ignore_punctuation: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\n    ignore_numbers: Boolean, defaults to False. If true, removes all punctuation before\n        comparing predictions and references.\nReturns:\n    exact_match: Dictionary containing exact_match rate. Possible values are between 0.0 and 100.0, inclusive.\nExamples:\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    25.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    50.0\n\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True)\n    >>> print(round(results["exact_match"], 1))\n    75.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["the cat", "theater", "YELLING", "agent007"]\n    >>> preds = ["cat?", "theater", "yelling", "agent"]\n    >>> results = exact_match.compute(references=refs, predictions=preds, regexes_to_ignore=["the ", "yell", "YELL"], ignore_case=True, ignore_punctuation=True, ignore_numbers=True)\n    >>> print(round(results["exact_match"], 1))\n    100.0\n\n    >>> exact_match = datasets.load_metric("exact_match")\n    >>> refs = ["The cat sat on the mat.", "Theaters are great.", "It\'s like comparing oranges and apples."]\n    >>> preds = ["The cat sat on the mat?", "Theaters are great.", "It\'s like comparing apples and oranges."]\n    >>> results = exact_match.compute(references=refs, predictions=preds)\n    >>> print(round(results["exact_match"], 1))\n    33.3\n\n'

lowercase						:      List[str]									= '\n'




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION  ,		_KWARGS_DESCRIPTION)
class 				lowerCamelCase__							(       datasets.Metric):




	'''simple docstring'''




	def      _lowerCamelCase       (      self	:Dict		)	->				Optional[Any]:
								return datasets.MetricInfo(
								    description=_DESCRIPTION  ,     citation=_CITATION  ,     inputs_description=_KWARGS_DESCRIPTION  ,     features=datasets.Features(
								        {
								            "predictions": datasets.Value("string"  ,     id="sequence"		),
								            "references": datasets.Value("string"  ,     id="sequence"		),
								        }		)  ,     reference_urls=[]  ,     )







	def      _lowerCamelCase       (      self	:int  ,     a	:Optional[Any]  ,     a	:Dict  ,     a	:Optional[int]=None  ,     a	:int=False  ,     a	:Tuple=False  ,     a	:Optional[int]=False  ,     )	->				Any:
								if regexes_to_ignore is not None:
															for s in regexes_to_ignore:
																						__UpperCamelCase			:     List[Any]         =      np.array([re.sub(a  ,     ""  ,     a		) for x in predictions]		)
																						__UpperCamelCase			:     Optional[Any]         =      np.array([re.sub(a  ,     ""  ,     a		) for x in references]		)
								else:
															__UpperCamelCase			:     Optional[int]         =      np.asarray(a		)
															__UpperCamelCase			:     List[str]         =      np.asarray(a		)

								if ignore_case:
															__UpperCamelCase			:     Optional[int]         =      np.char.lower(a		)
															__UpperCamelCase			:     str         =      np.char.lower(a		)

								if ignore_punctuation:
															__UpperCamelCase			:     Tuple         =      string.punctuation.maketrans(""  ,     ""  ,     string.punctuation		)
															__UpperCamelCase			:     int         =      np.char.translate(a  ,     table=a		)
															__UpperCamelCase			:     str         =      np.char.translate(a  ,     table=a		)

								if ignore_numbers:
															__UpperCamelCase			:     List[str]         =      string.digits.maketrans(""  ,     ""  ,     string.digits		)
															__UpperCamelCase			:     Tuple         =      np.char.translate(a  ,     table=a		)
															__UpperCamelCase			:     Union[str, Any]         =      np.char.translate(a  ,     table=a		)

								__UpperCamelCase			:     List[Any]         =      predictions == references

								return {"exact_match": np.mean(a		) * 1_0_0}