code: 
  
  from __future__ import annotations
  
  import inspect
  import unittest
  from typing import List, Tuple
  
  from transformers import ConvNextConfig
  from transformers.testing_utils import require_tf, require_vision, slow
  from transformers.utils import cached_property, is_tf_available, is_vision_available
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_tf_available():
         import tensorflow as tf
  
         from transformers import TFConvNextForImageClassification, TFConvNextModel
  
  
  if is_vision_available():
         from PIL import Image
  
         from transformers import ConvNextImageProcessor
  
  
  class    SCREAMING_SNAKE_CASE__      :
  
  
  
  
  
      def __init__(   self		,     a		,     a=13		,     a=32		,     a=3		,     a=4		,     a=[10, 20, 30, 40]		,     a=[2, 2, 3, 2]		,     a=True		,     a=True		,     a=37		,     a="gelu"		,     a=10		,     a=0.02		,     a=3		,     a=None		,     ):
           lowercase__					:     str   = parent
           lowercase__					:     List[str]   = batch_size
           lowercase__					:     Optional[int]   = image_size
           lowercase__					:     Any   = num_channels
           lowercase__					:     Union[str, Any]   = num_stages
           lowercase__					:     Union[str, Any]   = hidden_sizes
           lowercase__					:     Union[str, Any]   = depths
           lowercase__					:     Any   = is_training
           lowercase__					:     List[Any]   = use_labels
           lowercase__					:     Union[str, Any]   = intermediate_size
           lowercase__					:     str   = hidden_act
           lowercase__					:     Any   = type_sequence_label_size
           lowercase__					:     str   = initializer_range
           lowercase__					:     List[Any]   = scope
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     List[Any]   = floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size])
  
           lowercase__					:     Union[str, Any]   = None
           if self.use_labels:
                lowercase__					:     List[str]   = ids_tensor([self.batch_size]		,     self.type_sequence_label_size)
  
           lowercase__					:     int   = self.get_config()
  
           return config, pixel_values, labels
  
  
  
  
  
      def    snake_case_       (   self):
           return ConvNextConfig(
               num_channels=self.num_channels		,     hidden_sizes=self.hidden_sizes		,     depths=self.depths		,     num_stages=self.num_stages		,     hidden_act=self.hidden_act		,     is_decoder=a		,     initializer_range=self.initializer_range		,     )
  
  
  
  
  
      def    snake_case_       (   self		,     a		,     a		,     a):
           lowercase__					:     Optional[int]   = TFConvNextModel(config=a)
           lowercase__					:     Union[str, Any]   = model(a		,     training=a)
           # 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    snake_case_       (   self		,     a		,     a		,     a):
           lowercase__					:     List[Any]   = self.type_sequence_label_size
           lowercase__					:     int   = TFConvNextForImageClassification(a)
           lowercase__					:     List[Any]   = model(a		,     labels=a		,     training=a)
           self.parent.assertEqual(result.logits.shape		,     (self.batch_size, self.type_sequence_label_size))
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     Optional[Any]   = self.prepare_config_and_inputs()
           lowercase__   ,				lowercase__   ,				lowercase__					:     str   = config_and_inputs
           lowercase__					:     List[Any]   = {'pixel_values': pixel_values}
           return config, inputs_dict
  
  
  
  @require_tf
  class    SCREAMING_SNAKE_CASE__      (__snake_case	, __snake_case	, unittest.TestCase  ):
      __lowerCamelCase		: List[str]														=  (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else ()
      __lowerCamelCase		: Optional[int]														=  (
          {"""feature-extraction""": TFConvNextModel, """image-classification""": TFConvNextForImageClassification}
          if is_tf_available()
          else {}
      )
  
      __lowerCamelCase		: str														=  False
      __lowerCamelCase		: Optional[Any]														=  False
      __lowerCamelCase		: Union[str, Any]														=  False
      __lowerCamelCase		: List[str]														=  False
      __lowerCamelCase		: Dict														=  False
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     Optional[int]   = TFConvNextModelTester(self)
           lowercase__					:     Any   = ConfigTester(
               self		,     config_class=a		,     has_text_modality=a		,     hidden_size=37		,     )
  
  
  
  
  
      @unittest.skip(reason='ConvNext does not use inputs_embeds')
      def    snake_case_       (   self):
           pass
  
  
  
  
  
      @unittest.skipIf(
          not is_tf_available() or len(tf.config.list_physical_devices('GPU')) == 0		,     reason='TF does not support backprop for grouped convolutions on CPU.'		,     )
      @slow
      def    snake_case_       (   self):
           super().test_keras_fit()
  
  
  
  
  
      @unittest.skip(reason='ConvNext does not support input and output embeddings')
      def    snake_case_       (   self):
           pass
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__   ,				lowercase__					:     Union[str, Any]   = self.model_tester.prepare_config_and_inputs_for_common()
  
           for model_class in self.all_model_classes:
                lowercase__					:     Dict   = model_class(a)
                lowercase__					:     List[str]   = inspect.signature(model.call)
                # signature.parameters is an OrderedDict => so arg_names order is deterministic
                lowercase__					:     Optional[Any]   = [*signature.parameters.keys()]
  
                lowercase__					:     str   = ['pixel_values']
                self.assertListEqual(arg_names[:1]		,     a)
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     List[Any]   = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*a)
  
  
  
  
  
      @unittest.skipIf(
          not is_tf_available() or len(tf.config.list_physical_devices('GPU')) == 0		,     reason='TF does not support backprop for grouped convolutions on CPU.'		,     )
      def    snake_case_       (   self):
           super().test_dataset_conversion()
  
  
  
  
  
      def    snake_case_       (   self):
           def check_hidden_states_output(a		,     a		,     a):
                lowercase__					:     Dict   = model_class(a)
  
                lowercase__					:     Optional[int]   = model(**self._prepare_for_class(a		,     a))
                lowercase__					:     Any   = outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states
  
                lowercase__					:     Tuple   = self.model_tester.num_stages
                self.assertEqual(len(a)		,     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]		,     )
  
           lowercase__   ,				lowercase__					:     Optional[Any]   = self.model_tester.prepare_config_and_inputs_for_common()
  
           for model_class in self.all_model_classes:
                lowercase__					:     List[str]   = True
                check_hidden_states_output(a		,     a		,     a)
  
                # check that output_hidden_states also work using config
                del inputs_dict["output_hidden_states"]
                lowercase__					:     Tuple   = True
  
                check_hidden_states_output(a		,     a		,     a)
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__   ,				lowercase__					:     Any   = self.model_tester.prepare_config_and_inputs_for_common()
  
           def check_equivalence(a		,     a		,     a		,     a={}):
                lowercase__					:     Optional[int]   = model(a		,     return_dict=a		,     **a)
                lowercase__					:     int   = model(a		,     return_dict=a		,     **a).to_tuple()
  
                def recursive_check(a		,     a):
                     if isinstance(a		,     (List, Tuple)):
                          for tuple_iterable_value, dict_iterable_value in zip(a		,     a):
                               recursive_check(a		,     a)
                     elif tuple_object is None:
                          return
                     else:
                          self.assertTrue(
                              all(tf.equal(a		,     a))		,     msg=(
                                  'Tuple and dict output are not equal. Difference:'
                                  f""" {tf.math.reduce_max(tf.abs(tuple_object - dict_object))}"""
                              )		,     )
  
                     recursive_check(a		,     a)
  
           for model_class in self.all_model_classes:
                lowercase__					:     Dict   = model_class(a)
  
                lowercase__					:     List[Any]   = self._prepare_for_class(a		,     a)
                lowercase__					:     Optional[int]   = self._prepare_for_class(a		,     a)
                check_equivalence(a		,     a		,     a)
  
                lowercase__					:     str   = self._prepare_for_class(a		,     a		,     return_labels=a)
                lowercase__					:     List[str]   = self._prepare_for_class(a		,     a		,     return_labels=a)
                check_equivalence(a		,     a		,     a)
  
                lowercase__					:     Union[str, Any]   = self._prepare_for_class(a		,     a)
                lowercase__					:     str   = self._prepare_for_class(a		,     a)
                check_equivalence(a		,     a		,     a		,     {'output_hidden_states': True})
  
                lowercase__					:     List[Any]   = self._prepare_for_class(a		,     a		,     return_labels=a)
                lowercase__					:     Optional[int]   = self._prepare_for_class(a		,     a		,     return_labels=a)
                check_equivalence(a		,     a		,     a		,     {'output_hidden_states': True})
  
  
  
  
  
      def    snake_case_       (   self):
           lowercase__					:     List[Any]   = self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_image_classification(*a)
  
  
  
  
  
      @slow
      def    snake_case_       (   self):
           lowercase__					:     Any   = TFConvNextModel.from_pretrained('facebook/convnext-tiny-224')
           self.assertIsNotNone(a)
  
  
  
  def 			snake_case__    (					):
  
  
  
       '''simple docstring'''
  
  
  
  
  
       lowercase__					:     Dict   = Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'    )
       return image
  
  
  @require_tf
  @require_vision
  class    SCREAMING_SNAKE_CASE__      (unittest.TestCase  ):
  
  
  
  
  
      @cached_property
      def    snake_case_       (   self):
           return ConvNextImageProcessor.from_pretrained('facebook/convnext-tiny-224') if is_vision_available() else None
  
  
  
  
  
      @slow
      def    snake_case_       (   self):
           lowercase__					:     Union[str, Any]   = TFConvNextForImageClassification.from_pretrained('facebook/convnext-tiny-224')
  
           lowercase__					:     Optional[int]   = self.default_image_processor
           lowercase__					:     Optional[Any]   = prepare_img()
           lowercase__					:     Tuple   = image_processor(images=a		,     return_tensors='tf')
  
           # forward pass
           lowercase__					:     str   = model(**a)
  
           # verify the logits
           lowercase__					:     Optional[int]   = tf.TensorShape((1, 1000))
           self.assertEqual(outputs.logits.shape		,     a)
  
           lowercase__					:     Any   = tf.constant([-0.0_260, -0.4_739, 0.1_911])
  
           tf.debugging.assert_near(outputs.logits[0, :3]		,     a		,     atol=1e-4)
  
  
style_context: 
  
  from cva import destroyAllWindows, imread, imshow, waitKey
  
  def 			snake_case__    (					SCREAMING_SNAKE_CASE_	:					int			,  SCREAMING_SNAKE_CASE_	:					int    ):
  
  
  
       '''simple docstring'''
  
  
  
  
  
       lowercase__   ,				lowercase__					:     Optional[int]   = img.shape[0], img.shape[1]
  
       def to_grayscale(SCREAMING_SNAKE_CASE_	:					Union[str, Any]			,  SCREAMING_SNAKE_CASE_	:					List[Any]			,  SCREAMING_SNAKE_CASE_	:					Union[str, Any]    ):
            return 0.2126 * red + 0.587 * green + 0.114 * blue
  
       def normalize(SCREAMING_SNAKE_CASE_	:					int    ):
            return min(SCREAMING_SNAKE_CASE_			,  255    )
  
       for i in range(SCREAMING_SNAKE_CASE_    ):
            for j in range(SCREAMING_SNAKE_CASE_    ):
                 lowercase__					:     str   = int(to_grayscale(*img[i][j]    )    )
                 lowercase__					:     Dict   = [
                     normalize(SCREAMING_SNAKE_CASE_    ),
                     normalize(greyscale + factor    ),
                     normalize(greyscale + 2 * factor    ),
                 ]
  
       return img
  
  
  if __name__ == "__main__":
         # read original image
         snake_case_    						=				{
             percentage: imread('''image_data/lena.jpg''', 1) for percentage in (10, 20, 30, 40)
         }
  
         for percentage, img in images.items():
                make_sepia(img, percentage)
  
         for percentage, img in images.items():
                imshow(F'''Original image with sepia (factor: {percentage})''', img)
  
         waitKey(0)
         destroyAllWindows()
  
  