




"""simple docstring"""






import unittest

from transformers import (
    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    PreTrainedTokenizer,
    is_vision_available,
)
from transformers.pipelines import ImageClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
       from PIL import Image
else:


       class 					UpperCAmelCase		:



           """simple docstring"""

           @staticmethod
           def _snake_case    (     *_UpperCAmelCase					,    **_UpperCAmelCase							):
              pass


@is_pipeline_test
@require_torch_or_tf
@require_vision
class 					UpperCAmelCase		(unittest.TestCase						):



    """simple docstring"""

    _UpperCAmelCase			:Dict							=				MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
    _UpperCAmelCase			:List[Any]							=				TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING






    def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase					,    _UpperCAmelCase							):
       lowercase__:     str      =   ImageClassificationPipeline(model=__snake_case					,    image_processor=__snake_case					,    top_k=2							)
       lowercase__:     List[Any]      =   [
           Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							),
           '''http://images.cocodataset.org/val2017/000000039769.jpg''',
       ]
       return image_classifier, examples






    def _snake_case    (     self					,    _UpperCAmelCase					,    _UpperCAmelCase							):
       lowercase__:     List[Any]      =   image_classifier('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							)

       self.assertEqual(
           __snake_case					,    [
               {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
               {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
           ]					,    )

       import datasets

       lowercase__:     List[str]      =   datasets.load_dataset('''hf-internal-testing/fixtures_image_utils'''					,    '''image'''					,    split='''test'''							)

       # Accepts URL + PIL.Image + lists
       lowercase__:     Optional[Any]      =   image_classifier(
           [
               Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png'''							),
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               # RGBA
               dataset[0]['''file'''],
               # LA
               dataset[1]['''file'''],
               # L
               dataset[2]['''file'''],
           ]							)
       self.assertEqual(
           __snake_case					,    [
               [
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
               ],
               [
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
               ],
               [
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
               ],
               [
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
               ],
               [
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
                   {'''score''': ANY(__snake_case							), '''label''': ANY(__snake_case							)},
               ],
           ]					,    )






    @require_torch
    def _snake_case    (     self							):
       lowercase__:     Dict      =   '''hf-internal-testing/tiny-random-vit'''
       lowercase__:     Dict      =   pipeline('''image-classification'''					,    model=__snake_case							)

       lowercase__:     int      =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}]					,    )

       lowercase__:     Tuple      =   image_classifier(
           [
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           ]					,    top_k=2					,    )
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [
               [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
               [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
           ]					,    )






    @require_tf
    def _snake_case    (     self							):
       lowercase__:     List[str]      =   '''hf-internal-testing/tiny-random-vit'''
       lowercase__:     List[str]      =   pipeline('''image-classification'''					,    model=__snake_case					,    framework='''tf'''							)

       lowercase__:     Union[str, Any]      =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}]					,    )

       lowercase__:     Tuple      =   image_classifier(
           [
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
               '''http://images.cocodataset.org/val2017/000000039769.jpg''',
           ]					,    top_k=2					,    )
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [
               [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
               [{'''label''': '''LABEL_1''', '''score''': 0.574}, {'''label''': '''LABEL_0''', '''score''': 0.426}],
           ]					,    )






    def _snake_case    (     self							):
       lowercase__:     List[Any]      =   PreTrainedTokenizer()

       # Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
       lowercase__:     str      =   pipeline(
           '''image-classification'''					,    model='''hf-internal-testing/tiny-random-vit'''					,    tokenizer=__snake_case							)

       self.assertIs(image_classifier.tokenizer					,    __snake_case							)






    @slow
    @require_torch
    def _snake_case    (     self							):
       # Perceiver is not tested by `run_pipeline_test` properly.
       # That is because the type of feature_extractor and model preprocessor need to be kept
       # in sync, which is not the case in the current design
       lowercase__:     Tuple      =   pipeline('''image-classification'''					,    model='''deepmind/vision-perceiver-conv'''							)
       lowercase__:     int      =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [
               {'''score''': 0.4_385, '''label''': '''tabby, tabby cat'''},
               {'''score''': 0.321, '''label''': '''tiger cat'''},
               {'''score''': 0.0_502, '''label''': '''Egyptian cat'''},
               {'''score''': 0.0_137, '''label''': '''crib, cot'''},
               {'''score''': 0.007, '''label''': '''radiator'''},
           ]					,    )

       lowercase__:     List[str]      =   pipeline('''image-classification'''					,    model='''deepmind/vision-perceiver-fourier'''							)
       lowercase__:     Optional[Any]      =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [
               {'''score''': 0.5_658, '''label''': '''tabby, tabby cat'''},
               {'''score''': 0.1_309, '''label''': '''tiger cat'''},
               {'''score''': 0.0_722, '''label''': '''Egyptian cat'''},
               {'''score''': 0.0_707, '''label''': '''remote control, remote'''},
               {'''score''': 0.0_082, '''label''': '''computer keyboard, keypad'''},
           ]					,    )

       lowercase__:     Optional[Any]      =   pipeline('''image-classification'''					,    model='''deepmind/vision-perceiver-learned'''							)
       lowercase__:     List[Any]      =   image_classifier('''http://images.cocodataset.org/val2017/000000039769.jpg'''							)
       self.assertEqual(
           nested_simplify(__snake_case					,    decimals=4							)					,    [
               {'''score''': 0.3_022, '''label''': '''tabby, tabby cat'''},
               {'''score''': 0.2_362, '''label''': '''Egyptian cat'''},
               {'''score''': 0.1_856, '''label''': '''tiger cat'''},
               {'''score''': 0.0_324, '''label''': '''remote control, remote'''},
               {'''score''': 0.0_096, '''label''': '''quilt, comforter, comfort, puff'''},
           ]					,    )

"""simple docstring"""






def SCREAMING_SNAKE_CASE__    (     __UpperCAmelCase = 1_0_0_0				)						->						int:
   lowercase__:     Union[str, Any]      =   0
   lowercase__:     Any      =   0
   while 1:
      num += 3
      if num >= n:
         break
      total += num
      num += 2
      if num >= n:
         break
      total += num
      num += 1
      if num >= n:
         break
      total += num
      num += 3
      if num >= n:
         break
      total += num
      num += 1
      if num >= n:
         break
      total += num
      num += 2
      if num >= n:
         break
      total += num
      num += 3
      if num >= n:
         break
      total += num
   return total


if __name__ == "__main__":
       print(f'''{solution() = }''')
