





"""simple docstring"""
import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ConvNextConfig, UperNetConfig
from transformers.testing_utils import require_torch, require_torch_multi_gpu, require_vision, slow, torch_device
from transformers.utils import is_torch_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch

       from transformers import UperNetForSemanticSegmentation
       from transformers.models.upernet.modeling_upernet import UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
       from PIL import Image

       from transformers import AutoImageProcessor







class       a							:



 def __init__(     self				,       _snake_case				,       _snake_case=13				,       _snake_case=32				,       _snake_case=3				,       _snake_case=4				,       _snake_case=[10, 20, 30, 40]				,       _snake_case=[2, 2, 3, 2]				,       _snake_case=True				,       _snake_case=True				,       _snake_case=37				,       _snake_case="gelu"				,       _snake_case=10				,       _snake_case=0.02				,       _snake_case=["stage2", "stage3", "stage4"]				,       _snake_case=3				,       _snake_case=None				,       ):







  """simple docstring"""






  lowerCAmelCase    				= parent
  lowerCAmelCase    				= batch_size
  lowerCAmelCase    				= image_size
  lowerCAmelCase    				= num_channels
  lowerCAmelCase    				= num_stages
  lowerCAmelCase    				= hidden_sizes
  lowerCAmelCase    				= depths
  lowerCAmelCase    				= is_training
  lowerCAmelCase    				= use_labels
  lowerCAmelCase    				= intermediate_size
  lowerCAmelCase    				= hidden_act
  lowerCAmelCase    				= type_sequence_label_size
  lowerCAmelCase    				= initializer_range
  lowerCAmelCase    				= out_features
  lowerCAmelCase    				= num_labels
  lowerCAmelCase    				= scope
  lowerCAmelCase    				= num_stages



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]     )

  lowerCAmelCase    				= None
  if self.use_labels:
   lowerCAmelCase    				= ids_tensor([self.batch_size]				,       self.type_sequence_label_size     )

  lowerCAmelCase    				= self.get_config()

  return config, pixel_values, labels



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return ConvNextConfig(
      num_channels=self.num_channels				,       num_stages=self.num_stages				,       hidden_sizes=self.hidden_sizes				,       depths=self.depths				,       is_training=self.is_training				,       intermediate_size=self.intermediate_size				,       hidden_act=self.hidden_act				,       out_features=self.out_features				,       )



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return UperNetConfig(
      backbone_config=self.get_backbone_config()				,       hidden_size=5_12				,       pool_scales=[1, 2, 3, 6]				,       use_auxiliary_head=_snake_case				,       auxiliary_loss_weight=0.4				,       auxiliary_in_channels=40				,       auxiliary_channels=2_56				,       auxiliary_num_convs=1				,       auxiliary_concat_input=_snake_case				,       loss_ignore_index=2_55				,       num_labels=self.num_labels				,       )



 def    UpperCamelCase__  (     self				,       _snake_case				,       _snake_case				,       _snake_case     ):







  """simple docstring"""






  lowerCAmelCase    				= UperNetForSemanticSegmentation(config=_snake_case     )
  model.to(_snake_case     )
  model.eval()
  lowerCAmelCase    				= model(_snake_case     )
  self.parent.assertEqual(
      result.logits.shape				,       (self.batch_size, self.num_labels, self.image_size, self.image_size)     )



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= self.prepare_config_and_inputs()
  (
      (
      lowerCAmelCase
  )				,(
      lowerCAmelCase
  )				,(
      lowerCAmelCase
  )				,
  )    				= config_and_inputs
  lowerCAmelCase    				= {'pixel_values': pixel_values}
  return config, inputs_dict







@require_torch
class       a							(   a__   , a__   , unittest.TestCase  ):
 snake_case__             =       (UperNetForSemanticSegmentation,) if is_torch_available() else ()
 snake_case__             =       {'''image-segmentation''': UperNetForSemanticSegmentation} if is_torch_available() else {}
 snake_case__             =       False
 snake_case__             =       False
 snake_case__             =       False
 snake_case__             =       False
 snake_case__             =       False
 snake_case__             =       False



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= UperNetModelTester(self     )
  lowerCAmelCase    				= ConfigTester(self				,       config_class=_snake_case				,       has_text_modality=_snake_case				,       hidden_size=37     )



 def    UpperCamelCase__  (     self     ):







  """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    UpperCamelCase__  (     self     ):







  """simple docstring"""






  return



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase				,lowerCAmelCase    				= self.model_tester.prepare_config_and_inputs_for_common()

  for model_class in self.all_model_classes:
   lowerCAmelCase    				= model_class(_snake_case     )
   lowerCAmelCase    				= inspect.signature(model.forward     )
   # signature.parameters is an OrderedDict => so arg_names order is deterministic
   lowerCAmelCase    				= [*signature.parameters.keys()]

   lowerCAmelCase    				= ['pixel_values']
   self.assertListEqual(arg_names[:1]				,       _snake_case     )



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= self.model_tester.prepare_config_and_inputs()
  self.model_tester.create_and_check_for_semantic_segmentation(*_snake_case     )



 @unittest.skip(reason='UperNet does not use inputs_embeds'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 @unittest.skip(reason='UperNet does not support input and output embeddings'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 @unittest.skip(reason='UperNet does not have a base model'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 @unittest.skip(reason='UperNet does not have a base model'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 @require_torch_multi_gpu
 @unittest.skip(reason='UperNet has some layers using `add_module` which doesn\'t work well with `nn.DataParallel`'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 @unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  def check_hidden_states_output(_snake_case				,       _snake_case				,       _snake_case     ):
   lowerCAmelCase    				= model_class(_snake_case     )
   model.to(_snake_case     )
   model.eval()

   with torch.no_grad():
    lowerCAmelCase    				= model(**self._prepare_for_class(_snake_case				,       _snake_case     )     )

   lowerCAmelCase    				= outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

   lowerCAmelCase    				= self.model_tester.num_stages
   self.assertEqual(len(_snake_case     )				,       expected_num_stages + 1     )

   # ConvNext'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]				,       )

  lowerCAmelCase				,lowerCAmelCase    				= self.model_tester.prepare_config_and_inputs_for_common()

  for model_class in self.all_model_classes:
   lowerCAmelCase    				= True
   check_hidden_states_output(_snake_case				,       _snake_case				,       _snake_case     )

   # check that output_hidden_states also work using config
   del inputs_dict["output_hidden_states"]
   lowerCAmelCase    				= True

   check_hidden_states_output(_snake_case				,       _snake_case				,       _snake_case     )



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase				,lowerCAmelCase    				= self.model_tester.prepare_config_and_inputs_for_common()

  lowerCAmelCase    				= _config_zero_init(_snake_case     )
  lowerCAmelCase    				= _config_zero_init(configs_no_init.backbone_config     )
  for model_class in self.all_model_classes:
   lowerCAmelCase    				= model_class(config=_snake_case     )
   for name, param in model.named_parameters():
    if param.requires_grad:
     self.assertIn(
         ((param.data.mean() * 1E9).round() / 1E9).item()				,       [0.0, 1.0]				,       msg=F'Parameter {name} of model {model_class} seems not properly initialized'				,       )



 @unittest.skip(reason='UperNet does not have tied weights'     )
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  pass



 @slow
 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  for model_name in UPERNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
   lowerCAmelCase    				= UperNetForSemanticSegmentation.from_pretrained(_snake_case     )
   self.assertIsNotNone(_snake_case     )


def 		_SCREAMING_SNAKE_CASE			():
 lowerCAmelCase    				= hf_hub_download(
     repo_id='hf-internal-testing/fixtures_ade20k'  ,     repo_type='dataset'  ,     filename='ADE_val_00000001.jpg'			)
 lowerCAmelCase    				= Image.open(_UpperCAmelCase			).convert('RGB'			)
 return image







@require_torch
@require_vision
@slow
class       a							(   unittest.TestCase  ):



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= AutoImageProcessor.from_pretrained('openmmlab/upernet-swin-tiny'     )
  lowerCAmelCase    				= UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-swin-tiny'     ).to(_snake_case     )

  lowerCAmelCase    				= prepare_img()
  lowerCAmelCase    				= processor(images=_snake_case				,       return_tensors='pt'     ).to(_snake_case     )

  with torch.no_grad():
   lowerCAmelCase    				= model(**_snake_case     )

  lowerCAmelCase    				= torch.Size((1, model.config.num_labels, 5_12, 5_12)     )
  self.assertEqual(outputs.logits.shape				,       _snake_case     )

  lowerCAmelCase    				= torch.tensor(
      [[-7.5_958, -7.5_958, -7.4_302], [-7.5_958, -7.5_958, -7.4_302], [-7.4_797, -7.4_797, -7.3_068]]     ).to(_snake_case     )
  self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]				,       _snake_case				,       atol=1E-4     )     )



 def    UpperCamelCase__  (     self     ):







  """simple docstring"""






  lowerCAmelCase    				= AutoImageProcessor.from_pretrained('openmmlab/upernet-convnext-tiny'     )
  lowerCAmelCase    				= UperNetForSemanticSegmentation.from_pretrained('openmmlab/upernet-convnext-tiny'     ).to(_snake_case     )

  lowerCAmelCase    				= prepare_img()
  lowerCAmelCase    				= processor(images=_snake_case				,       return_tensors='pt'     ).to(_snake_case     )

  with torch.no_grad():
   lowerCAmelCase    				= model(**_snake_case     )

  lowerCAmelCase    				= torch.Size((1, model.config.num_labels, 5_12, 5_12)     )
  self.assertEqual(outputs.logits.shape				,       _snake_case     )

  lowerCAmelCase    				= torch.tensor(
      [[-8.8_110, -8.8_110, -8.6_521], [-8.8_110, -8.8_110, -8.6_521], [-8.7_746, -8.7_746, -8.6_130]]     ).to(_snake_case     )
  self.assertTrue(torch.allclose(outputs.logits[0, 0, :3, :3]				,       _snake_case				,       atol=1E-4     )     )








import copy
import inspect
import unittest

from transformers import PretrainedConfig, SwiftFormerConfig
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_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 SwiftFormerForImageClassification, SwiftFormerModel
    from transformers.models.swiftformer.modeling_swiftformer import SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
    from PIL import Image

    from transformers import ViTImageProcessor





class 			_SCREAMING_SNAKE_CASE :







   '''simple docstring'''




   def __init__(       self					:			List[str]     , __lowerCamelCase					:			int     , __lowerCamelCase					:			int=13     , __lowerCamelCase					:			Optional[int]=3     , __lowerCamelCase					:			str=True     , __lowerCamelCase					:			Any=True     , __lowerCamelCase					:			Optional[Any]=0.1     , __lowerCamelCase					:			Any=0.1     , __lowerCamelCase					:			Optional[int]=224     , __lowerCamelCase					:			Any=1000     , __lowerCamelCase					:			Optional[Any]=[3, 3, 6, 4]     , __lowerCamelCase					:			List[Any]=[48, 56, 112, 220]     , ):
       SCREAMING_SNAKE_CASE										=   parent
       SCREAMING_SNAKE_CASE										=   batch_size
       SCREAMING_SNAKE_CASE										=   num_channels
       SCREAMING_SNAKE_CASE										=   is_training
       SCREAMING_SNAKE_CASE										=   use_labels
       SCREAMING_SNAKE_CASE										=   hidden_dropout_prob
       SCREAMING_SNAKE_CASE										=   attention_probs_dropout_prob
       SCREAMING_SNAKE_CASE										=   num_labels
       SCREAMING_SNAKE_CASE										=   image_size
       SCREAMING_SNAKE_CASE										=   layer_depths
       SCREAMING_SNAKE_CASE										=   embed_dims





   def      _snake_case		(       self					:			Optional[Any]			):
       SCREAMING_SNAKE_CASE										=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)

       SCREAMING_SNAKE_CASE										=   None
       if self.use_labels:
           SCREAMING_SNAKE_CASE										=   ids_tensor([self.batch_size]     , self.num_labels			)

       SCREAMING_SNAKE_CASE										=   self.get_config()

       return config, pixel_values, labels





   def      _snake_case		(       self					:			Dict			):
       return SwiftFormerConfig(
           depths=self.layer_depths     , embed_dims=self.embed_dims     , mlp_ratio=4     , downsamples=[True, True, True, True]     , hidden_act="gelu"     , num_labels=self.num_labels     , down_patch_size=3     , down_stride=2     , down_pad=1     , drop_rate=0.0     , drop_path_rate=0.0     , use_layer_scale=__lowerCamelCase     , layer_scale_init_value=1e-5     , )





   def      _snake_case		(       self					:			List[str]     , __lowerCamelCase					:			Union[str, Any]     , __lowerCamelCase					:			Tuple     , __lowerCamelCase					:			List[Any]			):
       SCREAMING_SNAKE_CASE										=   SwiftFormerModel(config=__lowerCamelCase			)
       model.to(__lowerCamelCase			)
       model.eval()
       SCREAMING_SNAKE_CASE										=   model(__lowerCamelCase			)
       self.parent.assertEqual(result.last_hidden_state.shape     , (self.batch_size, self.embed_dims[-1], 7, 7)			)





   def      _snake_case		(       self					:			Dict     , __lowerCamelCase					:			int     , __lowerCamelCase					:			Any     , __lowerCamelCase					:			Optional[int]			):
       SCREAMING_SNAKE_CASE										=   self.num_labels
       SCREAMING_SNAKE_CASE										=   SwiftFormerForImageClassification(__lowerCamelCase			)
       model.to(__lowerCamelCase			)
       model.eval()
       SCREAMING_SNAKE_CASE										=   model(__lowerCamelCase     , labels=__lowerCamelCase			)
       self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.num_labels)			)

       SCREAMING_SNAKE_CASE										=   SwiftFormerForImageClassification(__lowerCamelCase			)
       model.to(__lowerCamelCase			)
       model.eval()

       SCREAMING_SNAKE_CASE										=   floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]			)
       SCREAMING_SNAKE_CASE										=   model(__lowerCamelCase			)
       self.parent.assertEqual(result.logits.shape     , (self.batch_size, self.num_labels)			)





   def      _snake_case		(       self					:			int			):
       ((SCREAMING_SNAKE_CASE)							,	(SCREAMING_SNAKE_CASE)							,	(SCREAMING_SNAKE_CASE))										=   self.prepare_config_and_inputs()
       SCREAMING_SNAKE_CASE										=   {"pixel_values": pixel_values}
       return config, inputs_dict





@require_torch
class 			_SCREAMING_SNAKE_CASE (   __snake_case					,       __snake_case					,       unittest.TestCase		):







   '''simple docstring'''




   lowerCamelCase__				=      (SwiftFormerModel, SwiftFormerForImageClassification) if is_torch_available() else ()
   lowerCamelCase__				=      (
       {"feature-extraction": SwiftFormerModel, "image-classification": SwiftFormerForImageClassification}
       if is_torch_available()
       else {}
   )

   lowerCamelCase__				=      False
   lowerCamelCase__				=      False
   lowerCamelCase__				=      False
   lowerCamelCase__				=      False
   lowerCamelCase__				=      False





   def      _snake_case		(       self					:			int			):
       SCREAMING_SNAKE_CASE										=   SwiftFormerModelTester(self			)
       SCREAMING_SNAKE_CASE										=   ConfigTester(
           self     , config_class=__lowerCamelCase     , has_text_modality=__lowerCamelCase     , hidden_size=37     , num_attention_heads=12     , num_hidden_layers=12     , )





   def      _snake_case		(       self					:			List[Any]			):
       self.config_tester.run_common_tests()





   @unittest.skip(reason="SwiftFormer does not use inputs_embeds"			)
   def      _snake_case		(       self					:			Optional[int]			):
       pass





   def      _snake_case		(       self					:			Optional[int]			):
       SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           SCREAMING_SNAKE_CASE										=   model_class(__lowerCamelCase			)
           SCREAMING_SNAKE_CASE										=   model.get_output_embeddings()
           self.assertTrue(x is None or isinstance(__lowerCamelCase     , nn.Linear			)			)





   def      _snake_case		(       self					:			List[Any]			):
       SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           SCREAMING_SNAKE_CASE										=   model_class(__lowerCamelCase			)
           SCREAMING_SNAKE_CASE										=   inspect.signature(model.forward			)
           # signature.parameters is an OrderedDict => so arg_names order is deterministic
           SCREAMING_SNAKE_CASE										=   [*signature.parameters.keys()]

           SCREAMING_SNAKE_CASE										=   ["pixel_values"]
           self.assertListEqual(arg_names[:1]     , __lowerCamelCase			)





   def      _snake_case		(       self					:			Union[str, Any]			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_model(*__lowerCamelCase			)





   def      _snake_case		(       self					:			int			):
       SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs()
       self.model_tester.create_and_check_for_image_classification(*__lowerCamelCase			)





   @slow
   def      _snake_case		(       self					:			Tuple			):
       for model_name in SWIFTFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
           SCREAMING_SNAKE_CASE										=   SwiftFormerModel.from_pretrained(__lowerCamelCase			)
           self.assertIsNotNone(__lowerCamelCase			)





   @unittest.skip(reason="SwiftFormer does not output attentions"			)
   def      _snake_case		(       self					:			Union[str, Any]			):
       pass





   def      _snake_case		(       self					:			Optional[Any]			):
       def check_hidden_states_output(__lowerCamelCase					:			Optional[int]     , __lowerCamelCase					:			str     , __lowerCamelCase					:			Tuple			):
           SCREAMING_SNAKE_CASE										=   model_class(__lowerCamelCase			)
           model.to(__lowerCamelCase			)
           model.eval()

           with torch.no_grad():
               SCREAMING_SNAKE_CASE										=   model(**self._prepare_for_class(__lowerCamelCase     , __lowerCamelCase			)			)

           SCREAMING_SNAKE_CASE										=   outputs.hidden_states

           SCREAMING_SNAKE_CASE										=   8
           self.assertEqual(len(__lowerCamelCase			)     , __lowerCamelCase			)  # TODO

           # SwiftFormer's feature maps are of shape (batch_size, embed_dims, height, width)
           # with the width and height being successively divided by 2, after every 2 blocks
           for i in range(len(__lowerCamelCase			)			):
               self.assertEqual(
                   hidden_states[i].shape     , torch.Size(
                       [
                           self.model_tester.batch_size,
                           self.model_tester.embed_dims[i // 2],
                           (self.model_tester.image_size // 4) // 2 ** (i // 2),
                           (self.model_tester.image_size // 4) // 2 ** (i // 2),
                       ]			)     , )

       SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs_for_common()

       for model_class in self.all_model_classes:
           SCREAMING_SNAKE_CASE										=   True
           check_hidden_states_output(__lowerCamelCase     , __lowerCamelCase     , __lowerCamelCase			)

           # check that output_hidden_states also work using config
           del inputs_dict["output_hidden_states"]
           SCREAMING_SNAKE_CASE										=   True

           check_hidden_states_output(__lowerCamelCase     , __lowerCamelCase     , __lowerCamelCase			)





   def      _snake_case		(       self					:			List[Any]			):
       def _config_zero_init(__lowerCamelCase					:			List[Any]			):
           SCREAMING_SNAKE_CASE										=   copy.deepcopy(__lowerCamelCase			)
           for key in configs_no_init.__dict__.keys():
               if "_range" in key or "_std" in key or "initializer_factor" in key or "layer_scale" in key:
                   setattr(__lowerCamelCase     , __lowerCamelCase     , 1e-10			)
               if isinstance(getattr(__lowerCamelCase     , __lowerCamelCase     , __lowerCamelCase			)     , __lowerCamelCase			):
                   SCREAMING_SNAKE_CASE										=   _config_zero_init(getattr(__lowerCamelCase     , __lowerCamelCase			)			)
                   setattr(__lowerCamelCase     , __lowerCamelCase     , __lowerCamelCase			)
           return configs_no_init

       SCREAMING_SNAKE_CASE							,	SCREAMING_SNAKE_CASE										=   self.model_tester.prepare_config_and_inputs_for_common()

       SCREAMING_SNAKE_CASE										=   _config_zero_init(__lowerCamelCase			)
       for model_class in self.all_model_classes:
           SCREAMING_SNAKE_CASE										=   model_class(config=__lowerCamelCase			)
           for name, param in model.named_parameters():
               if param.requires_grad:
                   self.assertIn(
                       ((param.data.mean() * 1e9) / 1e9).round().item()     , [0.0, 1.0]     , msg=f"Parameter {name} of model {model_class} seems not properly initialized"     , )





   @unittest.skip("Will be fixed soon by reducing the size of the model used for common tests."			)
   def      _snake_case		(       self					:			str			):
       pass





def 	__a     (      ):
    SCREAMING_SNAKE_CASE										=   Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"       )
    return image





@require_torch
@require_vision
class 			_SCREAMING_SNAKE_CASE (   unittest.TestCase		):







   '''simple docstring'''




   @cached_property
   def      _snake_case		(       self					:			List[str]			):
       return ViTImageProcessor.from_pretrained("MBZUAI/swiftformer-xs"			) if is_vision_available() else None





   @slow
   def      _snake_case		(       self					:			List[Any]			):
       SCREAMING_SNAKE_CASE										=   SwiftFormerForImageClassification.from_pretrained("MBZUAI/swiftformer-xs"			).to(__lowerCamelCase			)

       SCREAMING_SNAKE_CASE										=   self.default_image_processor
       SCREAMING_SNAKE_CASE										=   prepare_img()
       SCREAMING_SNAKE_CASE										=   image_processor(images=__lowerCamelCase     , return_tensors="pt"			).to(__lowerCamelCase			)

       # forward pass
       with torch.no_grad():
           SCREAMING_SNAKE_CASE										=   model(**__lowerCamelCase			)

       # verify the logits
       SCREAMING_SNAKE_CASE										=   torch.Size((1, 1000)			)
       self.assertEqual(outputs.logits.shape     , __lowerCamelCase			)

       SCREAMING_SNAKE_CASE										=   torch.tensor([[-2.17_03e00, 2.11_07e00, -2.08_11e00]]			).to(__lowerCamelCase			)
       self.assertTrue(torch.allclose(outputs.logits[0, :3]     , __lowerCamelCase     , atol=1e-4			)			)