

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


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import TvltImageProcessor




def  UpperCamelCase(	UpperCAmelCase_    ,			UpperCAmelCase_=10    ,			UpperCAmelCase_=10    ,			UpperCAmelCase_=False    ,			UpperCAmelCase_=False      ):
 UpperCAmelCase			:      Optional[Any]		   =					[]
 for i in range(image_processor_tester.num_frames      ):
  video.append(np.random.randint(2_55    ,			size=(image_processor_tester.num_channels, width, height)    ,			dtype=np.uinta      )      )

 if not numpify and not torchify:
  # PIL expects the channel dimension as last dimension
  UpperCAmelCase			:      Optional[Any]		   =					[Image.fromarray(np.moveaxis(UpperCAmelCase_    ,			0    ,			-1      )      ) for frame in video]

 if torchify:
  UpperCAmelCase			:      List[str]		   =					[torch.from_numpy(UpperCAmelCase_      ) for frame in video]

 return video




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

 UpperCAmelCase			:      str		   =					[]
 for i in range(image_processor_tester.batch_size      ):
  if equal_resolution:
   UpperCAmelCase			:      Tuple		   =					image_processor_tester.max_resolution
  else:
   UpperCAmelCase   ,					UpperCAmelCase			:      Optional[int]		   =					np.random.choice(
       np.arange(image_processor_tester.min_resolution    ,			image_processor_tester.max_resolution      )    ,			2      )
   UpperCAmelCase			:      Dict		   =					prepare_video(
       image_processor_tester=UpperCAmelCase_    ,			width=UpperCAmelCase_    ,			height=UpperCAmelCase_    ,			numpify=UpperCAmelCase_    ,			torchify=UpperCAmelCase_    ,			)
  video_inputs.append(UpperCAmelCase_      )

 return video_inputs




class 			A_					(							unittest.TestCase				):






     '''simple docstring'''



     def __init__(						self					:	Tuple	,     lowercase_					:	List[Any]	,     lowercase_					:	str=7	,     lowercase_					:	List[str]=3	,     lowercase_					:	Dict=4	,     lowercase_					:	Dict=18	,     lowercase_					:	int=30	,     lowercase_					:	Tuple=400	,     lowercase_					:	Dict=True	,     lowercase_					:	Union[str, Any]=None	,     lowercase_					:	int=True	,     lowercase_					:	Tuple=[0.5, 0.5, 0.5]	,     lowercase_					:	int=[0.5, 0.5, 0.5]	,     lowercase_					:	str=True	,     lowercase_					:	int=None	,     )		->      List[str]:
      UpperCAmelCase			:      Tuple		   =					size if size is not None else {'shortest_edge': 18}
      UpperCAmelCase			:      List[str]		   =					crop_size if crop_size is not None else {'height': 18, 'width': 18}

      UpperCAmelCase			:      Optional[Any]		   =					parent
      UpperCAmelCase			:      List[str]		   =					batch_size
      UpperCAmelCase			:      int		   =					num_channels
      UpperCAmelCase			:      Dict		   =					num_frames
      UpperCAmelCase			:      Tuple		   =					image_size
      UpperCAmelCase			:      str		   =					min_resolution
      UpperCAmelCase			:      Dict		   =					max_resolution
      UpperCAmelCase			:      Optional[Any]		   =					do_resize
      UpperCAmelCase			:      Optional[int]		   =					size
      UpperCAmelCase			:      Dict		   =					do_normalize
      UpperCAmelCase			:      Optional[int]		   =					image_mean
      UpperCAmelCase			:      List[str]		   =					image_std
      UpperCAmelCase			:      List[str]		   =					do_center_crop
      UpperCAmelCase			:      Optional[int]		   =					crop_size




     def   UpperCAmelCase_			(						self					:	Union[str, Any]			)		->      Tuple:
      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "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_					(							_snake_case			,  unittest.TestCase				):






     '''simple docstring'''



     UpperCAmelCase_		:      Optional[int]    						=    TvltImageProcessor if is_vision_available() else None


     def   UpperCAmelCase_			(						self					:	Dict			)		->      Optional[Any]:
      UpperCAmelCase			:      Dict		   =					TvltImageProcessorTester(self			)


     @property
     def   UpperCAmelCase_			(						self					:	str			)		->      Any:
      return self.image_processor_tester.prepare_image_processor_dict()


     def   UpperCAmelCase_			(						self					:	Any			)		->      Optional[int]:
      UpperCAmelCase			:      Tuple		   =					self.image_processing_class(**self.image_processor_dict			)
      self.assertTrue(hasattr(lowercase_	,     'image_mean'			)			)
      self.assertTrue(hasattr(lowercase_	,     'image_std'			)			)
      self.assertTrue(hasattr(lowercase_	,     'do_normalize'			)			)
      self.assertTrue(hasattr(lowercase_	,     'do_resize'			)			)
      self.assertTrue(hasattr(lowercase_	,     'do_center_crop'			)			)
      self.assertTrue(hasattr(lowercase_	,     'size'			)			)


     def   UpperCAmelCase_			(						self					:	Union[str, Any]			)		->      Optional[Any]:
      # Initialize image_processor
      UpperCAmelCase			:      Tuple		   =					self.image_processing_class(**self.image_processor_dict			)
      # create random PIL videos
      UpperCAmelCase			:      Any		   =					prepare_video_inputs(self.image_processor_tester	,     equal_resolution=lowercase_			)
      for video in video_inputs:
       self.assertIsInstance(lowercase_	,     lowercase_			)
       self.assertIsInstance(video[0]	,     Image.Image			)

      # Test not batched input
      UpperCAmelCase			:      Optional[int]		   =					image_processor(video_inputs[0]	,     return_tensors='pt'			).pixel_values
      self.assertEqual(
          encoded_videos.shape	,     (
              1,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )	,     )

      # Test batched
      UpperCAmelCase			:      Union[str, Any]		   =					image_processor(lowercase_	,     return_tensors='pt'			).pixel_values
      self.assertEqual(
          encoded_videos.shape	,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )	,     )


     def   UpperCAmelCase_			(						self					:	Any			)		->      Dict:
      # Initialize image_processor
      UpperCAmelCase			:      Dict		   =					self.image_processing_class(**self.image_processor_dict			)
      # create random numpy tensors
      UpperCAmelCase			:      Tuple		   =					prepare_video_inputs(self.image_processor_tester	,     equal_resolution=lowercase_	,     numpify=lowercase_			)
      for video in video_inputs:
       self.assertIsInstance(lowercase_	,     lowercase_			)
       self.assertIsInstance(video[0]	,     np.ndarray			)

      # Test not batched input
      UpperCAmelCase			:      Dict		   =					image_processor(video_inputs[0]	,     return_tensors='pt'			).pixel_values
      self.assertEqual(
          encoded_videos.shape	,     (
              1,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )	,     )

      # Test batched
      UpperCAmelCase			:      Dict		   =					image_processor(lowercase_	,     return_tensors='pt'			).pixel_values
      self.assertEqual(
          encoded_videos.shape	,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )	,     )




     def   UpperCAmelCase_			(						self					:	Optional[Any]			)		->      List[Any]:
      # Initialize image_processor
      UpperCAmelCase			:      Optional[int]		   =					self.image_processing_class(**self.image_processor_dict			)
      # create random PyTorch tensors
      UpperCAmelCase			:      int		   =					prepare_video_inputs(self.image_processor_tester	,     equal_resolution=lowercase_	,     torchify=lowercase_			)
      for video in video_inputs:
       self.assertIsInstance(lowercase_	,     lowercase_			)
       self.assertIsInstance(video[0]	,     torch.Tensor			)

      # Test not batched input
      UpperCAmelCase			:      List[str]		   =					image_processor(video_inputs[0]	,     return_tensors='pt'			).pixel_values
      self.assertEqual(
          encoded_videos.shape	,     (
              1,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size['height'],
              self.image_processor_tester.crop_size['width'],
          )	,     )

      # Test batched
      UpperCAmelCase			:      List[str]		   =					image_processor(lowercase_	,     return_tensors='pt'			).pixel_values
      self.assertEqual(
          encoded_videos.shape	,     (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_frames,
              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


lowercase__            =     "\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"


lowercase__            =     "\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"


lowercase__            =     "\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				):






     '''simple docstring'''



     def   UpperCAmelCase_			(						self					:	int			)		->      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   UpperCAmelCase_			(						self					:	str	,     lowercase_					:	Union[str, Any]	,     lowercase_					:	Any	,     lowercase_					:	Tuple=True	,     lowercase_					:	Union[str, Any]=None			)		->      Dict:
      return {
          "accuracy": float(
              accuracy_score(lowercase_	,     lowercase_	,     normalize=lowercase_	,     sample_weight=lowercase_			)			)
      }




