"""simple docstring"""


from __future__ import annotations

import unittest

from transformers import RoFormerConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
    import tensorflow as tf

    from transformers import (
        TFRoFormerForCausalLM,
        TFRoFormerForMaskedLM,
        TFRoFormerForMultipleChoice,
        TFRoFormerForQuestionAnswering,
        TFRoFormerForSequenceClassification,
        TFRoFormerForTokenClassification,
        TFRoFormerModel,
    )
    from transformers.models.roformer.modeling_tf_roformer import (
        TFRoFormerSelfAttention,
        TFRoFormerSinusoidalPositionalEmbedding,
    )


class 				a :


    def __init__(    self		:     List[str]      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     Optional[Any]=13      , __lowerCAmelCase		:     Optional[int]=7      , __lowerCAmelCase		:     Any=True      , __lowerCAmelCase		:     str=True      , __lowerCAmelCase		:     str=True      , __lowerCAmelCase		:     str=True      , __lowerCAmelCase		:     Optional[int]=99      , __lowerCAmelCase		:     List[str]=32      , __lowerCAmelCase		:     Union[str, Any]=2      , __lowerCAmelCase		:     Optional[Any]=4      , __lowerCAmelCase		:     str=37      , __lowerCAmelCase		:     Optional[int]="gelu"      , __lowerCAmelCase		:     Any=0.1      , __lowerCAmelCase		:     Optional[int]=0.1      , __lowerCAmelCase		:     List[Any]=512      , __lowerCAmelCase		:     Optional[Any]=16      , __lowerCAmelCase		:     Tuple=2      , __lowerCAmelCase		:     List[Any]=0.02      , __lowerCAmelCase		:     str=3      , __lowerCAmelCase		:     str=4      , __lowerCAmelCase		:     List[Any]=None      , ):
      _UpperCAmelCase         =					parent
      _UpperCAmelCase         =					13
      _UpperCAmelCase         =					7
      _UpperCAmelCase         =					True
      _UpperCAmelCase         =					True
      _UpperCAmelCase         =					True
      _UpperCAmelCase         =					True
      _UpperCAmelCase         =					99
      _UpperCAmelCase         =					32
      _UpperCAmelCase         =					2
      _UpperCAmelCase         =					4
      _UpperCAmelCase         =					37
      _UpperCAmelCase         =					"""gelu"""
      _UpperCAmelCase         =					0.1
      _UpperCAmelCase         =					0.1
      _UpperCAmelCase         =					512
      _UpperCAmelCase         =					16
      _UpperCAmelCase         =					2
      _UpperCAmelCase         =					0.02
      _UpperCAmelCase         =					3
      _UpperCAmelCase         =					4
      _UpperCAmelCase         =					None


    def    lowerCAmelCase_     (    self		:     int    ):
      _UpperCAmelCase         =					ids_tensor([self.batch_size, self.seq_length]      , self.vocab_size    )

      _UpperCAmelCase         =					None
      if self.use_input_mask:
        _UpperCAmelCase         =					random_attention_mask([self.batch_size, self.seq_length]    )

      _UpperCAmelCase         =					None
      if self.use_token_type_ids:
        _UpperCAmelCase         =					ids_tensor([self.batch_size, self.seq_length]      , self.type_vocab_size    )

      _UpperCAmelCase         =					None
      _UpperCAmelCase         =					None
      _UpperCAmelCase         =					None
      if self.use_labels:
        _UpperCAmelCase         =					ids_tensor([self.batch_size]      , self.type_sequence_label_size    )
        _UpperCAmelCase         =					ids_tensor([self.batch_size, self.seq_length]      , self.num_labels    )
        _UpperCAmelCase         =					ids_tensor([self.batch_size]      , self.num_choices    )

      _UpperCAmelCase         =					RoFormerConfig(
          vocab_size=self.vocab_size      , hidden_size=self.hidden_size      , num_hidden_layers=self.num_hidden_layers      , num_attention_heads=self.num_attention_heads      , intermediate_size=self.intermediate_size      , hidden_act=self.hidden_act      , hidden_dropout_prob=self.hidden_dropout_prob      , attention_probs_dropout_prob=self.attention_probs_dropout_prob      , max_position_embeddings=self.max_position_embeddings      , type_vocab_size=self.type_vocab_size      , initializer_range=self.initializer_range      , return_dict=__lowerCAmelCase      , )

      return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels


    def    lowerCAmelCase_     (    self		:     Dict      , __lowerCAmelCase		:     Dict      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     Dict      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     Optional[int]      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Optional[Any]    ):
      _UpperCAmelCase         =					TFRoFormerModel(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					{"""input_ids""": input_ids, """attention_mask""": input_mask, """token_type_ids""": token_type_ids}

      _UpperCAmelCase         =					[input_ids, input_mask]
      _UpperCAmelCase         =					model(__lowerCAmelCase    )

      _UpperCAmelCase         =					model(__lowerCAmelCase    )

      self.parent.assertEqual(result.last_hidden_state.shape      , (self.batch_size, self.seq_length, self.hidden_size)    )


    def    lowerCAmelCase_     (    self		:     Union[str, Any]      , __lowerCAmelCase		:     int      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     str      , __lowerCAmelCase		:     List[str]      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     Dict      , __lowerCAmelCase		:     Optional[Any]    ):
      _UpperCAmelCase         =					True
      _UpperCAmelCase         =					TFRoFormerForCausalLM(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					{
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      _UpperCAmelCase         =					model(__lowerCAmelCase    )["""logits"""]
      self.parent.assertListEqual(
          list(prediction_scores.numpy().shape    )      , [self.batch_size, self.seq_length, self.vocab_size]    )


    def    lowerCAmelCase_     (    self		:     List[Any]      , __lowerCAmelCase		:     Dict      , __lowerCAmelCase		:     Tuple      , __lowerCAmelCase		:     List[str]      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     List[str]      , __lowerCAmelCase		:     Optional[int]      , __lowerCAmelCase		:     Dict    ):
      _UpperCAmelCase         =					TFRoFormerForMaskedLM(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					{
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      _UpperCAmelCase         =					model(__lowerCAmelCase    )
      self.parent.assertEqual(result.logits.shape      , (self.batch_size, self.seq_length, self.vocab_size)    )


    def    lowerCAmelCase_     (    self		:     Union[str, Any]      , __lowerCAmelCase		:     List[str]      , __lowerCAmelCase		:     Optional[int]      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     Union[str, Any]      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Any    ):
      _UpperCAmelCase         =					self.num_labels
      _UpperCAmelCase         =					TFRoFormerForSequenceClassification(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					{
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }

      _UpperCAmelCase         =					model(__lowerCAmelCase    )
      self.parent.assertEqual(result.logits.shape      , (self.batch_size, self.num_labels)    )


    def    lowerCAmelCase_     (    self		:     Dict      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     str      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     Optional[int]      , __lowerCAmelCase		:     str      , __lowerCAmelCase		:     Optional[Any]    ):
      _UpperCAmelCase         =					self.num_choices
      _UpperCAmelCase         =					TFRoFormerForMultipleChoice(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					tf.tile(tf.expand_dims(__lowerCAmelCase      , 1    )      , (1, self.num_choices, 1)    )
      _UpperCAmelCase         =					tf.tile(tf.expand_dims(__lowerCAmelCase      , 1    )      , (1, self.num_choices, 1)    )
      _UpperCAmelCase         =					tf.tile(tf.expand_dims(__lowerCAmelCase      , 1    )      , (1, self.num_choices, 1)    )
      _UpperCAmelCase         =					{
          """input_ids""": multiple_choice_inputs_ids,
          """attention_mask""": multiple_choice_input_mask,
          """token_type_ids""": multiple_choice_token_type_ids,
      }
      _UpperCAmelCase         =					model(__lowerCAmelCase    )
      self.parent.assertEqual(result.logits.shape      , (self.batch_size, self.num_choices)    )


    def    lowerCAmelCase_     (    self		:     Dict      , __lowerCAmelCase		:     Dict      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Union[str, Any]      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     int      , __lowerCAmelCase		:     List[Any]    ):
      _UpperCAmelCase         =					self.num_labels
      _UpperCAmelCase         =					TFRoFormerForTokenClassification(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					{
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }
      _UpperCAmelCase         =					model(__lowerCAmelCase    )
      self.parent.assertEqual(result.logits.shape      , (self.batch_size, self.seq_length, self.num_labels)    )


    def    lowerCAmelCase_     (    self		:     Tuple      , __lowerCAmelCase		:     Tuple      , __lowerCAmelCase		:     int      , __lowerCAmelCase		:     Optional[int]      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     List[str]      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     Tuple    ):
      _UpperCAmelCase         =					TFRoFormerForQuestionAnswering(config=__lowerCAmelCase    )
      _UpperCAmelCase         =					{
          """input_ids""": input_ids,
          """attention_mask""": input_mask,
          """token_type_ids""": token_type_ids,
      }

      _UpperCAmelCase         =					model(__lowerCAmelCase    )
      self.parent.assertEqual(result.start_logits.shape      , (self.batch_size, self.seq_length)    )
      self.parent.assertEqual(result.end_logits.shape      , (self.batch_size, self.seq_length)    )


    def    lowerCAmelCase_     (    self		:     List[str]    ):
      _UpperCAmelCase         =					self.prepare_config_and_inputs()
      (
          (
          _UpperCAmelCase
      )       , (
          _UpperCAmelCase
      )       , (
          _UpperCAmelCase
      )       , (
          _UpperCAmelCase
      )       , (
          _UpperCAmelCase
      )       , (
          _UpperCAmelCase
      )       , (
          _UpperCAmelCase
      )       , 
      )         =					config_and_inputs
      _UpperCAmelCase         =					{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
      return config, inputs_dict



@require_tf
class 				a (						lowerCAmelCase_		,							lowerCAmelCase_		,							unittest.TestCase      ):
    _snake_case   :     Optional[Any]   							=							(
        (
            TFRoFormerModel,
            TFRoFormerForCausalLM,
            TFRoFormerForMaskedLM,
            TFRoFormerForQuestionAnswering,
            TFRoFormerForSequenceClassification,
            TFRoFormerForTokenClassification,
            TFRoFormerForMultipleChoice,
        )
        if is_tf_available()
        else ()
    )
    _snake_case   :     int   							=							(
        {
            'feature-extraction': TFRoFormerModel,
            'fill-mask': TFRoFormerForMaskedLM,
            'question-answering': TFRoFormerForQuestionAnswering,
            'text-classification': TFRoFormerForSequenceClassification,
            'text-generation': TFRoFormerForCausalLM,
            'token-classification': TFRoFormerForTokenClassification,
            'zero-shot': TFRoFormerForSequenceClassification,
        }
        if is_tf_available()
        else {}
    )

    _snake_case   :     Tuple   							=							False
    _snake_case   :     Optional[Any]   							=							False


    def    lowerCAmelCase_     (    self		:     List[str]      , __lowerCAmelCase		:     str      , __lowerCAmelCase		:     Any      , __lowerCAmelCase		:     List[Any]      , __lowerCAmelCase		:     Optional[Any]      , __lowerCAmelCase		:     Any    ):
      if pipeline_test_casse_name == "TextGenerationPipelineTests":
        return True

      return False


    def    lowerCAmelCase_     (    self		:     int    ):
      _UpperCAmelCase         =					TFRoFormerModelTester(self    )
      _UpperCAmelCase         =					ConfigTester(self      , config_class=__lowerCAmelCase      , hidden_size=37    )


    def    lowerCAmelCase_     (    self		:     Tuple    ):
      self.config_tester.run_common_tests()


    def    lowerCAmelCase_     (    self		:     Optional[Any]    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_model(*__lowerCAmelCase    )


    def    lowerCAmelCase_     (    self		:     str    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase    )


    def    lowerCAmelCase_     (    self		:     List[Any]    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_lm_head(*__lowerCAmelCase    )


    def    lowerCAmelCase_     (    self		:     Dict    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_multiple_choice(*__lowerCAmelCase    )


    def    lowerCAmelCase_     (    self		:     List[str]    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase    )


    def    lowerCAmelCase_     (    self		:     Tuple    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase    )


    def    lowerCAmelCase_     (    self		:     Optional[int]    ):
      _UpperCAmelCase         =					self.model_tester.prepare_config_and_inputs()
      self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase    )


    @slow
    def    lowerCAmelCase_     (    self		:     Any    ):
      _UpperCAmelCase         =					TFRoFormerModel.from_pretrained("""junnyu/roformer_chinese_base"""    )
      self.assertIsNotNone(__lowerCAmelCase    )



@require_tf
class 				a (						unittest.TestCase      ):


    @slow
    def    lowerCAmelCase_     (    self		:     Dict    ):
      _UpperCAmelCase         =					TFRoFormerForMaskedLM.from_pretrained("""junnyu/roformer_chinese_base"""    )
      _UpperCAmelCase         =					tf.constant([[0, 1, 2, 3, 4, 5]]    )
      _UpperCAmelCase         =					model(__lowerCAmelCase    )[0]

      # TODO Replace vocab size
      _UpperCAmelCase         =					5_0000

      _UpperCAmelCase         =					[1, 6, vocab_size]
      self.assertEqual(output.shape      , __lowerCAmelCase    )

      print(output[:, :3, :3]    )

      # TODO Replace values below with what was printed above.
      _UpperCAmelCase         =					tf.constant(
          [
              [
                  [-0.12_053_341, -1.0_264_901, 0.29_221_946],
                  [-1.5_133_783, 0.197_433, 0.15_190_607],
                  [-5.0_135_403, -3.900_256, -0.84_038_764],
              ]
          ]    )
      tf.debugging.assert_near(output[:, :3, :3]      , __lowerCAmelCase      , atol=1e-4    )



@require_tf
class 				a (						unittest.TestCase      ):
    _snake_case   :     str   							=							1e-4


    def    lowerCAmelCase_     (    self		:     int    ):
      _UpperCAmelCase         =					tf.constant([[4, 10]]    )
      _UpperCAmelCase         =					TFRoFormerSinusoidalPositionalEmbedding(num_positions=6      , embedding_dim=6    )

      _UpperCAmelCase         =					emba(input_ids.shape    )
      _UpperCAmelCase         =					tf.constant(
          [[0.0_000, 0.0_000, 0.0_000, 1.0_000, 1.0_000, 1.0_000], [0.8_415, 0.0_464, 0.0_022, 0.5_403, 0.9_989, 1.0_000]]    )

      tf.debugging.assert_near(__lowerCAmelCase      , __lowerCAmelCase      , atol=self.tolerance    )


    def    lowerCAmelCase_     (    self		:     Union[str, Any]    ):
      _UpperCAmelCase         =					tf.constant(
          [
              [0.0_000, 0.0_000, 0.0_000, 0.0_000, 0.0_000],
              [0.8_415, 0.8_219, 0.8_020, 0.7_819, 0.7_617],
              [0.9_093, 0.9_364, 0.9_581, 0.9_749, 0.9_870],
          ]    )
      _UpperCAmelCase         =					TFRoFormerSinusoidalPositionalEmbedding(num_positions=512      , embedding_dim=512    )
      emba([2, 16, 512]    )
      _UpperCAmelCase         =					emba.weight[:3, :5]

      tf.debugging.assert_near(__lowerCAmelCase      , __lowerCAmelCase      , atol=self.tolerance    )



@require_tf
class 				a (						unittest.TestCase      ):
    _snake_case   :     int   							=							1e-4


    def    lowerCAmelCase_     (    self		:     Any    ):
      # 2,12,16,64
      _UpperCAmelCase         =					tf.reshape(tf.range(2 * 12 * 16 * 64      , dtype=tf.floataa    )      , shape=(2, 12, 16, 64)    ) / 100

      _UpperCAmelCase         =					-tf.reshape(tf.range(2 * 12 * 16 * 64      , dtype=tf.floataa    )      , shape=(2, 12, 16, 64)    ) / 100

      _UpperCAmelCase         =					TFRoFormerSinusoidalPositionalEmbedding(num_positions=32      , embedding_dim=64    )
      _UpperCAmelCase         =					embed_positions([2, 16, 768]    )[None, None, :, :]

      _UpperCAmelCase       , _UpperCAmelCase         =					TFRoFormerSelfAttention.apply_rotary_position_embeddings(
          __lowerCAmelCase      , __lowerCAmelCase      , __lowerCAmelCase    )

      _UpperCAmelCase         =					tf.constant(
          [
              [0.0_000, 0.0_100, 0.0_200, 0.0_300, 0.0_400, 0.0_500, 0.0_600, 0.0_700],
              [-0.2_012, 0.8_897, 0.0_263, 0.9_401, 0.2_074, 0.9_463, 0.3_481, 0.9_343],
              [-1.7_057, 0.6_271, -1.2_145, 1.3_897, -0.6_303, 1.7_647, -0.1_173, 1.8_985],
              [-2.1_731, -1.6_397, -2.7_358, 0.2_854, -2.1_840, 1.7_183, -1.3_018, 2.4_871],
              [0.2_717, -3.6_173, -2.9_206, -2.1_988, -3.6_638, 0.3_858, -2.9_155, 2.2_980],
              [3.9_859, -2.1_580, -0.7_984, -4.4_904, -4.1_181, -2.0_252, -4.4_782, 1.1_253],
          ]    )
      _UpperCAmelCase         =					tf.constant(
          [
              [0.0_000, -0.0_100, -0.0_200, -0.0_300, -0.0_400, -0.0_500, -0.0_600, -0.0_700],
              [0.2_012, -0.8_897, -0.0_263, -0.9_401, -0.2_074, -0.9_463, -0.3_481, -0.9_343],
              [1.7_057, -0.6_271, 1.2_145, -1.3_897, 0.6_303, -1.7_647, 0.1_173, -1.8_985],
              [2.1_731, 1.6_397, 2.7_358, -0.2_854, 2.1_840, -1.7_183, 1.3_018, -2.4_871],
              [-0.2_717, 3.6_173, 2.9_206, 2.1_988, 3.6_638, -0.3_858, 2.9_155, -2.2_980],
              [-3.9_859, 2.1_580, 0.7_984, 4.4_904, 4.1_181, 2.0_252, 4.4_782, -1.1_253],
          ]    )

      tf.debugging.assert_near(query_layer[0, 0, :6, :8]      , __lowerCAmelCase      , atol=self.tolerance    )
      tf.debugging.assert_near(key_layer[0, 0, :6, :8]      , __lowerCAmelCase      , atol=self.tolerance    )

"""simple docstring"""


import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import MobileViTImageProcessor


class 				a (						unittest.TestCase      ):


    def __init__(    self		:     Dict      , __lowerCAmelCase		:     Tuple      , __lowerCAmelCase		:     Optional[Any]=7      , __lowerCAmelCase		:     Optional[Any]=3      , __lowerCAmelCase		:     Optional[Any]=18      , __lowerCAmelCase		:     str=30      , __lowerCAmelCase		:     List[str]=400      , __lowerCAmelCase		:     Union[str, Any]=True      , __lowerCAmelCase		:     str=None      , __lowerCAmelCase		:     Optional[int]=True      , __lowerCAmelCase		:     int=None      , __lowerCAmelCase		:     List[str]=True      , ):
      _UpperCAmelCase         =					size if size is not None else {"""shortest_edge""": 20}
      _UpperCAmelCase         =					crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
      _UpperCAmelCase         =					parent
      _UpperCAmelCase         =					batch_size
      _UpperCAmelCase         =					num_channels
      _UpperCAmelCase         =					image_size
      _UpperCAmelCase         =					min_resolution
      _UpperCAmelCase         =					max_resolution
      _UpperCAmelCase         =					do_resize
      _UpperCAmelCase         =					size
      _UpperCAmelCase         =					do_center_crop
      _UpperCAmelCase         =					crop_size
      _UpperCAmelCase         =					do_flip_channel_order


    def    lowerCAmelCase_     (    self		:     List[str]    ):
      return {
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
          "do_flip_channel_order": self.do_flip_channel_order,
      }



@require_torch
@require_vision
class 				a (						lowerCAmelCase_		,							unittest.TestCase      ):
    _snake_case   :     Optional[int]   							=							MobileViTImageProcessor if is_vision_available() else None


    def    lowerCAmelCase_     (    self		:     Optional[Any]    ):
      _UpperCAmelCase         =					MobileViTImageProcessingTester(self    )


    @property
    def    lowerCAmelCase_     (    self		:     Tuple    ):
      return self.image_processor_tester.prepare_image_processor_dict()


    def    lowerCAmelCase_     (    self		:     Dict    ):
      _UpperCAmelCase         =					self.image_processing_class(**self.image_processor_dict    )
      self.assertTrue(hasattr(__lowerCAmelCase      , """do_resize"""    )    )
      self.assertTrue(hasattr(__lowerCAmelCase      , """size"""    )    )
      self.assertTrue(hasattr(__lowerCAmelCase      , """do_center_crop"""    )    )
      self.assertTrue(hasattr(__lowerCAmelCase      , """center_crop"""    )    )
      self.assertTrue(hasattr(__lowerCAmelCase      , """do_flip_channel_order"""    )    )


    def    lowerCAmelCase_     (    self		:     Union[str, Any]    ):
      _UpperCAmelCase         =					self.image_processing_class.from_dict(self.image_processor_dict    )
      self.assertEqual(image_processor.size      , {"""shortest_edge""": 20}    )
      self.assertEqual(image_processor.crop_size      , {"""height""": 18, """width""": 18}    )

      _UpperCAmelCase         =					self.image_processing_class.from_dict(self.image_processor_dict      , size=42      , crop_size=84    )
      self.assertEqual(image_processor.size      , {"""shortest_edge""": 42}    )
      self.assertEqual(image_processor.crop_size      , {"""height""": 84, """width""": 84}    )


    def    lowerCAmelCase_     (    self		:     List[str]    ):
      pass


    def    lowerCAmelCase_     (    self		:     Dict    ):
      # Initialize image_processing
      _UpperCAmelCase         =					self.image_processing_class(**self.image_processor_dict    )
      # create random PIL images
      _UpperCAmelCase         =					prepare_image_inputs(self.image_processor_tester      , equal_resolution=__lowerCAmelCase    )
      for image in image_inputs:
        self.assertIsInstance(__lowerCAmelCase      , Image.Image    )

      # Test not batched input
      _UpperCAmelCase         =					image_processing(image_inputs[0]      , return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape      , (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )      , )

      # Test batched
      _UpperCAmelCase         =					image_processing(__lowerCAmelCase      , return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape      , (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )      , )


    def    lowerCAmelCase_     (    self		:     str    ):
      # Initialize image_processing
      _UpperCAmelCase         =					self.image_processing_class(**self.image_processor_dict    )
      # create random numpy tensors
      _UpperCAmelCase         =					prepare_image_inputs(self.image_processor_tester      , equal_resolution=__lowerCAmelCase      , numpify=__lowerCAmelCase    )
      for image in image_inputs:
        self.assertIsInstance(__lowerCAmelCase      , np.ndarray    )

      # Test not batched input
      _UpperCAmelCase         =					image_processing(image_inputs[0]      , return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape      , (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )      , )

      # Test batched
      _UpperCAmelCase         =					image_processing(__lowerCAmelCase      , return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape      , (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )      , )


    def    lowerCAmelCase_     (    self		:     Optional[int]    ):
      # Initialize image_processing
      _UpperCAmelCase         =					self.image_processing_class(**self.image_processor_dict    )
      # create random PyTorch tensors
      _UpperCAmelCase         =					prepare_image_inputs(self.image_processor_tester      , equal_resolution=__lowerCAmelCase      , torchify=__lowerCAmelCase    )
      for image in image_inputs:
        self.assertIsInstance(__lowerCAmelCase      , torch.Tensor    )

      # Test not batched input
      _UpperCAmelCase         =					image_processing(image_inputs[0]      , return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape      , (
              1,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )      , )

      # Test batched
      _UpperCAmelCase         =					image_processing(__lowerCAmelCase      , return_tensors="""pt"""    ).pixel_values
      self.assertEqual(
          encoded_images.shape      , (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["""height"""],
              self.image_processor_tester.crop_size["""width"""],
          )      , )
