

"""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     :
									@staticmethod
									def 							__snake_case	(						*_A ,						**_A       )      ->      str:






										'''simple docstring'''







										pass






@is_pipeline_test
@require_torch_or_tf
@require_vision
class       _UpperCAmelCase     (						unittest.TestCase):
			__a	:    int			   =							MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
			__a	:    List[str]			   =							TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
			def 							__snake_case	(						self ,						_A ,						_A ,						_A       )      ->      int:






				'''simple docstring'''







				_UpperCAmelCase      :							Optional[Any]       =   ImageClassificationPipeline(model=_A ,						image_processor=_A ,						top_k=2       )
				_UpperCAmelCase      :							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 ,						_A ,						_A       )      ->      Dict:






				'''simple docstring'''







				_UpperCAmelCase      :							List[Any]       =   image_classifier("""./tests/fixtures/tests_samples/COCO/000000039769.png"""       )

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

				import datasets

				_UpperCAmelCase      :							Dict       =   datasets.load_dataset("""hf-internal-testing/fixtures_image_utils""" ,						"""image""" ,						split="""test"""       )

				# Accepts URL + PIL.Image + lists
				_UpperCAmelCase      :							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(
				    _A ,						[
				        [
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				        ],
				        [
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				        ],
				        [
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				        ],
				        [
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				        ],
				        [
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				            {"""score""": ANY(_A       ), """label""": ANY(_A       )},
				        ],
				    ] ,						)
			@require_torch
			def 							__snake_case	(						self       )      ->      Optional[int]:






				'''simple docstring'''







				_UpperCAmelCase      :							Tuple       =   """hf-internal-testing/tiny-random-vit"""
				_UpperCAmelCase      :							List[Any]       =   pipeline("""image-classification""" ,						model=_A       )

				_UpperCAmelCase      :							List[str]       =   image_classifier("""http://images.cocodataset.org/val2017/000000039769.jpg"""       )
				self.assertEqual(
				    nested_simplify(_A ,						decimals=4       ) ,						[{"""label""": """LABEL_1""", """score""": 0.574}, {"""label""": """LABEL_0""", """score""": 0.426}] ,						)

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






				'''simple docstring'''







				_UpperCAmelCase      :							Any       =   """hf-internal-testing/tiny-random-vit"""
				_UpperCAmelCase      :							List[str]       =   pipeline("""image-classification""" ,						model=_A ,						framework="""tf"""       )

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

				_UpperCAmelCase      :							Any       =   image_classifier(
				    [
				        """http://images.cocodataset.org/val2017/000000039769.jpg""",
				        """http://images.cocodataset.org/val2017/000000039769.jpg""",
				    ] ,						top_k=2 ,						)
				self.assertEqual(
				    nested_simplify(_A ,						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       )      ->      Tuple:






				'''simple docstring'''







				_UpperCAmelCase      :							List[str]       =   PreTrainedTokenizer()

				# Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
				_UpperCAmelCase      :							List[Any]       =   pipeline(
				    """image-classification""" ,						model="""hf-internal-testing/tiny-random-vit""" ,						tokenizer=_A       )

				self.assertIs(image_classifier.tokenizer ,						_A       )
			@slow
			@require_torch
			def 							__snake_case	(						self       )      ->      List[str]:






				'''simple docstring'''







				_UpperCAmelCase      :							Union[str, Any]       =   pipeline("""image-classification""" ,						model="""deepmind/vision-perceiver-conv"""       )
				_UpperCAmelCase      :							List[Any]       =   image_classifier("""http://images.cocodataset.org/val2017/000000039769.jpg"""       )
				self.assertEqual(
				    nested_simplify(_A ,						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"""},
				    ] ,						)

				_UpperCAmelCase      :							List[Any]       =   pipeline("""image-classification""" ,						model="""deepmind/vision-perceiver-fourier"""       )
				_UpperCAmelCase      :							Any       =   image_classifier("""http://images.cocodataset.org/val2017/000000039769.jpg"""       )
				self.assertEqual(
				    nested_simplify(_A ,						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"""},
				    ] ,						)

				_UpperCAmelCase      :							Optional[Any]       =   pipeline("""image-classification""" ,						model="""deepmind/vision-perceiver-learned"""       )
				_UpperCAmelCase      :							Optional[int]       =   image_classifier("""http://images.cocodataset.org/val2017/000000039769.jpg"""       )
				self.assertEqual(
				    nested_simplify(_A ,						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"""},
				    ] ,						)








"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


lowerCamelCase__			:					int							  =					{'''configuration_qdqbert''': ['''QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''QDQBertConfig''']}

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__			:					Optional[int]							  =					[
						    '''QDQBERT_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''QDQBertForMaskedLM''',
						    '''QDQBertForMultipleChoice''',
						    '''QDQBertForNextSentencePrediction''',
						    '''QDQBertForQuestionAnswering''',
						    '''QDQBertForSequenceClassification''',
						    '''QDQBertForTokenClassification''',
						    '''QDQBertLayer''',
						    '''QDQBertLMHeadModel''',
						    '''QDQBertModel''',
						    '''QDQBertPreTrainedModel''',
						    '''load_tf_weights_in_qdqbert''',
						]


if TYPE_CHECKING:
						from .configuration_qdqbert import QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, QDQBertConfig

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_qdqbert import (
												    QDQBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
												    QDQBertForMaskedLM,
												    QDQBertForMultipleChoice,
												    QDQBertForNextSentencePrediction,
												    QDQBertForQuestionAnswering,
												    QDQBertForSequenceClassification,
												    QDQBertForTokenClassification,
												    QDQBertLayer,
												    QDQBertLMHeadModel,
												    QDQBertModel,
												    QDQBertPreTrainedModel,
												    load_tf_weights_in_qdqbert,
												)


else:
						import sys

						lowerCamelCase__			:					Optional[Any]							  =					_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





