code: 
  
  
  
  
  
  
  import inspect
  import unittest
  
  from transformers import ResNetConfig
  from transformers.testing_utils import require_torch, require_vision, slow, torch_device
  from transformers.utils import cached_property, is_torch_available, is_vision_available
  
  from ...test_backbone_common import BackboneTesterMixin
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
   import torch
   from torch import nn
  
   from transformers import ResNetBackbone, ResNetForImageClassification, ResNetModel
   from transformers.models.resnet.modeling_resnet import RESNET_PRETRAINED_MODEL_ARCHIVE_LIST
  
  
  if is_vision_available():
   from PIL import Image
  
   from transformers import AutoImageProcessor
  
  
  
  
  
  class     __a						:
  
  
  
  
  
  
  
   def __init__(	self      :     Optional[Any]							,     SCREAMING_SNAKE_CASE      :     int							,     SCREAMING_SNAKE_CASE      :     List[str]=3							,     SCREAMING_SNAKE_CASE      :     Dict=32							,     SCREAMING_SNAKE_CASE      :     Dict=3							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=10							,     SCREAMING_SNAKE_CASE      :     List[str]=[10, 20, 30, 40]							,     SCREAMING_SNAKE_CASE      :     int=[1, 1, 2, 1]							,     SCREAMING_SNAKE_CASE      :     Optional[int]=True							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=True							,     SCREAMING_SNAKE_CASE      :     Dict="relu"							,     SCREAMING_SNAKE_CASE      :     List[Any]=3							,     SCREAMING_SNAKE_CASE      :     Any=None							,     SCREAMING_SNAKE_CASE      :     Optional[Any]=["stage2", "stage3", "stage4"]							,     SCREAMING_SNAKE_CASE      :     int=[2, 3, 4]							,     ):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						parent
        UpperCamelCase__    :     Dict        =						batch_size
        UpperCamelCase__    :     List[str]        =						image_size
        UpperCamelCase__    :     List[Any]        =						num_channels
        UpperCamelCase__    :     Union[str, Any]        =						embeddings_size
        UpperCamelCase__    :     Optional[Any]        =						hidden_sizes
        UpperCamelCase__    :     str        =						depths
        UpperCamelCase__    :     Any        =						is_training
        UpperCamelCase__    :     Optional[int]        =						use_labels
        UpperCamelCase__    :     Tuple        =						hidden_act
        UpperCamelCase__    :     str        =						num_labels
        UpperCamelCase__    :     int        =						scope
        UpperCamelCase__    :     List[Any]        =						len(SCREAMING_SNAKE_CASE		)
        UpperCamelCase__    :     Optional[int]        =						out_features
        UpperCamelCase__    :     Optional[Any]        =						out_indices
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)
  
        UpperCamelCase__    :     Tuple        =						None
        if self.use_labels:
             UpperCamelCase__    :     Any        =						ids_tensor([self.batch_size]							,     self.num_labels		)
  
        UpperCamelCase__    :     List[str]        =						self.get_config()
  
        return config, pixel_values, labels
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return ResNetConfig(
            num_channels=self.num_channels							,     embeddings_size=self.embeddings_size							,     hidden_sizes=self.hidden_sizes							,     depths=self.depths							,     hidden_act=self.hidden_act							,     num_labels=self.num_labels							,     out_features=self.out_features							,     out_indices=self.out_indices							,     )
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple							,     SCREAMING_SNAKE_CASE      :     int							,     SCREAMING_SNAKE_CASE      :     List[str]							,     SCREAMING_SNAKE_CASE      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						ResNetModel(config=SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
        UpperCamelCase__    :     Tuple        =						model(SCREAMING_SNAKE_CASE		)
        # expected last hidden states: B, C, H // 32, W // 32
        self.parent.assertEqual(
            result.last_hidden_state.shape							,     (self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)							,     )
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     List[str]							,     SCREAMING_SNAKE_CASE      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						self.num_labels
        UpperCamelCase__    :     Optional[int]        =						ResNetForImageClassification(SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
        UpperCamelCase__    :     Any        =						model(SCREAMING_SNAKE_CASE							,     labels=SCREAMING_SNAKE_CASE		)
        self.parent.assertEqual(result.logits.shape							,     (self.batch_size, self.num_labels)		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     str							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     int        =						ResNetBackbone(config=SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
        UpperCamelCase__    :     Tuple        =						model(SCREAMING_SNAKE_CASE		)
  
        # verify feature maps
        self.parent.assertEqual(len(result.feature_maps		)							,     len(config.out_features		)		)
        self.parent.assertListEqual(list(result.feature_maps[0].shape		)							,     [self.batch_size, self.hidden_sizes[1], 4, 4]		)
  
        # verify channels
        self.parent.assertEqual(len(model.channels		)							,     len(config.out_features		)		)
        self.parent.assertListEqual(model.channels							,     config.hidden_sizes[1:]		)
  
        # verify backbone works with out_features=None
        UpperCamelCase__    :     Any        =						None
        UpperCamelCase__    :     str        =						ResNetBackbone(config=SCREAMING_SNAKE_CASE		)
        model.to(SCREAMING_SNAKE_CASE		)
        model.eval()
        UpperCamelCase__    :     List[str]        =						model(SCREAMING_SNAKE_CASE		)
  
        # verify feature maps
        self.parent.assertEqual(len(result.feature_maps		)							,     1		)
        self.parent.assertListEqual(list(result.feature_maps[0].shape		)							,     [self.batch_size, self.hidden_sizes[-1], 1, 1]		)
  
        # verify channels
        self.parent.assertEqual(len(model.channels		)							,     1		)
        self.parent.assertListEqual(model.channels							,     [config.hidden_sizes[-1]]		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						self.prepare_config_and_inputs()
        UpperCamelCase__       ,  UpperCamelCase__       ,  UpperCamelCase__    :     Tuple        =						config_and_inputs
        UpperCamelCase__    :     int        =						{"pixel_values": pixel_values}
        return config, inputs_dict
  
  
  
  
  
  
  
  @require_torch
  class     __a						(					A__ ,     A__ ,     unittest.TestCase ):
   _lowerCAmelCase : int 				=				(
       (
           ResNetModel,
           ResNetForImageClassification,
           ResNetBackbone,
       )
       if is_torch_available()
       else ()
   )
   _lowerCAmelCase : str 				=				(
       {'''feature-extraction''': ResNetModel, '''image-classification''': ResNetForImageClassification}
       if is_torch_available()
       else {}
   )
  
   _lowerCAmelCase : List[Any] 				=				True
   _lowerCAmelCase : Union[str, Any] 				=				False
   _lowerCAmelCase : List[str] 				=				False
   _lowerCAmelCase : str 				=				False
   _lowerCAmelCase : List[str] 				=				False
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Union[str, Any]        =						ResNetModelTester(self		)
        UpperCamelCase__    :     Optional[Any]        =						ConfigTester(self							,     config_class=SCREAMING_SNAKE_CASE							,     has_text_modality=SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Dict		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        self.create_and_test_config_common_properties()
        self.config_tester.create_and_test_config_to_json_string()
        self.config_tester.create_and_test_config_to_json_file()
        self.config_tester.create_and_test_config_from_and_save_pretrained()
        self.config_tester.create_and_test_config_with_num_labels()
        self.config_tester.check_config_can_be_init_without_params()
        self.config_tester.check_config_arguments_init()
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return
  
  
  
  
  
  
  
   @unittest.skip(reason="ResNet does not use inputs_embeds"		)
   def       __lowercase      (	self      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
   @unittest.skip(reason="ResNet does not support input and output embeddings"		)
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__       ,  UpperCamelCase__    :     int        =						self.model_tester.prepare_config_and_inputs_for_common()
  
        for model_class in self.all_model_classes:
             UpperCamelCase__    :     Tuple        =						model_class(SCREAMING_SNAKE_CASE		)
             UpperCamelCase__    :     Optional[Any]        =						inspect.signature(model.forward		)
             # signature.parameters is an OrderedDict => so arg_names order is deterministic
             UpperCamelCase__    :     Union[str, Any]        =						[*signature.parameters.keys()]
  
             UpperCamelCase__    :     str        =						["pixel_values"]
             self.assertListEqual(arg_names[:1]							,     SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[str]        =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     List[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_backbone(*SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Any		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__       ,  UpperCamelCase__    :     int        =						self.model_tester.prepare_config_and_inputs_for_common()
  
        for model_class in self.all_model_classes:
             UpperCamelCase__    :     str        =						model_class(config=SCREAMING_SNAKE_CASE		)
             for name, module in model.named_modules():
                  if isinstance(SCREAMING_SNAKE_CASE							,     (nn.BatchNormad, nn.GroupNorm)		):
                       self.assertTrue(
                           torch.all(module.weight == 1		)							,     msg=F'Parameter {name} of model {model_class} seems not properly initialized'							,     )
                       self.assertTrue(
                           torch.all(module.bias == 0		)							,     msg=F'Parameter {name} of model {model_class} seems not properly initialized'							,     )
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        def check_hidden_states_output(SCREAMING_SNAKE_CASE      :     List[Any]							,     SCREAMING_SNAKE_CASE      :     Optional[int]							,     SCREAMING_SNAKE_CASE      :     Optional[int]		):
             UpperCamelCase__    :     Tuple        =						model_class(SCREAMING_SNAKE_CASE		)
             model.to(SCREAMING_SNAKE_CASE		)
             model.eval()
  
             with torch.no_grad():
                  UpperCamelCase__    :     Dict        =						model(**self._prepare_for_class(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)		)
  
             UpperCamelCase__    :     Union[str, Any]        =						outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
             UpperCamelCase__    :     List[Any]        =						self.model_tester.num_stages
             self.assertEqual(len(SCREAMING_SNAKE_CASE		)							,     expected_num_stages + 1		)
  
             # ResNet's feature maps are of shape (batch_size, num_channels, height, width)
             self.assertListEqual(
                 list(hidden_states[0].shape[-2:]		)							,     [self.model_tester.image_size // 4, self.model_tester.image_size // 4]							,     )
  
        UpperCamelCase__       ,  UpperCamelCase__    :     Union[str, Any]        =						self.model_tester.prepare_config_and_inputs_for_common()
        UpperCamelCase__    :     Tuple        =						["basic", "bottleneck"]
        for model_class in self.all_model_classes:
             for layer_type in layers_type:
                  UpperCamelCase__    :     Union[str, Any]        =						layer_type
                  UpperCamelCase__    :     Any        =						True
                  check_hidden_states_output(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
  
                  # check that output_hidden_states also work using config
                  del inputs_dict["output_hidden_states"]
                  UpperCamelCase__    :     Union[str, Any]        =						True
  
                  check_hidden_states_output(SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE							,     SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   @unittest.skip(reason="ResNet does not use feedforward chunking"		)
   def       __lowercase      (	self      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        pass
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     str        =						self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_image_classification(*SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   @slow
   def       __lowercase      (	self      :     Dict		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        for model_name in RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
             UpperCamelCase__    :     Tuple        =						ResNetModel.from_pretrained(SCREAMING_SNAKE_CASE		)
             self.assertIsNotNone(SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
  def 	SCREAMING_SNAKE_CASE							(      )				->			int:
       UpperCamelCase__    :     str        =						Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"    )
       return image
  
  
  
  
  
  @require_torch
  @require_vision
  class     __a						(					unittest.TestCase ):
  
  
  
  
  
  
  
   @cached_property
   def       __lowercase      (	self      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        return (
            AutoImageProcessor.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]		)
            if is_vision_available()
            else None
        )
  
  
  
  
  
  
  
   @slow
   def       __lowercase      (	self      :     Union[str, Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						ResNetForImageClassification.from_pretrained(RESNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]		).to(SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     str        =						self.default_image_processor
        UpperCamelCase__    :     Any        =						prepare_img()
        UpperCamelCase__    :     List[str]        =						image_processor(images=SCREAMING_SNAKE_CASE							,     return_tensors="pt"		).to(SCREAMING_SNAKE_CASE		)
  
        # forward pass
        with torch.no_grad():
             UpperCamelCase__    :     int        =						model(**SCREAMING_SNAKE_CASE		)
  
        # verify the logits
        UpperCamelCase__    :     Optional[int]        =						torch.Size((1, 10_00)		)
        self.assertEqual(outputs.logits.shape							,     SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     Optional[int]        =						torch.tensor([-1_1.1_0_6_9, -9.7_8_7_7, -8.3_7_7_7]		).to(SCREAMING_SNAKE_CASE		)
  
        self.assertTrue(torch.allclose(outputs.logits[0, :3]							,     SCREAMING_SNAKE_CASE							,     atol=1e-4		)		)
  
  
  
  
  
  
  
  @require_torch
  class     __a						(					A__ ,     unittest.TestCase ):
   _lowerCAmelCase : str 				=				(ResNetBackbone,) if is_torch_available() else ()
   _lowerCAmelCase : Any 				=				False
   _lowerCAmelCase : Optional[Any] 				=				ResNetConfig
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[int]        =						ResNetModelTester(self		)
style_context: 
  
  
  
  
  
  
  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     __a						:
  
  
  
  
  
  
  
    @staticmethod
    def       __lowercase      (	*SCREAMING_SNAKE_CASE      :     Optional[Any]							,     **SCREAMING_SNAKE_CASE      :     Union[str, Any]		):
  
  
         '''simple docstring'''
  
  
  
  
  
  
         pass
  
  
  
  
  
  @is_pipeline_test
  @require_torch_or_tf
  @require_vision
  class     __a						(					unittest.TestCase ):
   _lowerCAmelCase : Tuple 				=				MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
   _lowerCAmelCase : str 				=				TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     str							,     SCREAMING_SNAKE_CASE      :     Union[str, Any]							,     SCREAMING_SNAKE_CASE      :     Optional[Any]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Dict        =						ImageClassificationPipeline(model=SCREAMING_SNAKE_CASE							,     image_processor=SCREAMING_SNAKE_CASE							,     top_k=2		)
        UpperCamelCase__    :     Union[str, Any]        =						[
            Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"		),
            "http://images.cocodataset.org/val2017/000000039769.jpg",
        ]
        return image_classifier, examples
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Tuple							,     SCREAMING_SNAKE_CASE      :     Tuple							,     SCREAMING_SNAKE_CASE      :     Tuple		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						image_classifier("./tests/fixtures/tests_samples/COCO/000000039769.png"		)
  
        self.assertEqual(
            SCREAMING_SNAKE_CASE							,     [
                {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
            ]							,     )
  
        import datasets
  
        UpperCamelCase__    :     int        =						datasets.load_dataset("hf-internal-testing/fixtures_image_utils"							,     "image"							,     split="test"		)
  
        # Accepts URL + PIL.Image + lists
        UpperCamelCase__    :     Tuple        =						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(
            SCREAMING_SNAKE_CASE							,     [
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
                [
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                    {"score": ANY(SCREAMING_SNAKE_CASE		), "label": ANY(SCREAMING_SNAKE_CASE		)},
                ],
            ]							,     )
  
  
  
  
  
  
  
   @require_torch
   def       __lowercase      (	self      :     List[str]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     List[Any]        =						"hf-internal-testing/tiny-random-vit"
        UpperCamelCase__    :     List[str]        =						pipeline("image-classification"							,     model=SCREAMING_SNAKE_CASE		)
  
        UpperCamelCase__    :     List[str]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}]							,     )
  
        UpperCamelCase__    :     Optional[Any]        =						image_classifier(
            [
                "http://images.cocodataset.org/val2017/000000039769.jpg",
                "http://images.cocodataset.org/val2017/000000039769.jpg",
            ]							,     top_k=2							,     )
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
            ]							,     )
  
  
  
  
  
  
  
   @require_tf
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     str        =						"hf-internal-testing/tiny-random-vit"
        UpperCamelCase__    :     int        =						pipeline("image-classification"							,     model=SCREAMING_SNAKE_CASE							,     framework="tf"		)
  
        UpperCamelCase__    :     List[Any]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}]							,     )
  
        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(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
                [{"label": "LABEL_1", "score": 0.5_7_4}, {"label": "LABEL_0", "score": 0.4_2_6}],
            ]							,     )
  
  
  
  
  
  
  
   def       __lowercase      (	self      :     Optional[int]		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Any        =						PreTrainedTokenizer()
  
        # Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
        UpperCamelCase__    :     str        =						pipeline(
            "image-classification"							,     model="hf-internal-testing/tiny-random-vit"							,     tokenizer=SCREAMING_SNAKE_CASE		)
  
        self.assertIs(image_classifier.tokenizer							,     SCREAMING_SNAKE_CASE		)
  
  
  
  
  
  
  
   @slow
   @require_torch
   def       __lowercase      (	self      :     int		):
  
  
        '''simple docstring'''
  
  
  
  
  
  
        UpperCamelCase__    :     Optional[Any]        =						pipeline("image-classification"							,     model="deepmind/vision-perceiver-conv"		)
        UpperCamelCase__    :     Any        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                {"score": 0.4_3_8_5, "label": "tabby, tabby cat"},
                {"score": 0.3_2_1, "label": "tiger cat"},
                {"score": 0.0_5_0_2, "label": "Egyptian cat"},
                {"score": 0.0_1_3_7, "label": "crib, cot"},
                {"score": 0.0_0_7, "label": "radiator"},
            ]							,     )
  
        UpperCamelCase__    :     Optional[Any]        =						pipeline("image-classification"							,     model="deepmind/vision-perceiver-fourier"		)
        UpperCamelCase__    :     List[str]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                {"score": 0.5_6_5_8, "label": "tabby, tabby cat"},
                {"score": 0.1_3_0_9, "label": "tiger cat"},
                {"score": 0.0_7_2_2, "label": "Egyptian cat"},
                {"score": 0.0_7_0_7, "label": "remote control, remote"},
                {"score": 0.0_0_8_2, "label": "computer keyboard, keypad"},
            ]							,     )
  
        UpperCamelCase__    :     List[str]        =						pipeline("image-classification"							,     model="deepmind/vision-perceiver-learned"		)
        UpperCamelCase__    :     Optional[int]        =						image_classifier("http://images.cocodataset.org/val2017/000000039769.jpg"		)
        self.assertEqual(
            nested_simplify(SCREAMING_SNAKE_CASE							,     decimals=4		)							,     [
                {"score": 0.3_0_2_2, "label": "tabby, tabby cat"},
                {"score": 0.2_3_6_2, "label": "Egyptian cat"},
                {"score": 0.1_8_5_6, "label": "tiger cat"},
                {"score": 0.0_3_2_4, "label": "remote control, remote"},
                {"score": 0.0_0_9_6, "label": "quilt, comforter, comfort, puff"},
            ]							,     )