


'''simple docstring'''


import collections
import inspect
import unittest

from transformers import FocalNetConfig
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, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
      import torch
      from torch import nn

      from transformers import (
          FocalNetBackbone,
          FocalNetForImageClassification,
          FocalNetForMaskedImageModeling,
          FocalNetModel,
      )
      from transformers.models.focalnet.modeling_focalnet import FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
      from PIL import Image

      from transformers import AutoImageProcessor






class 	lowerCAmelCase__			:




   def __init__(		self  :     List[Any]	,  lowerCamelCase__  :     Any	,  lowerCamelCase__  :     Any=13	,  lowerCamelCase__  :     Dict=32	,  lowerCamelCase__  :     Union[str, Any]=2	,  lowerCamelCase__  :     Optional[Any]=3	,  lowerCamelCase__  :     Union[str, Any]=16	,  lowerCamelCase__  :     Union[str, Any]=[32, 64, 1_28]	,  lowerCamelCase__  :     str=[1, 2, 1]	,  lowerCamelCase__  :     Optional[Any]=[2, 2, 4]	,  lowerCamelCase__  :     str=2	,  lowerCamelCase__  :     str=2.0	,  lowerCamelCase__  :     int=True	,  lowerCamelCase__  :     int=0.0	,  lowerCamelCase__  :     Tuple=0.0	,  lowerCamelCase__  :     str=0.1	,  lowerCamelCase__  :     str="gelu"	,  lowerCamelCase__  :     Union[str, Any]=False	,  lowerCamelCase__  :     List[Any]=True	,  lowerCamelCase__  :     Optional[Any]=0.0_2	,  lowerCamelCase__  :     Any=1E-5	,  lowerCamelCase__  :     str=True	,  lowerCamelCase__  :     Dict=None	,  lowerCamelCase__  :     Any=True	,  lowerCamelCase__  :     List[Any]=10	,  lowerCamelCase__  :     str=8	,  lowerCamelCase__  :     str=["stage1", "stage2"]	,  lowerCamelCase__  :     str=[1, 2]	,  )   ->Any:



     '''simple docstring'''







     _UpperCAmelCase		:       str								=      parent
     _UpperCAmelCase		:       int								=      batch_size
     _UpperCAmelCase		:       int								=      image_size
     _UpperCAmelCase		:       Dict								=      patch_size
     _UpperCAmelCase		:       Any								=      num_channels
     _UpperCAmelCase		:       Optional[Any]								=      embed_dim
     _UpperCAmelCase		:       Dict								=      hidden_sizes
     _UpperCAmelCase		:       Dict								=      depths
     _UpperCAmelCase		:       Optional[Any]								=      num_heads
     _UpperCAmelCase		:       Optional[Any]								=      window_size
     _UpperCAmelCase		:       List[Any]								=      mlp_ratio
     _UpperCAmelCase		:       int								=      qkv_bias
     _UpperCAmelCase		:       Optional[Any]								=      hidden_dropout_prob
     _UpperCAmelCase		:       Optional[int]								=      attention_probs_dropout_prob
     _UpperCAmelCase		:       Tuple								=      drop_path_rate
     _UpperCAmelCase		:       int								=      hidden_act
     _UpperCAmelCase		:       Optional[Any]								=      use_absolute_embeddings
     _UpperCAmelCase		:       Union[str, Any]								=      patch_norm
     _UpperCAmelCase		:       int								=      layer_norm_eps
     _UpperCAmelCase		:       Optional[int]								=      initializer_range
     _UpperCAmelCase		:       Any								=      is_training
     _UpperCAmelCase		:       Optional[Any]								=      scope
     _UpperCAmelCase		:       str								=      use_labels
     _UpperCAmelCase		:       Dict								=      type_sequence_label_size
     _UpperCAmelCase		:       str								=      encoder_stride
     _UpperCAmelCase		:       Tuple								=      out_features
     _UpperCAmelCase		:       int								=      out_indices




   def 							lowerCAmelCase__    (		self  :     int )   ->List[str]:



     '''simple docstring'''







     _UpperCAmelCase		:       Dict								=      floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size] )

     _UpperCAmelCase		:       Optional[int]								=      None
     if self.use_labels:
       _UpperCAmelCase		:       Optional[Any]								=      ids_tensor([self.batch_size]	,  self.type_sequence_label_size )

     _UpperCAmelCase		:       Optional[int]								=      self.get_config()

     return config, pixel_values, labels




   def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->Any:



     '''simple docstring'''







     return FocalNetConfig(
         image_size=self.image_size	,  patch_size=self.patch_size	,  num_channels=self.num_channels	,  embed_dim=self.embed_dim	,  hidden_sizes=self.hidden_sizes	,  depths=self.depths	,  num_heads=self.num_heads	,  window_size=self.window_size	,  mlp_ratio=self.mlp_ratio	,  qkv_bias=self.qkv_bias	,  hidden_dropout_prob=self.hidden_dropout_prob	,  attention_probs_dropout_prob=self.attention_probs_dropout_prob	,  drop_path_rate=self.drop_path_rate	,  hidden_act=self.hidden_act	,  use_absolute_embeddings=self.use_absolute_embeddings	,  path_norm=self.patch_norm	,  layer_norm_eps=self.layer_norm_eps	,  initializer_range=self.initializer_range	,  encoder_stride=self.encoder_stride	,  out_features=self.out_features	,  out_indices=self.out_indices	,  )




   def 							lowerCAmelCase__    (		self  :     List[Any]	,  lowerCamelCase__  :     List[str]	,  lowerCamelCase__  :     Optional[Any]	,  lowerCamelCase__  :     str )   ->Any:



     '''simple docstring'''







     _UpperCAmelCase		:       Tuple								=      FocalNetModel(config=lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()
     _UpperCAmelCase		:       List[Any]								=      model(lowerCamelCase__ )

     _UpperCAmelCase		:       List[Any]								=      ((config.image_size // config.patch_size) ** 2) // (4 ** (len(config.depths ) - 1))
     _UpperCAmelCase		:       Union[str, Any]								=      int(config.embed_dim * 2 ** (len(config.depths ) - 1) )

     self.parent.assertEqual(result.last_hidden_state.shape	,  (self.batch_size, expected_seq_len, expected_dim) )




   def 							lowerCAmelCase__    (		self  :     Dict	,  lowerCamelCase__  :     int	,  lowerCamelCase__  :     List[Any]	,  lowerCamelCase__  :     List[Any] )   ->Dict:



     '''simple docstring'''







     _UpperCAmelCase		:       Optional[int]								=      FocalNetBackbone(config=lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()
     _UpperCAmelCase		:       List[str]								=      model(lowerCamelCase__ )

     # 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.image_size, 8, 8] )

     # 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		:       Union[str, Any]								=      FocalNetBackbone(config=lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()
     _UpperCAmelCase		:       List[Any]								=      model(lowerCamelCase__ )

     # verify feature maps
     self.parent.assertEqual(len(result.feature_maps )	,  1 )
     self.parent.assertListEqual(list(result.feature_maps[0].shape )	,  [self.batch_size, self.image_size * 2, 4, 4] )

     # verify channels
     self.parent.assertEqual(len(model.channels )	,  1 )
     self.parent.assertListEqual(model.channels	,  [config.hidden_sizes[-1]] )




   def 							lowerCAmelCase__    (		self  :     List[str]	,  lowerCamelCase__  :     Any	,  lowerCamelCase__  :     Tuple	,  lowerCamelCase__  :     List[str] )   ->int:



     '''simple docstring'''







     _UpperCAmelCase		:       Dict								=      FocalNetForMaskedImageModeling(config=lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()
     _UpperCAmelCase		:       Union[str, Any]								=      model(lowerCamelCase__ )
     self.parent.assertEqual(
         result.reconstruction.shape	,  (self.batch_size, self.num_channels, self.image_size, self.image_size) )

     # test greyscale images
     _UpperCAmelCase		:       Optional[int]								=      1
     _UpperCAmelCase		:       Tuple								=      FocalNetForMaskedImageModeling(lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()

     _UpperCAmelCase		:       Tuple								=      floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
     _UpperCAmelCase		:       List[Any]								=      model(lowerCamelCase__ )
     self.parent.assertEqual(result.reconstruction.shape	,  (self.batch_size, 1, self.image_size, self.image_size) )




   def 							lowerCAmelCase__    (		self  :     Union[str, Any]	,  lowerCamelCase__  :     Optional[int]	,  lowerCamelCase__  :     Any	,  lowerCamelCase__  :     List[str] )   ->Optional[Any]:



     '''simple docstring'''







     _UpperCAmelCase		:       int								=      self.type_sequence_label_size
     _UpperCAmelCase		:       Any								=      FocalNetForImageClassification(lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()
     _UpperCAmelCase		:       Optional[int]								=      model(lowerCamelCase__	,  labels=lowerCamelCase__ )
     self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.type_sequence_label_size) )

     # test greyscale images
     _UpperCAmelCase		:       int								=      1
     _UpperCAmelCase		:       Dict								=      FocalNetForImageClassification(lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()

     _UpperCAmelCase		:       Union[str, Any]								=      floats_tensor([self.batch_size, 1, self.image_size, self.image_size] )
     _UpperCAmelCase		:       List[Any]								=      model(lowerCamelCase__ )
     self.parent.assertEqual(result.logits.shape	,  (self.batch_size, self.type_sequence_label_size) )






   def 							lowerCAmelCase__    (		self  :     Any )   ->Optional[Any]:



     '''simple docstring'''







     _UpperCAmelCase		:       int								=      self.prepare_config_and_inputs()

     _UpperCAmelCase		:       str								=      config_and_inputs
     _UpperCAmelCase		:       Optional[int]								=      {"pixel_values": pixel_values}
     return config, inputs_dict






@require_torch
class 	lowerCAmelCase__			(			UpperCAmelCase__    ,       UpperCAmelCase__    ,       unittest.TestCase	):
   lowerCAmelCase :	Optional[int]          =     (
       (
           FocalNetModel,
           FocalNetForImageClassification,
           FocalNetForMaskedImageModeling,
           FocalNetBackbone,
       )
       if is_torch_available()
       else ()
   )
   lowerCAmelCase :	Tuple          =     (
       {"feature-extraction": FocalNetModel, "image-classification": FocalNetForImageClassification}
       if is_torch_available()
       else {}
   )
   lowerCAmelCase :	Any          =     False

   lowerCAmelCase :	Optional[Any]          =     False
   lowerCAmelCase :	List[str]          =     False
   lowerCAmelCase :	Tuple          =     False
   lowerCAmelCase :	List[Any]          =     False




   def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->str:



     '''simple docstring'''







     _UpperCAmelCase		:       Tuple								=      FocalNetModelTester(self )
     _UpperCAmelCase		:       Tuple								=      ConfigTester(self	,  config_class=lowerCamelCase__	,  embed_dim=37	,  has_text_modality=lowerCamelCase__ )




   def 							lowerCAmelCase__    (		self  :     str )   ->int:



     '''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 							lowerCAmelCase__    (		self  :     List[str] )   ->Any:



     '''simple docstring'''







     return




   def 							lowerCAmelCase__    (		self  :     int )   ->Optional[int]:



     '''simple docstring'''







     _UpperCAmelCase		:       Tuple								=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*lowerCamelCase__ )




   def 							lowerCAmelCase__    (		self  :     Dict )   ->Union[str, Any]:



     '''simple docstring'''







     _UpperCAmelCase		:       Union[str, Any]								=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_backbone(*lowerCamelCase__ )




   def 							lowerCAmelCase__    (		self  :     Tuple )   ->List[str]:



     '''simple docstring'''







     _UpperCAmelCase		:       List[str]								=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_masked_image_modeling(*lowerCamelCase__ )




   def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->List[str]:



     '''simple docstring'''







     _UpperCAmelCase		:       Tuple								=      self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*lowerCamelCase__ )




   @unittest.skip(reason="FocalNet does not use inputs_embeds" )
   def 							lowerCAmelCase__    (		self  :     Tuple )   ->Tuple:



     '''simple docstring'''







     pass




   @unittest.skip(reason="FocalNet does not use feedforward chunking" )
   def 							lowerCAmelCase__    (		self  :     str )   ->int:



     '''simple docstring'''







     pass




   def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->str:



     '''simple docstring'''







     _UpperCAmelCase		:       List[Any]								=      self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes[:-1]:
       _UpperCAmelCase		:       Union[str, Any]								=      model_class(lowerCamelCase__ )
       self.assertIsInstance(model.get_input_embeddings()	,  (nn.Module) )
       _UpperCAmelCase		:       int								=      model.get_output_embeddings()
       self.assertTrue(x is None or isinstance(lowerCamelCase__	,  nn.Linear ) )




   def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->str:



     '''simple docstring'''







     _UpperCAmelCase		:       Union[str, Any]								=      self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes[:-1]:
       _UpperCAmelCase		:       Dict								=      model_class(lowerCamelCase__ )
       _UpperCAmelCase		:       List[str]								=      inspect.signature(model.forward )
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       _UpperCAmelCase		:       int								=      [*signature.parameters.keys()]

       _UpperCAmelCase		:       List[str]								=      ["pixel_values"]
       self.assertListEqual(arg_names[:1]	,  lowerCamelCase__ )




   def 							lowerCAmelCase__    (		self  :     List[str]	,  lowerCamelCase__  :     Any	,  lowerCamelCase__  :     List[str]	,  lowerCamelCase__  :     int	,  lowerCamelCase__  :     List[Any] )   ->str:



     '''simple docstring'''







     _UpperCAmelCase		:       int								=      model_class(lowerCamelCase__ )
     model.to(lowerCamelCase__ )
     model.eval()

     with torch.no_grad():
       _UpperCAmelCase		:       List[Any]								=      model(**self._prepare_for_class(lowerCamelCase__	,  lowerCamelCase__ ) )

     _UpperCAmelCase		:       Union[str, Any]								=      outputs.hidden_states

     _UpperCAmelCase		:       Union[str, Any]								=      getattr(
         self.model_tester	,  "expected_num_hidden_layers"	,  len(self.model_tester.depths ) + 1 )
     self.assertEqual(len(lowerCamelCase__ )	,  lowerCamelCase__ )

     # FocalNet has a different seq_length
     _UpperCAmelCase		:       int								=      (
         config.patch_size
         if isinstance(config.patch_size	,  collections.abc.Iterable )
         else (config.patch_size, config.patch_size)
     )

     _UpperCAmelCase		:       int								=      (image_size[1] // patch_size[1]) * (image_size[0] // patch_size[0])

     self.assertListEqual(
         list(hidden_states[0].shape[-2:] )	,  [num_patches, self.model_tester.embed_dim]	,  )

     _UpperCAmelCase		:       Optional[Any]								=      outputs.reshaped_hidden_states
     self.assertEqual(len(lowerCamelCase__ )	,  lowerCamelCase__ )

     _UpperCAmelCase		:       Optional[Any]								=      reshaped_hidden_states[0].shape
     _UpperCAmelCase		:       Optional[int]								=      (
         reshaped_hidden_states[0].view(lowerCamelCase__	,  lowerCamelCase__	,  height * width ).permute(0	,  2	,  1 )
     )
     self.assertListEqual(
         list(reshaped_hidden_states.shape[-2:] )	,  [num_patches, self.model_tester.embed_dim]	,  )




   def 							lowerCAmelCase__    (		self  :     Any )   ->Optional[Any]:



     '''simple docstring'''







     _UpperCAmelCase		:       int								=      self.model_tester.prepare_config_and_inputs_for_common()

     _UpperCAmelCase		:       Optional[Any]								=      (
         self.model_tester.image_size
         if isinstance(self.model_tester.image_size	,  collections.abc.Iterable )
         else (self.model_tester.image_size, self.model_tester.image_size)
     )

     for model_class in self.all_model_classes[:-1]:
       _UpperCAmelCase		:       Union[str, Any]								=      True
       self.check_hidden_states_output(lowerCamelCase__	,  lowerCamelCase__	,  lowerCamelCase__	,  lowerCamelCase__ )

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       _UpperCAmelCase		:       Any								=      True

       self.check_hidden_states_output(lowerCamelCase__	,  lowerCamelCase__	,  lowerCamelCase__	,  lowerCamelCase__ )




   def 							lowerCAmelCase__    (		self  :     Union[str, Any] )   ->Union[str, Any]:



     '''simple docstring'''







     _UpperCAmelCase		:       Dict								=      self.model_tester.prepare_config_and_inputs_for_common()
     _UpperCAmelCase		:       int								=      3

     _UpperCAmelCase		:       Optional[int]								=      (
         self.model_tester.image_size
         if isinstance(self.model_tester.image_size	,  collections.abc.Iterable )
         else (self.model_tester.image_size, self.model_tester.image_size)
     )
     _UpperCAmelCase		:       Any								=      (
         config.patch_size
         if isinstance(config.patch_size	,  collections.abc.Iterable )
         else (config.patch_size, config.patch_size)
     )

     _UpperCAmelCase		:       Optional[Any]								=      image_size[0] + patch_size[0] - (image_size[0] % patch_size[0])
     _UpperCAmelCase		:       Any								=      image_size[1] + patch_size[1] - (image_size[1] % patch_size[1])

     for model_class in self.all_model_classes[:-1]:
       _UpperCAmelCase		:       int								=      True
       self.check_hidden_states_output(lowerCamelCase__	,  lowerCamelCase__	,  lowerCamelCase__	,  (padded_height, padded_width) )

       # check that output_hidden_states also work using config
       del inputs_dict["output_hidden_states"]
       _UpperCAmelCase		:       str								=      True
       self.check_hidden_states_output(lowerCamelCase__	,  lowerCamelCase__	,  lowerCamelCase__	,  (padded_height, padded_width) )




   @slow
   def 							lowerCAmelCase__    (		self  :     Tuple )   ->List[str]:



     '''simple docstring'''







     for model_name in FOCALNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       _UpperCAmelCase		:       Optional[Any]								=      FocalNetModel.from_pretrained(lowerCamelCase__ )
       self.assertIsNotNone(lowerCamelCase__ )






   def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->Dict:



     '''simple docstring'''







     _UpperCAmelCase		:       Tuple								=      self.model_tester.prepare_config_and_inputs_for_common()

     _UpperCAmelCase		:       Tuple								=      _config_zero_init(lowerCamelCase__ )
     for model_class in self.all_model_classes:
       _UpperCAmelCase		:       List[str]								=      model_class(config=lowerCamelCase__ )
       for name, param in model.named_parameters():
         if "embeddings" not in name and 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"""	,  )






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




   @cached_property
   def 							lowerCAmelCase__    (		self  :     Optional[int] )   ->Tuple:



     '''simple docstring'''







     return AutoImageProcessor.from_pretrained("microsoft/focalnet-tiny" ) if is_vision_available() else None






   @slow
   def 							lowerCAmelCase__    (		self  :     List[str] )   ->Tuple:



     '''simple docstring'''







     _UpperCAmelCase		:       int								=      FocalNetForImageClassification.from_pretrained("microsoft/focalnet-tiny" ).to(lowerCamelCase__ )
     _UpperCAmelCase		:       Tuple								=      self.default_image_processor

     _UpperCAmelCase		:       Optional[int]								=      Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png" )
     _UpperCAmelCase		:       List[Any]								=      image_processor(images=lowerCamelCase__	,  return_tensors="pt" ).to(lowerCamelCase__ )

     # forward pass
     with torch.no_grad():
       _UpperCAmelCase		:       Dict								=      model(**lowerCamelCase__ )

     # verify the logits
     _UpperCAmelCase		:       List[Any]								=      torch.Size((1, 10_00) )
     self.assertEqual(outputs.logits.shape	,  lowerCamelCase__ )
     _UpperCAmelCase		:       Optional[Any]								=      torch.tensor([0.2_1_6_6, -0.4_3_6_8, 0.2_1_9_1] ).to(lowerCamelCase__ )
     self.assertTrue(torch.allclose(outputs.logits[0, :3]	,  lowerCamelCase__	,  atol=1E-4 ) )
     self.assertTrue(outputs.logits.argmax(dim=-1 ).item()	,  2_81 )






@require_torch
class 	lowerCAmelCase__			(			UpperCAmelCase__    ,       unittest.TestCase	):
   lowerCAmelCase :	str          =     (FocalNetBackbone,) if is_torch_available() else ()
   lowerCAmelCase :	int          =     FocalNetConfig

   lowerCAmelCase :	Tuple          =     False




   def 							lowerCAmelCase__    (		self  :     str )   ->int:



     '''simple docstring'''







     _UpperCAmelCase		:       List[str]								=      FocalNetModelTester(self )







'''simple docstring'''


from typing import List, Optional, Union

from ...image_utils import ImageInput
from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding, PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
from ...utils import TensorType






class 	lowerCAmelCase__			(			UpperCAmelCase__	):
			lowerCAmelCase :	Any          =     ["image_processor", "tokenizer"]
			lowerCAmelCase :	List[Any]          =     "BlipImageProcessor"
			lowerCAmelCase :	Union[str, Any]          =     "AutoTokenizer"




			def __init__(		self  :     Any	,  lowerCamelCase__  :     Tuple	,  lowerCamelCase__  :     int )   ->Optional[int]:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[int]								=      False
					super().__init__(lowerCamelCase__	,  lowerCamelCase__ )
					_UpperCAmelCase		:       Tuple								=      self.image_processor




			def __call__(		self  :     Dict	,  lowerCamelCase__  :     ImageInput = None	,  lowerCamelCase__  :     Union[TextInput, PreTokenizedInput, List[TextInput], List[PreTokenizedInput]] = None	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Union[bool, str, PaddingStrategy] = False	,  lowerCamelCase__  :     Union[bool, str, TruncationStrategy] = None	,  lowerCamelCase__  :     Optional[int] = None	,  lowerCamelCase__  :     int = 0	,  lowerCamelCase__  :     Optional[int] = None	,  lowerCamelCase__  :     Optional[bool] = None	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = False	,  lowerCamelCase__  :     bool = True	,  lowerCamelCase__  :     Optional[Union[str, TensorType]] = None	,  **lowerCamelCase__  :     Tuple	,  )   ->BatchEncoding:



					'''simple docstring'''







					if images is None and text is None:
							raise ValueError("You have to specify either images or text." )

					# Get only text
					if images is None:
							_UpperCAmelCase		:       Optional[int]								=      self.tokenizer
							_UpperCAmelCase		:       List[Any]								=      self.tokenizer(
							    text=lowerCamelCase__	,  add_special_tokens=lowerCamelCase__	,  padding=lowerCamelCase__	,  truncation=lowerCamelCase__	,  max_length=lowerCamelCase__	,  stride=lowerCamelCase__	,  pad_to_multiple_of=lowerCamelCase__	,  return_attention_mask=lowerCamelCase__	,  return_overflowing_tokens=lowerCamelCase__	,  return_special_tokens_mask=lowerCamelCase__	,  return_offsets_mapping=lowerCamelCase__	,  return_token_type_ids=lowerCamelCase__	,  return_length=lowerCamelCase__	,  verbose=lowerCamelCase__	,  return_tensors=lowerCamelCase__	,  **lowerCamelCase__	,  )
							return text_encoding

					# add pixel_values
					_UpperCAmelCase		:       Optional[int]								=      self.image_processor(lowerCamelCase__	,  return_tensors=lowerCamelCase__ )

					if text is not None:
							_UpperCAmelCase		:       Dict								=      self.tokenizer(
							    text=lowerCamelCase__	,  add_special_tokens=lowerCamelCase__	,  padding=lowerCamelCase__	,  truncation=lowerCamelCase__	,  max_length=lowerCamelCase__	,  stride=lowerCamelCase__	,  pad_to_multiple_of=lowerCamelCase__	,  return_attention_mask=lowerCamelCase__	,  return_overflowing_tokens=lowerCamelCase__	,  return_special_tokens_mask=lowerCamelCase__	,  return_offsets_mapping=lowerCamelCase__	,  return_token_type_ids=lowerCamelCase__	,  return_length=lowerCamelCase__	,  verbose=lowerCamelCase__	,  return_tensors=lowerCamelCase__	,  **lowerCamelCase__	,  )
					else:
							_UpperCAmelCase		:       int								=      None

					if text_encoding is not None:
							encoding_image_processor.update(lowerCamelCase__ )

					return encoding_image_processor




			def 							lowerCAmelCase__    (		self  :     List[Any]	,  *lowerCamelCase__  :     Optional[int]	,  **lowerCamelCase__  :     Dict )   ->Optional[Any]:



					'''simple docstring'''







					return self.tokenizer.batch_decode(*lowerCamelCase__	,  **lowerCamelCase__ )




			def 							lowerCAmelCase__    (		self  :     int	,  *lowerCamelCase__  :     Dict	,  **lowerCamelCase__  :     str )   ->Optional[int]:



					'''simple docstring'''







					return self.tokenizer.decode(*lowerCamelCase__	,  **lowerCamelCase__ )






			@property
			# Copied from transformers.models.blip.processing_blip.BlipProcessor.model_input_names
			def 							lowerCAmelCase__    (		self  :     Any )   ->Optional[int]:



					'''simple docstring'''







					_UpperCAmelCase		:       Optional[Any]								=      self.tokenizer.model_input_names
					_UpperCAmelCase		:       Dict								=      self.image_processor.model_input_names
					return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names ) )



