





'''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 PoolFormerImageProcessor


class 					SCREAMING_SNAKE_CASE       (unittest.TestCase				):


     def __init__(		self		,      _UpperCAmelCase		,      _UpperCAmelCase=7		,      _UpperCAmelCase=3		,      _UpperCAmelCase=30		,      _UpperCAmelCase=400		,      _UpperCAmelCase=True		,      _UpperCAmelCase=None		,      _UpperCAmelCase=0.9		,      _UpperCAmelCase=None		,      _UpperCAmelCase=True		,      _UpperCAmelCase=[0.5, 0.5, 0.5]		,      _UpperCAmelCase=[0.5, 0.5, 0.5]		,      ):

          '''simple docstring'''






          __A		:					List[Any]						=			size if size is not None else {'shortest_edge': 30}
          __A		:					int						=			crop_size if crop_size is not None else {'height': 30, 'width': 30}
          __A		:					Optional[Any]						=			parent
          __A		:					List[Any]						=			batch_size
          __A		:					Any						=			num_channels
          __A		:					Union[str, Any]						=			min_resolution
          __A		:					Union[str, Any]						=			max_resolution
          __A		:					int						=			do_resize_and_center_crop
          __A		:					int						=			size
          __A		:					List[str]						=			crop_pct
          __A		:					str						=			crop_size
          __A		:					Optional[Any]						=			do_normalize
          __A		:					Optional[int]						=			image_mean
          __A		:					Optional[Any]						=			image_std


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          return {
              "size": self.size,
              "do_resize_and_center_crop": self.do_resize_and_center_crop,
              "crop_pct": self.crop_pct,
              "crop_size": self.crop_size,
              "do_normalize": self.do_normalize,
              "image_mean": self.image_mean,
              "image_std": self.image_std,
          }




@require_torch
@require_vision
class 					SCREAMING_SNAKE_CASE       (a__   ,						unittest.TestCase				):
     lowerCAmelCase						     =			PoolFormerImageProcessor if is_vision_available() else None


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Union[str, Any]						=			PoolFormerImageProcessingTester(self)


     @property
     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          return self.image_processor_tester.prepare_image_processor_dict()


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Optional[int]						=			self.image_processing_class(**self.image_processor_dict)
          self.assertTrue(hasattr(_UpperCAmelCase		,      'do_resize_and_center_crop'))
          self.assertTrue(hasattr(_UpperCAmelCase		,      'size'))
          self.assertTrue(hasattr(_UpperCAmelCase		,      'crop_pct'))
          self.assertTrue(hasattr(_UpperCAmelCase		,      'do_normalize'))
          self.assertTrue(hasattr(_UpperCAmelCase		,      'image_mean'))
          self.assertTrue(hasattr(_UpperCAmelCase		,      'image_std'))


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Union[str, Any]						=			self.image_processing_class.from_dict(self.image_processor_dict)
          self.assertEqual(image_processor.size		,      {'shortest_edge': 30})
          self.assertEqual(image_processor.crop_size		,      {'height': 30, 'width': 30})

          __A		:					Tuple						=			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 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          pass


     def 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Dict						=			self.image_processing_class(**self.image_processor_dict)
          # create random PIL images
          __A		:					Union[str, Any]						=			prepare_image_inputs(self.image_processor_tester		,      equal_resolution=_UpperCAmelCase)
          for image in image_inputs:
               self.assertIsInstance(_UpperCAmelCase		,      Image.Image)

          # Test not batched input
          __A		:					List[Any]						=			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
          __A		:					Optional[int]						=			image_processing(_UpperCAmelCase		,      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 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					Dict						=			self.image_processing_class(**self.image_processor_dict)
          # create random numpy tensors
          __A		:					Optional[int]						=			prepare_image_inputs(self.image_processor_tester		,      equal_resolution=_UpperCAmelCase		,      numpify=_UpperCAmelCase)
          for image in image_inputs:
               self.assertIsInstance(_UpperCAmelCase		,      np.ndarray)

          # Test not batched input
          __A		:					str						=			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
          __A		:					Any						=			image_processing(_UpperCAmelCase		,      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 				SCREAMING_SNAKE_CASE    (		self):

          '''simple docstring'''






          __A		:					List[Any]						=			self.image_processing_class(**self.image_processor_dict)
          # create random PyTorch tensors
          __A		:					List[Any]						=			prepare_image_inputs(self.image_processor_tester		,      equal_resolution=_UpperCAmelCase		,      torchify=_UpperCAmelCase)
          for image in image_inputs:
               self.assertIsInstance(_UpperCAmelCase		,      torch.Tensor)

          # Test not batched input
          __A		:					Tuple						=			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
          __A		:					str						=			image_processing(_UpperCAmelCase		,      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'],
              )		,      )






'''simple docstring'''




from ...configuration_utils import PretrainedConfig
from ...utils import logging


lowercase__       : List[Any]         =       logging.get_logger(__name__)

lowercase__       : Optional[int]         =       {
    '''unc-nlp/lxmert-base-uncased''': '''https://huggingface.co/unc-nlp/lxmert-base-uncased/resolve/main/config.json''',
}


class 					SCREAMING_SNAKE_CASE       (a__				):
     lowerCAmelCase						     =			'''lxmert'''
     lowerCAmelCase						     =			{}


     def __init__(		self		,      _UpperCAmelCase=3_0522		,      _UpperCAmelCase=768		,      _UpperCAmelCase=12		,      _UpperCAmelCase=9500		,      _UpperCAmelCase=1600		,      _UpperCAmelCase=400		,      _UpperCAmelCase=3072		,      _UpperCAmelCase="gelu"		,      _UpperCAmelCase=0.1		,      _UpperCAmelCase=0.1		,      _UpperCAmelCase=512		,      _UpperCAmelCase=2		,      _UpperCAmelCase=0.02		,      _UpperCAmelCase=1e-1_2		,      _UpperCAmelCase=9		,      _UpperCAmelCase=5		,      _UpperCAmelCase=5		,      _UpperCAmelCase=2048		,      _UpperCAmelCase=4		,      _UpperCAmelCase=6.67		,      _UpperCAmelCase=True		,      _UpperCAmelCase=True		,      _UpperCAmelCase=True		,      _UpperCAmelCase=True		,      _UpperCAmelCase=True		,      _UpperCAmelCase=True		,      _UpperCAmelCase=True		,      **_UpperCAmelCase		,      ):

          '''simple docstring'''






          __A		:					Tuple						=			vocab_size
          __A		:					int						=			hidden_size
          __A		:					str						=			num_attention_heads
          __A		:					Tuple						=			hidden_act
          __A		:					int						=			intermediate_size
          __A		:					str						=			hidden_dropout_prob
          __A		:					Optional[int]						=			attention_probs_dropout_prob
          __A		:					Optional[Any]						=			max_position_embeddings
          __A		:					Tuple						=			type_vocab_size
          __A		:					Optional[int]						=			initializer_range
          __A		:					Any						=			layer_norm_eps
          __A		:					Optional[Any]						=			num_qa_labels
          __A		:					Optional[int]						=			num_object_labels
          __A		:					Any						=			num_attr_labels
          __A		:					Union[str, Any]						=			l_layers
          __A		:					Optional[int]						=			x_layers
          __A		:					List[Any]						=			r_layers
          __A		:					Tuple						=			visual_feat_dim
          __A		:					Tuple						=			visual_pos_dim
          __A		:					Optional[int]						=			visual_loss_normalizer
          __A		:					int						=			task_matched
          __A		:					List[Any]						=			task_mask_lm
          __A		:					Optional[Any]						=			task_obj_predict
          __A		:					str						=			task_qa
          __A		:					List[Any]						=			visual_obj_loss
          __A		:					Optional[Any]						=			visual_attr_loss
          __A		:					Union[str, Any]						=			visual_feat_loss
          __A		:					Union[str, Any]						=			{'vision': r_layers, 'cross_encoder': x_layers, 'language': l_layers}
          super().__init__(**_UpperCAmelCase)