


'''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 ConvNextImageProcessor







class        __magic_name__  (					unittest.TestCase   ):

     """simple docstring"""






     def __init__(      self ,    lowerCamelCase ,    lowerCamelCase=7 ,    lowerCamelCase=3 ,    lowerCamelCase=18 ,    lowerCamelCase=30 ,    lowerCamelCase=400 ,    lowerCamelCase=True ,    lowerCamelCase=None ,    lowerCamelCase=0.875 ,    lowerCamelCase=True ,    lowerCamelCase=[0.5, 0.5, 0.5] ,    lowerCamelCase=[0.5, 0.5, 0.5] ,    ):


          '''simple docstring'''





          __A  :					Any						     =       size if size is not None else {"shortest_edge": 20}
          __A  :					int						     =       parent
          __A  :					int						     =       batch_size
          __A  :					str						     =       num_channels
          __A  :					Optional[int]						     =       image_size
          __A  :					Optional[Any]						     =       min_resolution
          __A  :					List[Any]						     =       max_resolution
          __A  :					Dict						     =       do_resize
          __A  :					List[Any]						     =       size
          __A  :					Union[str, Any]						     =       crop_pct
          __A  :					Any						     =       do_normalize
          __A  :					Optional[int]						     =       image_mean
          __A  :					Tuple						     =       image_std


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          return {
              "image_mean": self.image_mean,
              "image_std": self.image_std,
              "do_normalize": self.do_normalize,
              "do_resize": self.do_resize,
              "size": self.size,
              "crop_pct": self.crop_pct,
          }







@require_torch
@require_vision
class        __magic_name__  (					UpperCAmelCase__						,		unittest.TestCase   ):

     """simple docstring"""






     lowerCamelCase__						=							ConvNextImageProcessor if is_vision_available() else None


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          __A  :					List[Any]						     =       ConvNextImageProcessingTester(self		)


     @property
     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          return self.image_processor_tester.prepare_image_processor_dict()


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          __A  :					Dict						     =       self.image_processing_class(**self.image_processor_dict		)
          self.assertTrue(hasattr(lowerCamelCase__ ,    "do_resize"		)		)
          self.assertTrue(hasattr(lowerCamelCase__ ,    "size"		)		)
          self.assertTrue(hasattr(lowerCamelCase__ ,    "crop_pct"		)		)
          self.assertTrue(hasattr(lowerCamelCase__ ,    "do_normalize"		)		)
          self.assertTrue(hasattr(lowerCamelCase__ ,    "image_mean"		)		)
          self.assertTrue(hasattr(lowerCamelCase__ ,    "image_std"		)		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          __A  :					Dict						     =       self.image_processing_class.from_dict(self.image_processor_dict		)
          self.assertEqual(image_processor.size ,    {"shortest_edge": 20}		)

          __A  :					List[Any]						     =       self.image_processing_class.from_dict(self.image_processor_dict ,    size=42		)
          self.assertEqual(image_processor.size ,    {"shortest_edge": 42}		)


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          pass


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          __A  :					Tuple						     =       self.image_processing_class(**self.image_processor_dict		)
          # create random PIL images
          __A  :					Union[str, Any]						     =       prepare_image_inputs(self.image_processor_tester ,    equal_resolution=lowerCamelCase__		)
          for image in image_inputs:
               self.assertIsInstance(lowerCamelCase__ ,    Image.Image		)

          # Test not batched input
          __A  :					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.size["shortest_edge"],
                  self.image_processor_tester.size["shortest_edge"],
              ) ,    )

          # Test batched
          __A  :					Optional[Any]						     =       image_processing(lowerCamelCase__ ,    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.size["shortest_edge"],
                  self.image_processor_tester.size["shortest_edge"],
              ) ,    )


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          __A  :					int						     =       self.image_processing_class(**self.image_processor_dict		)
          # create random numpy tensors
          __A  :					List[str]						     =       prepare_image_inputs(self.image_processor_tester ,    equal_resolution=lowerCamelCase__ ,    numpify=lowerCamelCase__		)
          for image in image_inputs:
               self.assertIsInstance(lowerCamelCase__ ,    np.ndarray		)

          # Test not batched input
          __A  :					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.size["shortest_edge"],
                  self.image_processor_tester.size["shortest_edge"],
              ) ,    )

          # Test batched
          __A  :					List[Any]						     =       image_processing(lowerCamelCase__ ,    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.size["shortest_edge"],
                  self.image_processor_tester.size["shortest_edge"],
              ) ,    )


     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          __A  :					List[str]						     =       self.image_processing_class(**self.image_processor_dict		)
          # create random PyTorch tensors
          __A  :					Tuple						     =       prepare_image_inputs(self.image_processor_tester ,    equal_resolution=lowerCamelCase__ ,    torchify=lowerCamelCase__		)
          for image in image_inputs:
               self.assertIsInstance(lowerCamelCase__ ,    torch.Tensor		)

          # Test not batched input
          __A  :					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.size["shortest_edge"],
                  self.image_processor_tester.size["shortest_edge"],
              ) ,    )

          # Test batched
          __A  :					int						     =       image_processing(lowerCamelCase__ ,    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.size["shortest_edge"],
                  self.image_processor_tester.size["shortest_edge"],
              ) ,    )





'''simple docstring'''


from sklearn.metrics import accuracy_score

import datasets


_UpperCamelCase          =     """
Accuracy is the proportion of correct predictions among the total number of cases processed. It can be computed with:
Accuracy = (TP + TN) / (TP + TN + FP + FN)
 Where:
TP: True positive
TN: True negative
FP: False positive
FN: False negative
"""


_UpperCamelCase          =     """
Args:
    predictions (`list` of `int`): Predicted labels.
    references (`list` of `int`): Ground truth labels.
    normalize (`boolean`): If set to False, returns the number of correctly classified samples. Otherwise, returns the fraction of correctly classified samples. Defaults to True.
    sample_weight (`list` of `float`): Sample weights Defaults to None.

Returns:
    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.

Examples:

    Example 1-A simple example
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0])
        >>> print(results)
        {'accuracy': 0.5}

    Example 2-The same as Example 1, except with `normalize` set to `False`.
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> results = accuracy_metric.compute(references=[0, 1, 2, 0, 1, 2], predictions=[0, 1, 1, 2, 1, 0], normalize=False)
        >>> print(results)
        {'accuracy': 3.0}

    Example 3-The same as Example 1, except with `sample_weight` set.
        >>> accuracy_metric = datasets.load_metric(\"accuracy\")
        >>> 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])
        >>> print(results)
        {'accuracy': 0.8778625954198473}
"""


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







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

     """simple docstring"""






     def lowerCAmelCase__     (      self		):


          '''simple docstring'''





          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 lowerCAmelCase__     (      self ,    lowerCamelCase ,    lowerCamelCase ,    lowerCamelCase=True ,    lowerCamelCase=None		):


          '''simple docstring'''





          return {
              "accuracy": float(
                  accuracy_score(lowerCamelCase ,    lowerCamelCase ,    normalize=lowerCamelCase ,    sample_weight=lowerCamelCase		)		)
          }

