




'''simple docstring'''






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

a_					:    str          =    logging.get_logger(__name__)






def 	_A				(lowerCAmelCase__  :int		)   ->  List[List[ImageInput]]:




     '''simple docstring'''



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

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

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

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






class  a     (     _UpperCAmelCase       ):
 _lowerCAmelCase 					=	["""pixel_values"""]
 def __init__( self      ,				__magic_name__ = True      ,				__magic_name__ = None      ,				__magic_name__ = PILImageResampling.BILINEAR      ,				__magic_name__ = True      ,				__magic_name__ = None      ,				__magic_name__ = True      ,				__magic_name__ = 1 / 2_55      ,				__magic_name__ = True      ,				__magic_name__ = True      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				**__magic_name__      ,				)					->							int:
      super().__init__(**lowercase__						)
      _a			      =							size if size is not None else {"shortest_edge": 2_56}
      _a			      =							get_size_dict(lowercase__      ,				default_to_square=lowercase__						)
      _a			      =							crop_size if crop_size is not None else {"height": 2_24, "width": 2_24}
      _a			      =							get_size_dict(lowercase__      ,				param_name='crop_size'						)

      _a			      =							do_resize
      _a			      =							size
      _a			      =							do_center_crop
      _a			      =							crop_size
      _a			      =							resample
      _a			      =							do_rescale
      _a			      =							rescale_factor
      _a			      =							offset
      _a			      =							do_normalize
      _a			      =							image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
      _a			      =							image_std if image_std is not None else IMAGENET_STANDARD_STD
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__ = PILImageResampling.BILINEAR      ,				__magic_name__ = None      ,				**__magic_name__      ,				)					->							str:
      _a			      =							get_size_dict(lowercase__      ,				default_to_square=lowercase__						)
      if "shortest_edge" in size:
           _a			      =							get_resize_output_image_size(lowercase__      ,				size['shortest_edge']      ,				default_to_square=lowercase__						)
      elif "height" in size and "width" in size:
           _a			      =							(size["height"], size["width"])
      else:
           raise ValueError(f'Size must have \'height\' and \'width\' or \'shortest_edge\' as keys. Got {size.keys()}'						)
      return resize(lowercase__      ,				size=lowercase__      ,				resample=lowercase__      ,				data_format=lowercase__      ,				**lowercase__						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__ = None      ,				**__magic_name__      ,				)					->							Optional[int]:
      _a			      =							get_size_dict(lowercase__						)
      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(lowercase__      ,				size=(size['height'], size['width'])      ,				data_format=lowercase__      ,				**lowercase__						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__ = True      ,				__magic_name__ = None      ,				**__magic_name__      ,				)					->							Union[str, Any]:
      _a			      =							image.astype(np.floataa						)
      if offset:
           _a			      =							image - (scale / 2)
      return rescale(lowercase__      ,				scale=lowercase__      ,				data_format=lowercase__      ,				**lowercase__						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__      ,				__magic_name__ = None      ,				**__magic_name__      ,				)					->							Dict:
      return normalize(lowercase__      ,				mean=lowercase__      ,				std=lowercase__      ,				data_format=lowercase__      ,				**lowercase__						)
 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = ChannelDimension.FIRST      ,				)					->							Tuple:






      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.
      _a			      =							to_numpy_array(lowercase__						)

      if do_resize:
           _a			      =							self.resize(image=lowercase__      ,				size=lowercase__      ,				resample=lowercase__						)

      if do_center_crop:
           _a			      =							self.center_crop(lowercase__      ,				size=lowercase__						)

      if do_rescale:
           _a			      =							self.rescale(image=lowercase__      ,				scale=lowercase__      ,				offset=lowercase__						)

      if do_normalize:
           _a			      =							self.normalize(image=lowercase__      ,				mean=lowercase__      ,				std=lowercase__						)

      _a			      =							to_channel_dimension_format(lowercase__      ,				lowercase__						)
      return image




 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = None      ,				__magic_name__ = ChannelDimension.FIRST      ,				**__magic_name__      ,				)					->							int:
      _a			      =							do_resize if do_resize is not None else self.do_resize
      _a			      =							resample if resample is not None else self.resample
      _a			      =							do_center_crop if do_center_crop is not None else self.do_center_crop
      _a			      =							do_rescale if do_rescale is not None else self.do_rescale
      _a			      =							rescale_factor if rescale_factor is not None else self.rescale_factor
      _a			      =							offset if offset is not None else self.offset
      _a			      =							do_normalize if do_normalize is not None else self.do_normalize
      _a			      =							image_mean if image_mean is not None else self.image_mean
      _a			      =							image_std if image_std is not None else self.image_std

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

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

      _a			      =							make_batched(lowercase__						)

      _a			      =							[
          [
              self._preprocess_image(
                  image=lowercase__      ,				do_resize=lowercase__      ,				size=lowercase__      ,				resample=lowercase__      ,				do_center_crop=lowercase__      ,				crop_size=lowercase__      ,				do_rescale=lowercase__      ,				rescale_factor=lowercase__      ,				offset=lowercase__      ,				do_normalize=lowercase__      ,				image_mean=lowercase__      ,				image_std=lowercase__      ,				data_format=lowercase__      ,				)
              for img in video
          ]
          for video in videos
      ]

      _a			      =							{"pixel_values": videos}
      return BatchFeature(data=lowercase__      ,				tensor_type=lowercase__						)





'''simple docstring'''






import datasets


a_					:    List[Any]          =    "\\n@InProceedings{conneau2018xnli,\n  author = \"Conneau, Alexis\n                 and Rinott, Ruty\n                 and Lample, Guillaume\n                 and Williams, Adina\n                 and Bowman, Samuel R.\n                 and Schwenk, Holger\n                 and Stoyanov, Veselin\",\n  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",\n  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods\n               in Natural Language Processing\",\n  year = \"2018\",\n  publisher = \"Association for Computational Linguistics\",\n  location = \"Brussels, Belgium\",\n}\n"

a_					:    Optional[Any]          =    "\\nXNLI is a subset of a few thousand examples from MNLI which has been translated\ninto a 14 different languages (some low-ish resource). As with MNLI, the goal is\nto predict textual entailment (does sentence A imply/contradict/neither sentence\nB) and is a classification task (given two sentences, predict one of three\nlabels).\n"

a_					:    Optional[Any]          =    "\nComputes XNLI score which is just simple accuracy.\nArgs:\n    predictions: Predicted labels.\n    references: Ground truth labels.\nReturns:\n    'accuracy': accuracy\nExamples:\n\n    >>> predictions = [0, 1]\n    >>> references = [0, 1]\n    >>> xnli_metric = datasets.load_metric(\"xnli\")\n    >>> results = xnli_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'accuracy': 1.0}\n"






def 	_A				(lowerCAmelCase__  :List[Any]				,						lowerCAmelCase__  :Tuple		)   ->  Dict:




     '''simple docstring'''



     return (preds == labels).mean()






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION  ,				_KWARGS_DESCRIPTION       )
class  a     (     datasets.Metric       ):
 def 							__UpperCAmelCase		( self						)					->							Dict:
      return datasets.MetricInfo(
          description=_DESCRIPTION      ,				citation=_CITATION      ,				inputs_description=_KWARGS_DESCRIPTION      ,				features=datasets.Features(
              {
                  'predictions': datasets.Value('int64' if self.config_name != 'sts-b' else 'float32'						),
                  'references': datasets.Value('int64' if self.config_name != 'sts-b' else 'float32'						),
              }						)      ,				codebase_urls=[]      ,				reference_urls=[]      ,				format='numpy'      ,				)




 def 							__UpperCAmelCase		( self      ,				__magic_name__      ,				__magic_name__						)					->							Dict:
      return {"accuracy": simple_accuracy(__magic_name__      ,				__magic_name__						)}

