





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


if is_torch_available():
							import torch

if is_vision_available():
							from PIL import Image

							from transformers import BlipImageProcessor

class    __A  (    unittest.TestCase     ):


				def __init__(		self ,			UpperCAmelCase_ ,			UpperCAmelCase_=7 ,			UpperCAmelCase_=3 ,			UpperCAmelCase_=18 ,			UpperCAmelCase_=30 ,			UpperCAmelCase_=400 ,			UpperCAmelCase_=True ,			UpperCAmelCase_=None ,			UpperCAmelCase_=True ,			UpperCAmelCase_=False ,			UpperCAmelCase_=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3] ,			UpperCAmelCase_=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1] ,			UpperCAmelCase_=True ,			):
								lowerCamelCase									=size if size is not None else {"""height""": 20, """width""": 20}
								lowerCamelCase									=parent
								lowerCamelCase									=batch_size
								lowerCamelCase									=num_channels
								lowerCamelCase									=image_size
								lowerCamelCase									=min_resolution
								lowerCamelCase									=max_resolution
								lowerCamelCase									=do_resize
								lowerCamelCase									=size
								lowerCamelCase									=do_normalize
								lowerCamelCase									=image_mean
								lowerCamelCase									=image_std
								lowerCamelCase									=do_pad
								lowerCamelCase									=do_convert_rgb


				def _snake_case							(		self				):
								return {
								    "do_resize": self.do_resize,
								    "size": self.size,
								    "do_normalize": self.do_normalize,
								    "image_mean": self.image_mean,
								    "image_std": self.image_std,
								    "do_convert_rgb": self.do_convert_rgb,
								    "do_pad": self.do_pad,
								}


				def _snake_case							(		self ,			UpperCAmelCase_=False ,			UpperCAmelCase_=False ,			UpperCAmelCase_=False				):
								assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

								if equal_resolution:
												lowerCamelCase									=[]
												for i in range(self.batch_size				):
																image_inputs.append(
																    np.random.randint(
																        255 ,			size=(self.num_channels, self.max_resolution, self.max_resolution) ,			dtype=np.uinta				)				)
								else:
												lowerCamelCase									=[]
												for i in range(self.batch_size				):
																lowerCamelCase			,	lowerCamelCase									=np.random.choice(np.arange(self.min_resolution ,			self.max_resolution				) ,			2				)
																image_inputs.append(np.random.randint(255 ,			size=(self.num_channels, width, height) ,			dtype=np.uinta				)				)

								if not numpify and not torchify:
												# PIL expects the channel dimension as last dimension
												lowerCamelCase									=[Image.fromarray(np.moveaxis(UpperCAmelCase_ ,			0 ,			-1				)				) for x in image_inputs]

								if torchify:
												lowerCamelCase									=[torch.from_numpy(UpperCAmelCase_				) for x in image_inputs]

								return image_inputs




@require_torch
@require_vision
class    __A  (    a     ,       unittest.TestCase     ):
				__A  =					BlipImageProcessor if is_vision_available() else None


				def _snake_case							(		self				):
								lowerCamelCase									=BlipImageProcessingTester(self				)


				@property
				def _snake_case							(		self				):
								return self.image_processor_tester.prepare_image_processor_dict()


				def _snake_case							(		self				):
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_resize"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""size"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_normalize"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""image_mean"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""image_std"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_convert_rgb"""				)				)


				def _snake_case							(		self				):
								pass


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PIL images
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_				)
								for image in image_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			Image.Image				)

								# Test not batched input
								lowerCamelCase									=image_processor(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["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			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["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random numpy tensors
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_ ,			numpify=UpperCAmelCase_				)
								for image in image_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			np.ndarray				)

								# Test not batched input
								lowerCamelCase									=image_processor(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["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			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["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PyTorch tensors
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_ ,			torchify=UpperCAmelCase_				)
								for image in image_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			torch.Tensor				)

								# Test not batched input
								lowerCamelCase									=image_processor(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["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			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["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)




@require_torch
@require_vision
class    __A  (    a     ,       unittest.TestCase     ):
				__A  =					BlipImageProcessor if is_vision_available() else None


				def _snake_case							(		self				):
								lowerCamelCase									=BlipImageProcessingTester(self ,			num_channels=4				)
								lowerCamelCase									=3


				@property
				def _snake_case							(		self				):
								return self.image_processor_tester.prepare_image_processor_dict()


				def _snake_case							(		self				):
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_resize"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""size"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_normalize"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""image_mean"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""image_std"""				)				)
								self.assertTrue(hasattr(UpperCAmelCase_ ,			"""do_convert_rgb"""				)				)


				def _snake_case							(		self				):
								pass


				def _snake_case							(		self				):
								# Initialize image_processor
								lowerCamelCase									=self.image_processing_class(**self.image_processor_dict				)
								# create random PIL images
								lowerCamelCase									=self.image_processor_tester.prepare_inputs(equal_resolution=UpperCAmelCase_				)
								for image in image_inputs:
												self.assertIsInstance(UpperCAmelCase_ ,			Image.Image				)

								# Test not batched input
								lowerCamelCase									=image_processor(image_inputs[0] ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        1,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)

								# Test batched
								lowerCamelCase									=image_processor(UpperCAmelCase_ ,			return_tensors="""pt"""				).pixel_values
								self.assertEqual(
								    encoded_images.shape ,			(
								        self.image_processor_tester.batch_size,
								        self.expected_encoded_image_num_channels,
								        self.image_processor_tester.size["""height"""],
								        self.image_processor_tester.size["""width"""],
								    ) ,			)












from sklearn.metrics import accuracy_score

import datasets


UpperCAmelCase__    :      Optional[Any]       					='''
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__    :      Optional[int]       					='''
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__    :      List[str]       					='''
@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    __A  (    datasets.Metric     ):


				def _snake_case							(		self				):
								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 _snake_case							(		self ,			UpperCAmelCase_ ,			UpperCAmelCase_ ,			UpperCAmelCase_=True ,			UpperCAmelCase_=None				):
								return {
								    "accuracy": float(
								        accuracy_score(UpperCAmelCase_ ,			UpperCAmelCase_ ,			normalize=UpperCAmelCase_ ,			sample_weight=UpperCAmelCase_				)				)
								}





