code: 
  
  
  
  
  
  
  import inspect
  import unittest
  
  from transformers import ResNetConfig, is_flax_available
  from transformers.testing_utils import require_flax, slow
  from transformers.utils import cached_property, is_vision_available
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_flax_common import FlaxModelTesterMixin, floats_tensor
  
  
  if is_flax_available():
        import jax
        import jax.numpy as jnp
  
        from transformers.models.resnet.modeling_flax_resnet import FlaxResNetForImageClassification, FlaxResNetModel
  
  if is_vision_available():
        from PIL import Image
  
        from transformers import AutoImageProcessor
  
  
  
  
  
  
  
  class 							UpperCAmelCase_     (		unittest.TestCase		):
  
  
  
  
       def __init__(							self  ,	_lowerCAmelCase  ,	_lowerCAmelCase=3  ,	_lowerCAmelCase=32  ,	_lowerCAmelCase=3  ,	_lowerCAmelCase=10  ,	_lowerCAmelCase=[10, 20, 30, 40]  ,	_lowerCAmelCase=[1, 1, 2, 1]  ,	_lowerCAmelCase=True  ,	_lowerCAmelCase=True  ,	_lowerCAmelCase="relu"  ,	_lowerCAmelCase=3  ,	_lowerCAmelCase=None  ,	):
            UpperCAmelCase__			:     int										= parent
            UpperCAmelCase__			:     List[Any]										= batch_size
            UpperCAmelCase__			:     Dict										= image_size
            UpperCAmelCase__			:     Any										= num_channels
            UpperCAmelCase__			:     Dict										= embeddings_size
            UpperCAmelCase__			:     Union[str, Any]										= hidden_sizes
            UpperCAmelCase__			:     Dict										= depths
            UpperCAmelCase__			:     Optional[int]										= is_training
            UpperCAmelCase__			:     Tuple										= use_labels
            UpperCAmelCase__			:     Union[str, Any]										= hidden_act
            UpperCAmelCase__			:     Any										= num_labels
            UpperCAmelCase__			:     int										= scope
            UpperCAmelCase__			:     Any										= len(_lowerCAmelCase		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Tuple										= floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]		)
  
            UpperCAmelCase__			:     Tuple										= self.get_config()
  
            return config, pixel_values
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            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  ,	image_size=self.image_size  ,	)
  
  
  
  
       def      __UpperCAmelCase     (							self  ,	_lowerCAmelCase  ,	_lowerCAmelCase		):
            UpperCAmelCase__			:     List[Any]										= FlaxResNetModel(config=_lowerCAmelCase		)
            UpperCAmelCase__			:     Dict										= model(_lowerCAmelCase		)
  
            # Output shape (b, c, h, w)
            self.parent.assertEqual(
                result.last_hidden_state.shape  ,	(self.batch_size, self.hidden_sizes[-1], self.image_size // 32, self.image_size // 32)  ,	)
  
  
  
  
       def      __UpperCAmelCase     (							self  ,	_lowerCAmelCase  ,	_lowerCAmelCase		):
            UpperCAmelCase__			:     Optional[Any]										= self.num_labels
            UpperCAmelCase__			:     Optional[Any]										= FlaxResNetForImageClassification(config=_lowerCAmelCase		)
            UpperCAmelCase__			:     Optional[Any]										= model(_lowerCAmelCase		)
            self.parent.assertEqual(result.logits.shape  ,	(self.batch_size, self.num_labels)		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     str										= self.prepare_config_and_inputs()
            UpperCAmelCase__			,		UpperCAmelCase__			:     Union[str, Any]										= config_and_inputs
            UpperCAmelCase__			:     List[str]										= {"""pixel_values""": pixel_values}
            return config, inputs_dict
  
  
  
  
  
  
  
  @require_flax
  class 							UpperCAmelCase_     (		__lowerCamelCase       ,			unittest.TestCase		):
       __lowerCamelCase										=     (FlaxResNetModel, FlaxResNetForImageClassification) if is_flax_available() else ()
  
       __lowerCamelCase										=     False
       __lowerCamelCase										=     False
       __lowerCamelCase										=     False
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Optional[Any]										= FlaxResNetModelTester(self		)
            UpperCAmelCase__			:     Optional[int]										= ConfigTester(self  ,	config_class=_lowerCAmelCase  ,	has_text_modality=_lowerCAmelCase		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            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		):
            return
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Optional[Any]										= self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_model(*_lowerCAmelCase		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     List[str]										= self.model_tester.prepare_config_and_inputs()
            self.model_tester.create_and_check_for_image_classification(*_lowerCAmelCase		)
  
  
  
  
       @unittest.skip(reason="""ResNet does not use inputs_embeds"""		)
       def      __UpperCAmelCase     (							self		):
            pass
  
  
  
  
       @unittest.skip(reason="""ResNet does not support input and output embeddings"""		)
       def      __UpperCAmelCase     (							self		):
            pass
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			,		UpperCAmelCase__			:     List[Any]										= self.model_tester.prepare_config_and_inputs_for_common()
  
            for model_class in self.all_model_classes:
                 UpperCAmelCase__			:     Any										= model_class(_lowerCAmelCase		)
                 UpperCAmelCase__			:     str										= inspect.signature(model.__call__		)
                 # signature.parameters is an OrderedDict => so arg_names order is deterministic
                 UpperCAmelCase__			:     Tuple										= [*signature.parameters.keys()]
  
                 UpperCAmelCase__			:     Optional[Any]										= ["""pixel_values"""]
                 self.assertListEqual(arg_names[:1]  ,	_lowerCAmelCase		)
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            def check_hidden_states_output(_lowerCAmelCase  ,	_lowerCAmelCase  ,	_lowerCAmelCase		):
                 UpperCAmelCase__			:     Union[str, Any]										= model_class(_lowerCAmelCase		)
  
                 UpperCAmelCase__			:     List[str]										= model(**self._prepare_for_class(_lowerCAmelCase  ,	_lowerCAmelCase		)		)
  
                 UpperCAmelCase__			:     str										= outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
                 UpperCAmelCase__			:     str										= self.model_tester.num_stages
                 self.assertEqual(len(_lowerCAmelCase		)  ,	expected_num_stages + 1		)
  
  
  
  
       @unittest.skip(reason="""ResNet does not use feedforward chunking"""		)
       def      __UpperCAmelCase     (							self		):
            pass
  
  
  
  
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			,		UpperCAmelCase__			:     Tuple										= self.model_tester.prepare_config_and_inputs_for_common()
  
            for model_class in self.all_model_classes:
                 with self.subTest(model_class.__name__		):
                      UpperCAmelCase__			:     List[Any]										= self._prepare_for_class(_lowerCAmelCase  ,	_lowerCAmelCase		)
                      UpperCAmelCase__			:     Union[str, Any]										= model_class(_lowerCAmelCase		)
  
                      @jax.jit
                      def model_jitted(_lowerCAmelCase  ,	**_lowerCAmelCase		):
                           return model(pixel_values=_lowerCAmelCase  ,	**_lowerCAmelCase		)
  
                      with self.subTest("""JIT Enabled"""		):
                           UpperCAmelCase__			:     Union[str, Any]										= model_jitted(**_lowerCAmelCase		).to_tuple()
  
                      with self.subTest("""JIT Disabled"""		):
                           with jax.disable_jit():
                                UpperCAmelCase__			:     Any										= model_jitted(**_lowerCAmelCase		).to_tuple()
  
                      self.assertEqual(len(_lowerCAmelCase		)  ,	len(_lowerCAmelCase		)		)
                      for jitted_output, output in zip(_lowerCAmelCase  ,	_lowerCAmelCase		):
                           self.assertEqual(jitted_output.shape  ,	output.shape		)
  
  
  
  
  
  def    _lowerCamelCase	(	)   -> Tuple:
  
       '''simple docstring'''
       UpperCAmelCase__			:     Tuple										= Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""					)
       return image
  
  
  
  
  
  
  
  @require_flax
  class 							UpperCAmelCase_     (		unittest.TestCase		):
  
  
  
  
       @cached_property
       def      __UpperCAmelCase     (							self		):
            return AutoImageProcessor.from_pretrained("""microsoft/resnet-50"""		) if is_vision_available() else None
  
  
  
  
       @slow
       def      __UpperCAmelCase     (							self		):
            UpperCAmelCase__			:     Optional[Any]										= FlaxResNetForImageClassification.from_pretrained("""microsoft/resnet-50"""		)
  
            UpperCAmelCase__			:     Tuple										= self.default_image_processor
            UpperCAmelCase__			:     Any										= prepare_img()
            UpperCAmelCase__			:     Union[str, Any]										= image_processor(images=_lowerCAmelCase  ,	return_tensors="""np"""		)
  
            UpperCAmelCase__			:     Any										= model(**_lowerCAmelCase		)
  
            # verify the logits
            UpperCAmelCase__			:     Tuple										= (1, 1000)
            self.assertEqual(outputs.logits.shape  ,	_lowerCAmelCase		)
  
            UpperCAmelCase__			:     Tuple										= jnp.array([-1_1.1_0_6_9, -9.7_8_7_7, -8.3_7_7_7]		)
  
            self.assertTrue(jnp.allclose(outputs.logits[0, :3]  ,	_lowerCAmelCase  ,	atol=1e-4		)		)
  
  
  
  
  
  
  
style_context: 
  
  
  
  
  
  
  import math
  import os
  
  import cva
  import numpy as np
  
  SCREAMING_SNAKE_CASE__		:       Optional[Any]   							=							255.0
  
  
  
  
  
  def    _lowerCamelCase	(	__lowerCamelCase   ,       __lowerCamelCase					)   -> float:
  
       '''simple docstring'''
       UpperCAmelCase__			:     List[Any]										= np.mean((original - contrast) ** 2					)
       if mse == 0:
            return 100
  
       return 20 * math.logaa(PIXEL_MAX / math.sqrt(__lowerCamelCase					)					)
  
  
  
  
  
  def    _lowerCamelCase	(	)   -> None:
  
       '''simple docstring'''
       UpperCAmelCase__			:     Union[str, Any]										= os.path.dirname(os.path.realpath(__lowerCamelCase					)					)
       # Loading images (original image and compressed image)
       UpperCAmelCase__			:     List[Any]										= cva.imread(os.path.join(__lowerCamelCase   ,       """image_data/original_image.png"""					)					)
       UpperCAmelCase__			:     Dict										= cva.imread(os.path.join(__lowerCamelCase   ,       """image_data/compressed_image.png"""					)   ,       1					)
  
       UpperCAmelCase__			:     Tuple										= cva.imread(os.path.join(__lowerCamelCase   ,       """image_data/PSNR-example-base.png"""					)					)
       UpperCAmelCase__			:     int										= cva.imread(
           os.path.join(__lowerCamelCase   ,       """image_data/PSNR-example-comp-10.jpg"""					)   ,       1					)
  
       # Value expected: 29.73dB
       print("""-- First Test --"""					)
       print(F"PSNR value is {peak_signal_to_noise_ratio(__lowerCamelCase   ,       __lowerCamelCase					)} dB"					)
  
       # # Value expected: 31.53dB (Wikipedia Example)
       print("""\n-- Second Test --"""					)
       print(F"PSNR value is {peak_signal_to_noise_ratio(__lowerCamelCase   ,       __lowerCamelCase					)} dB"					)
  
  
  if __name__ == "__main__":
        main()
  
  
  
  
  
  
  