




import tempfile
import unittest

from transformers import DPRConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import DPRContextEncoder, DPRQuestionEncoder, DPRReader, DPRReaderTokenizer
		from transformers.models.dpr.modeling_dpr import (
		    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
		    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
		)




class       UpperCAmelCase_   :




							'''simple docstring'''



							def __init__(       self							:						Dict							,  a							:						Optional[Any]							,  a							:						int=13							,  a							:						int=7							,  a							:						Any=False							,  a							:						Union[str, Any]=True							,  a							:						Union[str, Any]=True							,  a							:						Tuple=True							,  a							:						Dict=99							,  a							:						Optional[int]=32							,  a							:						Any=5							,  a							:						Tuple=4							,  a							:						List[str]=37							,  a							:						Optional[Any]="gelu"							,  a							:						Tuple=0.1							,  a							:						List[str]=0.1							,  a							:						List[str]=512							,  a							:						Tuple=16							,  a							:						str=2							,  a							:						List[str]=0.02							,  a							:						int=3							,  a							:						Tuple=4							,  a							:						str=None							,  a							:						str=0							,  )      ->       List[str]:
										SCREAMING_SNAKE_CASE     =       parent
										SCREAMING_SNAKE_CASE     =       batch_size
										SCREAMING_SNAKE_CASE     =       seq_length
										SCREAMING_SNAKE_CASE     =       is_training
										SCREAMING_SNAKE_CASE     =       use_input_mask
										SCREAMING_SNAKE_CASE     =       use_token_type_ids
										SCREAMING_SNAKE_CASE     =       use_labels
										SCREAMING_SNAKE_CASE     =       vocab_size
										SCREAMING_SNAKE_CASE     =       hidden_size
										SCREAMING_SNAKE_CASE     =       num_hidden_layers
										SCREAMING_SNAKE_CASE     =       num_attention_heads
										SCREAMING_SNAKE_CASE     =       intermediate_size
										SCREAMING_SNAKE_CASE     =       hidden_act
										SCREAMING_SNAKE_CASE     =       hidden_dropout_prob
										SCREAMING_SNAKE_CASE     =       attention_probs_dropout_prob
										SCREAMING_SNAKE_CASE     =       max_position_embeddings
										SCREAMING_SNAKE_CASE     =       type_vocab_size
										SCREAMING_SNAKE_CASE     =       type_sequence_label_size
										SCREAMING_SNAKE_CASE     =       initializer_range
										SCREAMING_SNAKE_CASE     =       num_labels
										SCREAMING_SNAKE_CASE     =       num_choices
										SCREAMING_SNAKE_CASE     =       scope
										SCREAMING_SNAKE_CASE     =       projection_dim





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Optional[Any]:
										SCREAMING_SNAKE_CASE     =       ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size      )

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

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

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

										SCREAMING_SNAKE_CASE     =       self.get_config()

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





							def  _UpperCAmelCase  (       self							:						List[Any]      )      ->       List[Any]:
										return DPRConfig(
										    projection_dim=self.projection_dim							,  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							,  )





							def  _UpperCAmelCase  (       self							:						Optional[Any]							,  a							:						List[str]							,  a							:						List[str]							,  a							:						List[Any]							,  a							:						str							,  a							:						Tuple							,  a							:						List[str]							,  a							:						List[Any]      )      ->       Tuple:
										SCREAMING_SNAKE_CASE     =       DPRContextEncoder(config=a      )
										model.to(a      )
										model.eval()
										SCREAMING_SNAKE_CASE     =       model(a							,  attention_mask=a							,  token_type_ids=a      )
										SCREAMING_SNAKE_CASE     =       model(a							,  token_type_ids=a      )
										SCREAMING_SNAKE_CASE     =       model(a      )
										self.parent.assertEqual(result.pooler_output.shape							,  (self.batch_size, self.projection_dim or self.hidden_size)      )





							def  _UpperCAmelCase  (       self							:						Tuple							,  a							:						List[Any]							,  a							:						Optional[Any]							,  a							:						List[Any]							,  a							:						str							,  a							:						List[Any]							,  a							:						Tuple							,  a							:						List[Any]      )      ->       Optional[Any]:
										SCREAMING_SNAKE_CASE     =       DPRQuestionEncoder(config=a      )
										model.to(a      )
										model.eval()
										SCREAMING_SNAKE_CASE     =       model(a							,  attention_mask=a							,  token_type_ids=a      )
										SCREAMING_SNAKE_CASE     =       model(a							,  token_type_ids=a      )
										SCREAMING_SNAKE_CASE     =       model(a      )
										self.parent.assertEqual(result.pooler_output.shape							,  (self.batch_size, self.projection_dim or self.hidden_size)      )





							def  _UpperCAmelCase  (       self							:						str							,  a							:						Any							,  a							:						Optional[int]							,  a							:						Optional[int]							,  a							:						Tuple							,  a							:						Union[str, Any]							,  a							:						Any							,  a							:						List[Any]      )      ->       Optional[int]:
										SCREAMING_SNAKE_CASE     =       DPRReader(config=a      )
										model.to(a      )
										model.eval()
										SCREAMING_SNAKE_CASE     =       model(
										    a							,  attention_mask=a							,  )

										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)      )
										self.parent.assertEqual(result.relevance_logits.shape							,  (self.batch_size,)      )







							def  _UpperCAmelCase  (       self							:						Union[str, Any]      )      ->       Optional[Any]:
										SCREAMING_SNAKE_CASE     =       self.prepare_config_and_inputs()
										(
										    (
										    SCREAMING_SNAKE_CASE
										)  ,	(
										    SCREAMING_SNAKE_CASE
										)  ,	(
										    SCREAMING_SNAKE_CASE
										)  ,	(
										    SCREAMING_SNAKE_CASE
										)  ,	(
										    SCREAMING_SNAKE_CASE
										)  ,	(
										    SCREAMING_SNAKE_CASE
										)  ,	(
										    SCREAMING_SNAKE_CASE
										)  ,	
										)     =       config_and_inputs
										SCREAMING_SNAKE_CASE     =       {"""input_ids""": input_ids}
										return config, inputs_dict





@require_torch
class       UpperCAmelCase_   ( A		,   A		,   unittest.TestCase							):




							'''simple docstring'''



							a__    	=  (
							    (
							        DPRContextEncoder,
							        DPRQuestionEncoder,
							        DPRReader,
							    )
							    if is_torch_available()
							    else ()
							)
							a__    	=  {'''feature-extraction''': DPRQuestionEncoder} if is_torch_available() else {}

							a__    	=  False
							a__    	=  False  # why?
							a__    	=  False
							a__    	=  False





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       int:
										SCREAMING_SNAKE_CASE     =       DPRModelTester(self      )
										SCREAMING_SNAKE_CASE     =       ConfigTester(self							,  config_class=a							,  hidden_size=37      )





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       Optional[Any]:
										self.config_tester.run_common_tests()





							def  _UpperCAmelCase  (       self							:						int      )      ->       Optional[int]:
										SCREAMING_SNAKE_CASE     =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_context_encoder(*a      )





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       Dict:
										SCREAMING_SNAKE_CASE     =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_question_encoder(*a      )





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       int:
										SCREAMING_SNAKE_CASE     =       self.model_tester.prepare_config_and_inputs()
										self.model_tester.create_and_check_reader(*a      )





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       int:
										SCREAMING_SNAKE_CASE     =       self.model_tester.prepare_config_and_inputs()[0]

										SCREAMING_SNAKE_CASE     =       DPRQuestionEncoder(config=a      )
										model.to(a      )
										model.eval()

										with tempfile.TemporaryDirectory() as tmp_dirname:
													model.save_pretrained(a      )
													SCREAMING_SNAKE_CASE     =       DPRQuestionEncoder.from_pretrained(a							,  projection_dim=512      )

										self.assertIsNotNone(a      )







							@slow
							def  _UpperCAmelCase  (       self							:						str      )      ->       str:
										for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													SCREAMING_SNAKE_CASE     =       DPRContextEncoder.from_pretrained(a      )
													self.assertIsNotNone(a      )

										for model_name in DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													SCREAMING_SNAKE_CASE     =       DPRContextEncoder.from_pretrained(a      )
													self.assertIsNotNone(a      )

										for model_name in DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													SCREAMING_SNAKE_CASE     =       DPRQuestionEncoder.from_pretrained(a      )
													self.assertIsNotNone(a      )

										for model_name in DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
													SCREAMING_SNAKE_CASE     =       DPRReader.from_pretrained(a      )
													self.assertIsNotNone(a      )





@require_torch
class       UpperCAmelCase_   ( unittest.TestCase							):




							'''simple docstring'''



							@slow
							def  _UpperCAmelCase  (       self							:						List[Any]      )      ->       str:
										SCREAMING_SNAKE_CASE     =       DPRQuestionEncoder.from_pretrained("""facebook/dpr-question_encoder-single-nq-base"""							,  return_dict=a      )
										model.to(a      )

										SCREAMING_SNAKE_CASE     =       torch.tensor(
										    [[101, 7_592, 1_010, 2_003, 2_026, 3_899, 10_140, 1_029, 102]]							,  dtype=torch.long							,  device=a      )  # [CLS] hello, is my dog cute? [SEP]
										SCREAMING_SNAKE_CASE     =       model(a      )[0]  # embedding shape = (1, 768)
										# compare the actual values for a slice.
										SCREAMING_SNAKE_CASE     =       torch.tensor(
										    [
										        [
										            0.0323_6253,
										            0.1275_3335,
										            0.1681_8509,
										            0.0027_9786,
										            0.389_6933,
										            0.2426_4945,
										            0.217_8971,
										            -0.0233_5227,
										            -0.0848_1959,
										            -0.1432_4117,
										        ]
										    ]							,  dtype=torch.float							,  device=a							,  )
										self.assertTrue(torch.allclose(output[:, :10]							,  a							,  atol=1E-4      )      )







							@slow
							def  _UpperCAmelCase  (       self							:						Optional[int]      )      ->       Any:
										SCREAMING_SNAKE_CASE     =       DPRReaderTokenizer.from_pretrained("""facebook/dpr-reader-single-nq-base"""      )
										SCREAMING_SNAKE_CASE     =       DPRReader.from_pretrained("""facebook/dpr-reader-single-nq-base"""      )
										model.to(a      )

										SCREAMING_SNAKE_CASE     =       tokenizer(
										    questions="""What is love ?"""							,  titles="""Haddaway"""							,  texts="""What Is Love is a song recorded by the artist Haddaway"""							,  padding=a							,  return_tensors="""pt"""							,  )
										encoded_inputs.to(a      )

										SCREAMING_SNAKE_CASE     =       model(**a      )

										# compare the actual values for a slice.
										SCREAMING_SNAKE_CASE     =       torch.tensor(
										    [[-10.3005, -10.7765, -11.4872, -11.6841, -11.9312, -10.3002, -9.8544, -11.7378, -12.0821, -10.2975]]							,  dtype=torch.float							,  device=a							,  )

										SCREAMING_SNAKE_CASE     =       torch.tensor(
										    [[-11.0684, -11.7041, -11.5397, -10.3465, -10.8791, -6.8443, -11.9959, -11.0364, -10.0096, -6.8405]]							,  dtype=torch.float							,  device=a							,  )
										self.assertTrue(torch.allclose(outputs.start_logits[:, :10]							,  a							,  atol=1E-4      )      )
										self.assertTrue(torch.allclose(outputs.end_logits[:, :10]							,  a							,  atol=1E-4      )      )












import random
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():
		import PIL

		from transformers import FlavaImageProcessor
		from transformers.image_utils import PILImageResampling
		from transformers.models.flava.image_processing_flava import (
		    FLAVA_CODEBOOK_MEAN,
		    FLAVA_CODEBOOK_STD,
		    FLAVA_IMAGE_MEAN,
		    FLAVA_IMAGE_STD,
		)
else:
		__A    :				List[str]    						=	None




class       UpperCAmelCase_   ( unittest.TestCase							):




							'''simple docstring'''



							def __init__(       self							:						Dict							,  a							:						List[Any]							,  a							:						Tuple=7							,  a							:						Dict=3							,  a							:						List[Any]=30							,  a							:						List[Any]=400							,  a							:						Optional[Any]=True							,  a							:						Optional[int]=None							,  a							:						Any=True							,  a							:						Union[str, Any]=None							,  a							:						Union[str, Any]=None							,  a							:						List[Any]=True							,  a							:						Union[str, Any]=1 / 255							,  a							:						Optional[Any]=True							,  a							:						int=FLAVA_IMAGE_MEAN							,  a							:						int=FLAVA_IMAGE_STD							,  a							:						Tuple=14							,  a							:						str=75							,  a							:						str=None							,  a							:						int=16							,  a							:						List[str]=0.3							,  a							:						Optional[Any]=None							,  a							:						int=True							,  a							:						int=None							,  a							:						Optional[int]=None							,  a							:						Optional[Any]=True							,  a							:						List[Any]=None							,  a							:						str=True							,  a							:						int=True							,  a							:						str=FLAVA_CODEBOOK_MEAN							,  a							:						str=FLAVA_CODEBOOK_STD							,  )      ->       List[str]:
										SCREAMING_SNAKE_CASE     =       size if size is not None else {"""height""": 224, """width""": 224}
										SCREAMING_SNAKE_CASE     =       crop_size if crop_size is not None else {"""height""": 224, """width""": 224}
										SCREAMING_SNAKE_CASE     =       codebook_size if codebook_size is not None else {"""height""": 112, """width""": 112}
										SCREAMING_SNAKE_CASE     =       codebook_crop_size if codebook_crop_size is not None else {"""height""": 112, """width""": 112}

										SCREAMING_SNAKE_CASE     =       parent
										SCREAMING_SNAKE_CASE     =       batch_size
										SCREAMING_SNAKE_CASE     =       num_channels
										SCREAMING_SNAKE_CASE     =       do_resize
										SCREAMING_SNAKE_CASE     =       do_rescale
										SCREAMING_SNAKE_CASE     =       rescale_factor
										SCREAMING_SNAKE_CASE     =       min_resolution
										SCREAMING_SNAKE_CASE     =       max_resolution
										SCREAMING_SNAKE_CASE     =       size
										SCREAMING_SNAKE_CASE     =       resample if resample is not None else PILImageResampling.BICUBIC
										SCREAMING_SNAKE_CASE     =       do_normalize
										SCREAMING_SNAKE_CASE     =       image_mean
										SCREAMING_SNAKE_CASE     =       image_std
										SCREAMING_SNAKE_CASE     =       do_center_crop
										SCREAMING_SNAKE_CASE     =       crop_size

										SCREAMING_SNAKE_CASE     =       input_size_patches
										SCREAMING_SNAKE_CASE     =       total_mask_patches
										SCREAMING_SNAKE_CASE     =       mask_group_max_patches
										SCREAMING_SNAKE_CASE     =       mask_group_min_patches
										SCREAMING_SNAKE_CASE     =       mask_group_min_aspect_ratio
										SCREAMING_SNAKE_CASE     =       mask_group_max_aspect_ratio

										SCREAMING_SNAKE_CASE     =       codebook_do_resize
										SCREAMING_SNAKE_CASE     =       codebook_size
										SCREAMING_SNAKE_CASE     =       codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
										SCREAMING_SNAKE_CASE     =       codebook_do_center_crop
										SCREAMING_SNAKE_CASE     =       codebook_crop_size
										SCREAMING_SNAKE_CASE     =       codebook_do_map_pixels
										SCREAMING_SNAKE_CASE     =       codebook_do_normalize
										SCREAMING_SNAKE_CASE     =       codebook_image_mean
										SCREAMING_SNAKE_CASE     =       codebook_image_std





							def  _UpperCAmelCase  (       self							:						str      )      ->       str:
										return {
										    "image_mean": self.image_mean,
										    "image_std": self.image_std,
										    "do_normalize": self.do_normalize,
										    "do_resize": self.do_resize,
										    "size": self.size,
										    "resample": self.resample,
										    "do_rescale": self.do_rescale,
										    "rescale_factor": self.rescale_factor,
										    "do_center_crop": self.do_center_crop,
										    "crop_size": self.crop_size,
										    "input_size_patches": self.input_size_patches,
										    "total_mask_patches": self.total_mask_patches,
										    "mask_group_max_patches": self.mask_group_max_patches,
										    "mask_group_min_patches": self.mask_group_min_patches,
										    "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
										    "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
										    "codebook_do_resize": self.codebook_do_resize,
										    "codebook_size": self.codebook_size,
										    "codebook_resample": self.codebook_resample,
										    "codebook_do_center_crop": self.codebook_do_center_crop,
										    "codebook_crop_size": self.codebook_crop_size,
										    "codebook_do_map_pixels": self.codebook_do_map_pixels,
										    "codebook_do_normalize": self.codebook_do_normalize,
										    "codebook_image_mean": self.codebook_image_mean,
										    "codebook_image_std": self.codebook_image_std,
										}





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       List[Any]:
										return (self.size["height"], self.size["width"])





							def  _UpperCAmelCase  (       self							:						int      )      ->       int:
										return (
										    (self.input_size_patches, self.input_size_patches)
										    if not isinstance(self.input_size_patches							,  a      )
										    else self.input_size_patches
										)







							def  _UpperCAmelCase  (       self							:						str      )      ->       List[Any]:
										return (self.codebook_size["height"], self.codebook_size["width"])





@require_torch
@require_vision
class       UpperCAmelCase_   ( A		,   unittest.TestCase							):




							'''simple docstring'''



							a__    	=  FlavaImageProcessor if is_vision_available() else None
							a__    	=  None





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Any:
										SCREAMING_SNAKE_CASE     =       FlavaImageProcessingTester(self      )





							@property
							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Any:
										return self.image_processor_tester.prepare_image_processor_dict()





							def  _UpperCAmelCase  (       self							:						Optional[int]      )      ->       str:
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										self.assertTrue(hasattr(a							,  """image_mean"""      )      )
										self.assertTrue(hasattr(a							,  """image_std"""      )      )
										self.assertTrue(hasattr(a							,  """do_normalize"""      )      )
										self.assertTrue(hasattr(a							,  """do_resize"""      )      )
										self.assertTrue(hasattr(a							,  """resample"""      )      )
										self.assertTrue(hasattr(a							,  """crop_size"""      )      )
										self.assertTrue(hasattr(a							,  """do_center_crop"""      )      )
										self.assertTrue(hasattr(a							,  """do_rescale"""      )      )
										self.assertTrue(hasattr(a							,  """rescale_factor"""      )      )
										self.assertTrue(hasattr(a							,  """masking_generator"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_resize"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_size"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_resample"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_center_crop"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_crop_size"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_map_pixels"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_do_normalize"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_image_mean"""      )      )
										self.assertTrue(hasattr(a							,  """codebook_image_std"""      )      )





							def  _UpperCAmelCase  (       self							:						Union[str, Any]      )      ->       Optional[Any]:
										SCREAMING_SNAKE_CASE     =       self.image_processing_class.from_dict(self.image_processor_dict      )
										self.assertEqual(image_processor.size							,  {"""height""": 224, """width""": 224}      )
										self.assertEqual(image_processor.crop_size							,  {"""height""": 224, """width""": 224}      )
										self.assertEqual(image_processor.codebook_size							,  {"""height""": 112, """width""": 112}      )
										self.assertEqual(image_processor.codebook_crop_size							,  {"""height""": 112, """width""": 112}      )

										SCREAMING_SNAKE_CASE     =       self.image_processing_class.from_dict(
										    self.image_processor_dict							,  size=42							,  crop_size=84							,  codebook_size=33							,  codebook_crop_size=66      )
										self.assertEqual(image_processor.size							,  {"""height""": 42, """width""": 42}      )
										self.assertEqual(image_processor.crop_size							,  {"""height""": 84, """width""": 84}      )
										self.assertEqual(image_processor.codebook_size							,  {"""height""": 33, """width""": 33}      )
										self.assertEqual(image_processor.codebook_crop_size							,  {"""height""": 66, """width""": 66}      )





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       Optional[int]:
										pass





							def  _UpperCAmelCase  (       self							:						Optional[Any]      )      ->       Union[str, Any]:
										# Initialize image_processing
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										# create random PIL images
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a      )
										for image in image_inputs:
													self.assertIsInstance(a							,  PIL.Image.Image      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_tensors="""pt"""      )

										# Test no bool masked pos
										self.assertFalse("""bool_masked_pos""" in encoded_images      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()

										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)							,  )

										# Test batched
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_tensors="""pt"""      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()

										# Test no bool masked pos
										self.assertFalse("""bool_masked_pos""" in encoded_images      )

										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )





							def  _UpperCAmelCase  (       self							:						Any							,  a							:						List[str]							,  a							:						Tuple      )      ->       Union[str, Any]:
										# Initialize image_processing
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										# create random tensors
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a							,  **a      )
										for image in image_inputs:
													self.assertIsInstance(a							,  a      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_tensors="""pt"""      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)							,  )

										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_image_mask=a							,  return_tensors="""pt"""      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_mask_size()
										self.assertEqual(
										    encoded_images.bool_masked_pos.shape							,  (
										        self.image_processor_tester.batch_size,
										        expected_height,
										        expected_width,
										    )							,  )

										# Test batched
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_tensors="""pt"""      ).pixel_values

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )

										# Test masking
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_image_mask=a							,  return_tensors="""pt"""      )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_image_size()
										self.assertEqual(
										    encoded_images.pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )

										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_mask_size()
										self.assertEqual(
										    encoded_images.bool_masked_pos.shape							,  (
										        self.image_processor_tester.batch_size,
										        expected_height,
										        expected_width,
										    )							,  )





							def  _UpperCAmelCase  (       self							:						Optional[int]      )      ->       Dict:
										self._test_call_framework(np.ndarray							,  prepare_kwargs={"""numpify""": True}      )





							def  _UpperCAmelCase  (       self							:						Dict      )      ->       Dict:
										self._test_call_framework(torch.Tensor							,  prepare_kwargs={"""torchify""": True}      )





							def  _UpperCAmelCase  (       self							:						str      )      ->       Optional[int]:
										# Initialize image_processing
										random.seed(1_234      )
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a							,  torchify=a      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_image_mask=a							,  return_tensors="""pt"""      )
										self.assertEqual(encoded_images.bool_masked_pos.sum().item()							,  75      )







							def  _UpperCAmelCase  (       self							:						List[str]      )      ->       Tuple:
										# Initialize image_processing
										SCREAMING_SNAKE_CASE     =       self.image_processing_class(**self.image_processor_dict      )
										# create random PIL images
										SCREAMING_SNAKE_CASE     =       prepare_image_inputs(self.image_processor_tester							,  equal_resolution=a      )
										for image in image_inputs:
													self.assertIsInstance(a							,  PIL.Image.Image      )

										# Test not batched input
										SCREAMING_SNAKE_CASE     =       image_processing(image_inputs[0]							,  return_codebook_pixels=a							,  return_tensors="""pt"""      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_codebook_image_size()
										self.assertEqual(
										    encoded_images.codebook_pixel_values.shape							,  (1, self.image_processor_tester.num_channels, expected_height, expected_width)							,  )

										# Test batched
										SCREAMING_SNAKE_CASE     =       image_processing(a							,  return_codebook_pixels=a							,  return_tensors="""pt"""      )
										SCREAMING_SNAKE_CASE  ,	SCREAMING_SNAKE_CASE     =       self.image_processor_tester.get_expected_codebook_image_size()
										self.assertEqual(
										    encoded_images.codebook_pixel_values.shape							,  (
										        self.image_processor_tester.batch_size,
										        self.image_processor_tester.num_channels,
										        expected_height,
										        expected_width,
										    )							,  )






