




"""simple docstring"""





import unittest

from transformers import is_vision_available
from transformers.pipelines import pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
					from PIL import Image
else:



					class   a__					:


								@staticmethod
								def    a_  (   *UpperCamelCase_   :     Tuple   ,	**UpperCamelCase_   :     Tuple):


											"""simple docstring"""




											pass



@is_pipeline_test
@require_vision
class   a__					(						unittest.TestCase ):


			@require_torch
			def    a_  (   self   :     Optional[Any]):


						"""simple docstring"""




						__UpperCAmelCase						:			List[Any]												=       pipeline(
						    model="hf-internal-testing/tiny-random-clip-zero-shot-image-classification"   ,	)
						__UpperCAmelCase						:			int												=       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
						__UpperCAmelCase						:			Dict												=       image_classifier(UpperCamelCase_   ,	candidate_labels=["a", "b", "c"])

						# The floating scores are so close, we enter floating error approximation and the order is not guaranteed across
						# python and torch versions.
						self.assertIn(
						    nested_simplify(UpperCamelCase_)   ,	[
						        [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "b"}, {"score": 0.333, "label": "c"}],
						        [{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "c"}, {"score": 0.333, "label": "b"}],
						    ]   ,	)

						__UpperCAmelCase						:			Union[str, Any]												=       image_classifier([image] * 5   ,	candidate_labels=["A", "B", "C"]   ,	batch_size=2)
						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						    ]   ,	)


			@require_tf
			def    a_  (   self   :     str):


						"""simple docstring"""




						__UpperCAmelCase						:			Optional[int]												=       pipeline(
						    model="hf-internal-testing/tiny-random-clip-zero-shot-image-classification"   ,	framework="tf")
						__UpperCAmelCase						:			List[Any]												=       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
						__UpperCAmelCase						:			str												=       image_classifier(UpperCamelCase_   ,	candidate_labels=["a", "b", "c"])

						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[{"score": 0.333, "label": "a"}, {"score": 0.333, "label": "b"}, {"score": 0.333, "label": "c"}]   ,	)

						__UpperCAmelCase						:			str												=       image_classifier([image] * 5   ,	candidate_labels=["A", "B", "C"]   ,	batch_size=2)
						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						        [
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						            {"score": 0.333, "label": ANY(UpperCamelCase_)},
						        ],
						    ]   ,	)


			@slow
			@require_torch
			def    a_  (   self   :     Union[str, Any]):


						"""simple docstring"""




						__UpperCAmelCase						:			Optional[Any]												=       pipeline(
						    task="zero-shot-image-classification"   ,	model="openai/clip-vit-base-patch32"   ,	)
						# This is an image of 2 cats with remotes and no planes
						__UpperCAmelCase						:			Dict												=       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
						__UpperCAmelCase						:			Optional[int]												=       image_classifier(UpperCamelCase_   ,	candidate_labels=["cat", "plane", "remote"])

						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[
						        {"score": 0.511, "label": "remote"},
						        {"score": 0.485, "label": "cat"},
						        {"score": 0.004, "label": "plane"},
						    ]   ,	)

						__UpperCAmelCase						:			Dict												=       image_classifier([image] * 5   ,	candidate_labels=["cat", "plane", "remote"]   ,	batch_size=2)
						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[
						        [
						            {"score": 0.511, "label": "remote"},
						            {"score": 0.485, "label": "cat"},
						            {"score": 0.004, "label": "plane"},
						        ],
						    ]
						    * 5   ,	)


			@slow
			@require_tf
			def    a_  (   self   :     List[str]):


						"""simple docstring"""




						__UpperCAmelCase						:			Optional[int]												=       pipeline(
						    task="zero-shot-image-classification"   ,	model="openai/clip-vit-base-patch32"   ,	framework="tf")
						# This is an image of 2 cats with remotes and no planes
						__UpperCAmelCase						:			Tuple												=       Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png")
						__UpperCAmelCase						:			str												=       image_classifier(UpperCamelCase_   ,	candidate_labels=["cat", "plane", "remote"])
						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[
						        {"score": 0.511, "label": "remote"},
						        {"score": 0.485, "label": "cat"},
						        {"score": 0.004, "label": "plane"},
						    ]   ,	)

						__UpperCAmelCase						:			Union[str, Any]												=       image_classifier([image] * 5   ,	candidate_labels=["cat", "plane", "remote"]   ,	batch_size=2)
						self.assertEqual(
						    nested_simplify(UpperCamelCase_)   ,	[
						        [
						            {"score": 0.511, "label": "remote"},
						            {"score": 0.485, "label": "cat"},
						            {"score": 0.004, "label": "plane"},
						        ],
						    ]
						    * 5   ,	)



from collections import OrderedDict
from typing import Mapping

from packaging import version

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig
from ...utils import logging


_SCREAMING_SNAKE_CASE 		=      logging.get_logger(__name__)

_SCREAMING_SNAKE_CASE 		=      {
    """sail/poolformer_s12""": """https://huggingface.co/sail/poolformer_s12/resolve/main/config.json""",
    # See all PoolFormer models at https://huggingface.co/models?filter=poolformer
}
class SCREAMING_SNAKE_CASE_		(      __lowerCAmelCase		):
   __lowerCAmelCase           =				"""poolformer"""







   def __init__(     self						:						str   ,   lowerCamelCase_						:						Any=3   ,   lowerCamelCase_						:						Any=16   ,   lowerCamelCase_						:						Any=16   ,   lowerCamelCase_						:						Optional[Any]=3   ,   lowerCamelCase_						:						List[str]=4.0   ,   lowerCamelCase_						:						Tuple=[2, 2, 6, 2]   ,   lowerCamelCase_						:						Optional[Any]=[64, 128, 320, 512]   ,   lowerCamelCase_						:						Tuple=[7, 3, 3, 3]   ,   lowerCamelCase_						:						Optional[Any]=[4, 2, 2, 2]   ,   lowerCamelCase_						:						Dict=[2, 1, 1, 1]   ,   lowerCamelCase_						:						Tuple=4   ,   lowerCamelCase_						:						Optional[int]=0.0   ,   lowerCamelCase_						:						Union[str, Any]="gelu"   ,   lowerCamelCase_						:						Union[str, Any]=True   ,   lowerCamelCase_						:						Union[str, Any]=1E-5   ,   lowerCamelCase_						:						int=0.0_2   ,   **lowerCamelCase_						:						str   ,   ):





    """simple docstring"""


    UpperCamelCase			  =      num_channels
    UpperCamelCase			  =      patch_size
    UpperCamelCase			  =      stride
    UpperCamelCase			  =      padding
    UpperCamelCase			  =      pool_size
    UpperCamelCase			  =      hidden_sizes
    UpperCamelCase			  =      mlp_ratio
    UpperCamelCase			  =      depths
    UpperCamelCase			  =      patch_sizes
    UpperCamelCase			  =      strides
    UpperCamelCase			  =      num_encoder_blocks
    UpperCamelCase			  =      drop_path_rate
    UpperCamelCase			  =      hidden_act
    UpperCamelCase			  =      use_layer_scale
    UpperCamelCase			  =      layer_scale_init_value
    UpperCamelCase			  =      initializer_range
    super().__init__(**lowerCamelCase_				)





class SCREAMING_SNAKE_CASE_		(      __lowerCAmelCase		):
   __lowerCAmelCase           =				version.parse("""1.11"""		)







   @property
   def 						lowerCamelCase_	(     self						:						Any				):





    """simple docstring"""


    return OrderedDict(
        [
            ("""pixel_values""", {0: """batch""", 1: """num_channels""", 2: """height""", 3: """width"""}),
        ]				)







   @property
   def 						lowerCamelCase_	(     self						:						Any				):





    """simple docstring"""


    return 2E-3
