



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 						lowerCamelCase_     :






													'''simple docstring'''







													@staticmethod
													def       SCREAMING_SNAKE_CASE__		(						*__lowerCamelCase   :      List[Any]						,						**__lowerCamelCase   :      Optional[int]			)   ->					Any:
																pass

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






						'''simple docstring'''
						a__ =	MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
						a__ =	TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING







						def       SCREAMING_SNAKE_CASE__		(						self   :      Any						,						__lowerCamelCase   :      Optional[int]						,						__lowerCamelCase   :      Dict						,						__lowerCamelCase   :      Any			)   ->					List[Any]:
									A				:       List[Any]														=    ImageClassificationPipeline(model=__lowerCamelCase						,						image_processor=__lowerCamelCase						,						top_k=2			)
									A				:       List[Any]														=    [
									    Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"			),
									    "http://images.cocodataset.org/val2017/000000039769.jpg",
									]
									return image_classifier, examples







						def       SCREAMING_SNAKE_CASE__		(						self   :      List[Any]						,						__lowerCamelCase   :      Optional[int]						,						__lowerCamelCase   :      Tuple			)   ->					List[Any]:
									A				:       Any														=    image_classifier("./tests/fixtures/tests_samples/COCO/000000039769.png"			)

									self.assertEqual(
									    __lowerCamelCase						,						[
									        {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									        {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									    ]						,						)

									import datasets

									A				:       Optional[Any]														=    datasets.load_dataset("hf-internal-testing/fixtures_image_utils"						,						"image"						,						split="test"			)

									# Accepts URL + PIL.Image + lists
									A				:       Optional[int]														=    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(
									    __lowerCamelCase						,						[
									        [
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									        ],
									        [
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									        ],
									        [
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									        ],
									        [
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									        ],
									        [
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									            {"score": ANY(__lowerCamelCase			), "label": ANY(__lowerCamelCase			)},
									        ],
									    ]						,						)







						@require_torch
						def       SCREAMING_SNAKE_CASE__		(						self   :      Any			)   ->					Any:
									A				:       Optional[Any]														=    "hf-internal-testing/tiny-random-vit"
									A				:       str														=    pipeline("image-classification"						,						model=__lowerCamelCase			)

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

									A				:       str														=    image_classifier(
									    [
									        "http://images.cocodataset.org/val2017/000000039769.jpg",
									        "http://images.cocodataset.org/val2017/000000039769.jpg",
									    ]						,						top_k=2						,						)
									self.assertEqual(
									    nested_simplify(__lowerCamelCase						,						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       SCREAMING_SNAKE_CASE__		(						self   :      List[str]			)   ->					Dict:
									A				:       Optional[Any]														=    "hf-internal-testing/tiny-random-vit"
									A				:       Tuple														=    pipeline("image-classification"						,						model=__lowerCamelCase						,						framework="tf"			)

									A				:       Optional[Any]														=    image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"			)
									self.assertEqual(
									    nested_simplify(__lowerCamelCase						,						decimals=4			)						,						[{"label": "LABEL_1", "score": 0.574}, {"label": "LABEL_0", "score": 0.426}]						,						)

									A				:       Optional[int]														=    image_classifier(
									    [
									        "http://images.cocodataset.org/val2017/000000039769.jpg",
									        "http://images.cocodataset.org/val2017/000000039769.jpg",
									    ]						,						top_k=2						,						)
									self.assertEqual(
									    nested_simplify(__lowerCamelCase						,						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       SCREAMING_SNAKE_CASE__		(						self   :      int			)   ->					Optional[int]:
									A				:       Tuple														=    PreTrainedTokenizer()

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

									self.assertIs(image_classifier.tokenizer						,						__lowerCamelCase			)







						@slow
						@require_torch
						def       SCREAMING_SNAKE_CASE__		(						self   :      int			)   ->					Union[str, Any]:
									# 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
									A				:       Dict														=    pipeline("image-classification"						,						model="deepmind/vision-perceiver-conv"			)
									A				:       Optional[int]														=    image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"			)
									self.assertEqual(
									    nested_simplify(__lowerCamelCase						,						decimals=4			)						,						[
									        {"score": 0.4385, "label": "tabby, tabby cat"},
									        {"score": 0.321, "label": "tiger cat"},
									        {"score": 0.0502, "label": "Egyptian cat"},
									        {"score": 0.0137, "label": "crib, cot"},
									        {"score": 0.007, "label": "radiator"},
									    ]						,						)

									A				:       Dict														=    pipeline("image-classification"						,						model="deepmind/vision-perceiver-fourier"			)
									A				:       str														=    image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"			)
									self.assertEqual(
									    nested_simplify(__lowerCamelCase						,						decimals=4			)						,						[
									        {"score": 0.5658, "label": "tabby, tabby cat"},
									        {"score": 0.1309, "label": "tiger cat"},
									        {"score": 0.0722, "label": "Egyptian cat"},
									        {"score": 0.0707, "label": "remote control, remote"},
									        {"score": 0.0082, "label": "computer keyboard, keypad"},
									    ]						,						)

									A				:       Optional[int]														=    pipeline("image-classification"						,						model="deepmind/vision-perceiver-learned"			)
									A				:       List[Any]														=    image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"			)
									self.assertEqual(
									    nested_simplify(__lowerCamelCase						,						decimals=4			)						,						[
									        {"score": 0.3022, "label": "tabby, tabby cat"},
									        {"score": 0.2362, "label": "Egyptian cat"},
									        {"score": 0.1856, "label": "tiger cat"},
									        {"score": 0.0324, "label": "remote control, remote"},
									        {"score": 0.0096, "label": "quilt, comforter, comfort, puff"},
									    ]						,						)




import math
from decimal import Decimal, getcontext




def 						UpperCAmelCase (    _lowerCamelCase = 400_0000     ):

			try:
						A				:       Any														=    int(_lowerCamelCase     )
			except (TypeError, ValueError):
						raise TypeError("Parameter n must be int or castable to int."     )
			if n <= 0:
						raise ValueError("Parameter n must be greater than or equal to one."     )
			A				:       int														=    100
			A				:       Tuple														=    (Decimal(5     ) ** Decimal(0.5     ) + 1) / Decimal(2     )

			A				:       str														=    (math.floor(math.log(n * (phi + 2)			,     _lowerCamelCase     ) - 1     ) // 3) * 3 + 2
			A				:       Optional[int]														=    Decimal(round(phi ** Decimal(index + 1     )     )     ) / (phi + 2)
			A				:       str														=    num // 2
			return int(_lowerCamelCase     )


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