



"""simple docstring"""







import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import MobileNetVaImageProcessor

class 			_a     (   unittest.TestCase):



			def __init__( self       :							Union[str, Any]      ,  _lowercase       :							List[Any]      ,  _lowercase       :							str=7      ,  _lowercase       :							Any=3      ,  _lowercase       :							int=18      ,  _lowercase       :							List[str]=30      ,  _lowercase       :							Optional[Any]=400      ,  _lowercase       :							int=True      ,  _lowercase       :							Union[str, Any]=None      ,  _lowercase       :							Any=True      ,  _lowercase       :							List[Any]=None      ,  )       ->				Any:
									snake_case      : List[str]							=   size if size is not None else {"shortest_edge": 20}
									snake_case      : Dict							=   crop_size if crop_size is not None else {"height": 18, "width": 18}
									snake_case      : List[Any]							=   parent
									snake_case      : str							=   batch_size
									snake_case      : int							=   num_channels
									snake_case      : List[str]							=   image_size
									snake_case      : Optional[Any]							=   min_resolution
									snake_case      : List[str]							=   max_resolution
									snake_case      : str							=   do_resize
									snake_case      : List[str]							=   size
									snake_case      : Dict							=   do_center_crop
									snake_case      : str							=   crop_size



			def 							__lowercase				( self       :							Tuple		)       ->				Union[str, Any]:
									return {
									    "do_resize": self.do_resize,
									    "size": self.size,
									    "do_center_crop": self.do_center_crop,
									    "crop_size": self.crop_size,
									}



@require_torch
@require_vision
class 			_a     (   SCREAMING_SNAKE_CASE__    ,  unittest.TestCase):
			__magic_name__    				=    MobileNetVaImageProcessor if is_vision_available() else None



			def 							__lowercase				( self       :							Dict		)       ->				Any:
									snake_case      : str							=   MobileNetVaImageProcessingTester(self		)



			@property
			def 							__lowercase				( self       :							Dict		)       ->				Optional[Any]:
									return self.image_processor_tester.prepare_image_processor_dict()



			def 							__lowercase				( self       :							Dict		)       ->				List[str]:
									snake_case      : List[str]							=   self.image_processing_class(**self.image_processor_dict		)
									self.assertTrue(hasattr(_lowercase      ,  "do_resize"		)		)
									self.assertTrue(hasattr(_lowercase      ,  "size"		)		)
									self.assertTrue(hasattr(_lowercase      ,  "do_center_crop"		)		)
									self.assertTrue(hasattr(_lowercase      ,  "center_crop"		)		)



			def 							__lowercase				( self       :							Any		)       ->				str:
									snake_case      : List[str]							=   self.image_processing_class.from_dict(self.image_processor_dict		)
									self.assertEqual(image_processor.size      ,  {"shortest_edge": 20}		)
									self.assertEqual(image_processor.crop_size      ,  {"height": 18, "width": 18}		)

									snake_case      : Union[str, Any]							=   self.image_processing_class.from_dict(self.image_processor_dict      ,  size=42      ,  crop_size=84		)
									self.assertEqual(image_processor.size      ,  {"shortest_edge": 42}		)
									self.assertEqual(image_processor.crop_size      ,  {"height": 84, "width": 84}		)



			def 							__lowercase				( self       :							Tuple		)       ->				Optional[Any]:
									pass



			def 							__lowercase				( self       :							Optional[int]		)       ->				Optional[Any]:
									# Initialize image_processing
									snake_case      : Tuple							=   self.image_processing_class(**self.image_processor_dict		)
									# create random PIL images
									snake_case      : int							=   prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=_lowercase		)
									for image in image_inputs:
															self.assertIsInstance(_lowercase      ,  Image.Image		)

									# Test not batched input
									snake_case      : Optional[Any]							=   image_processing(image_inputs[0]      ,  return_tensors="pt"		).pixel_values
									self.assertEqual(
									    encoded_images.shape      ,  (
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )      ,  )

									# Test batched
									snake_case      : Optional[Any]							=   image_processing(_lowercase      ,  return_tensors="pt"		).pixel_values
									self.assertEqual(
									    encoded_images.shape      ,  (
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )      ,  )



			def 							__lowercase				( self       :							Union[str, Any]		)       ->				Optional[Any]:
									# Initialize image_processing
									snake_case      : Dict							=   self.image_processing_class(**self.image_processor_dict		)
									# create random numpy tensors
									snake_case      : Union[str, Any]							=   prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=_lowercase      ,  numpify=_lowercase		)
									for image in image_inputs:
															self.assertIsInstance(_lowercase      ,  np.ndarray		)

									# Test not batched input
									snake_case      : List[str]							=   image_processing(image_inputs[0]      ,  return_tensors="pt"		).pixel_values
									self.assertEqual(
									    encoded_images.shape      ,  (
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )      ,  )

									# Test batched
									snake_case      : str							=   image_processing(_lowercase      ,  return_tensors="pt"		).pixel_values
									self.assertEqual(
									    encoded_images.shape      ,  (
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )      ,  )



			def 							__lowercase				( self       :							int		)       ->				Union[str, Any]:
									# Initialize image_processing
									snake_case      : Dict							=   self.image_processing_class(**self.image_processor_dict		)
									# create random PyTorch tensors
									snake_case      : Any							=   prepare_image_inputs(self.image_processor_tester      ,  equal_resolution=_lowercase      ,  torchify=_lowercase		)
									for image in image_inputs:
															self.assertIsInstance(_lowercase      ,  torch.Tensor		)

									# Test not batched input
									snake_case      : List[Any]							=   image_processing(image_inputs[0]      ,  return_tensors="pt"		).pixel_values
									self.assertEqual(
									    encoded_images.shape      ,  (
									        1,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )      ,  )

									# Test batched
									snake_case      : Optional[Any]							=   image_processing(_lowercase      ,  return_tensors="pt"		).pixel_values
									self.assertEqual(
									    encoded_images.shape      ,  (
									        self.image_processor_tester.batch_size,
									        self.image_processor_tester.num_channels,
									        self.image_processor_tester.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )      ,  )








"""simple docstring"""







from sklearn.metrics import accuracy_score

import datasets


A    =	'\nAccuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with:\nAccuracy = (TP + TN) / (TP + TN + FP + FN)\n Where:\nTP: True positive\nTN: True negative\nFP: False positive\nFN: False negative\n'


A    =	'\nArgs:\n    predictions (`list` of `int`): Predicted labels.\n    references (`list` of `int`): Ground truth labels.\n    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.\n    sample_weight (`list` of `float`): Sample weights Defaults to None.\n\nReturns:\n    accuracy (`float` or `int`): Accuracy score. Minimum possible value is 0. Maximum possible value is 1.0, or the number of examples input, if `normalize` is set to `True`.. A higher score means higher accuracy.\n\nExamples:\n\n    Example 1-A simple example\n        >>> accuracy_metric = datasets.load_metric("accuracy")\n        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])\n        >>> print(results)\n        {\'accuracy\': 0.5}\n\n    Example 2-The same as Example 1, except with `normalize` set to `False`.\n        >>> accuracy_metric = datasets.load_metric("accuracy")\n        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)\n        >>> print(results)\n        {\'accuracy\': 3.0}\n\n    Example 3-The same as Example 1, except with `sample_weight` set.\n        >>> accuracy_metric = datasets.load_metric("accuracy")\n        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], sample_weight=[0.5, 2, 0.7, 0.5, 9, 0.4])\n        >>> print(results)\n        {\'accuracy\': 0.8778625954198473}\n'


A    =	'\n@article{scikit-learn,\n  title={Scikit-learn: Machine Learning in {P}ython},\n  author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.\n         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.\n         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and\n         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},\n  journal={Journal of Machine Learning Research},\n  volume={12},\n  pages={2825--2830},\n  year={2011}\n}\n'

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



			def 							__lowercase				( self       :							List[Any]		)       ->				List[str]:
									return datasets.MetricInfo(
									    description=_DESCRIPTION      ,  citation=_CITATION      ,  inputs_description=_KWARGS_DESCRIPTION      ,  features=datasets.Features(
									        {
									            "predictions": datasets.Sequence(datasets.Value("int32"		)		),
									            "references": datasets.Sequence(datasets.Value("int32"		)		),
									        }
									        if self.config_name == "multilabel"
									        else {
									            "predictions": datasets.Value("int32"		),
									            "references": datasets.Value("int32"		),
									        }		)      ,  reference_urls=["https://scikit-learn.org/stable/modules/generated/sklearn.metrics.accuracy_score.html"]      ,  )



			def 							__lowercase				( self       :							str      ,  _lowercase       :							Optional[int]      ,  _lowercase       :							Tuple      ,  _lowercase       :							Union[str, Any]=True      ,  _lowercase       :							int=None		)       ->				Any:
									return {
									    "accuracy": float(
									        accuracy_score(_lowercase      ,  _lowercase      ,  normalize=_lowercase      ,  sample_weight=_lowercase		)		)
									}



