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   lowercase			:




							def __init__(  self      :    Tuple		,							_UpperCamelCase      :    Optional[int]		,							_UpperCamelCase      :    int=13		,							_UpperCamelCase      :    Dict=7		,							_UpperCamelCase      :    Dict=False		,							_UpperCamelCase      :    List[Any]=True		,							_UpperCamelCase      :    Union[str, Any]=True		,							_UpperCamelCase      :    int=True		,							_UpperCamelCase      :    Dict=99		,							_UpperCamelCase      :    Union[str, Any]=32		,							_UpperCamelCase      :    Optional[Any]=5		,							_UpperCamelCase      :    List[str]=4		,							_UpperCamelCase      :    int=37		,							_UpperCamelCase      :    Dict="gelu"		,							_UpperCamelCase      :    Any=0.1		,							_UpperCamelCase      :    Tuple=0.1		,							_UpperCamelCase      :    Union[str, Any]=512		,							_UpperCamelCase      :    List[str]=16		,							_UpperCamelCase      :    Any=2		,							_UpperCamelCase      :    Dict=0.0_2		,							_UpperCamelCase      :    str=3		,							_UpperCamelCase      :    str=4		,							_UpperCamelCase      :    List[Any]=None		,							_UpperCamelCase      :    Dict=0		,							)    -> Optional[int]:



												'''simple docstring'''

												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 		__snake_case(  self      :    Optional[Any]					)    -> str:



												'''simple docstring'''

												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 		__snake_case(  self      :    Dict					)    -> str:



												'''simple docstring'''

												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 		__snake_case(  self      :    Optional[int]		,							_UpperCamelCase      :    int		,							_UpperCamelCase      :    Dict		,							_UpperCamelCase      :    List[Any]		,							_UpperCamelCase      :    Optional[Any]		,							_UpperCamelCase      :    Tuple		,							_UpperCamelCase      :    Any		,							_UpperCamelCase      :    Dict					)    -> Optional[int]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				DPRContextEncoder(config=snake_case__					)
												model.to(snake_case__					)
												model.eval()
												SCREAMING_SNAKE_CASE				=				model(snake_case__		,							attention_mask=snake_case__		,							token_type_ids=snake_case__					)
												SCREAMING_SNAKE_CASE				=				model(snake_case__		,							token_type_ids=snake_case__					)
												SCREAMING_SNAKE_CASE				=				model(snake_case__					)
												self.parent.assertEqual(result.pooler_output.shape		,							(self.batch_size, self.projection_dim or self.hidden_size)					)




							def 		__snake_case(  self      :    List[str]		,							_UpperCamelCase      :    int		,							_UpperCamelCase      :    int		,							_UpperCamelCase      :    Any		,							_UpperCamelCase      :    List[Any]		,							_UpperCamelCase      :    Tuple		,							_UpperCamelCase      :    str		,							_UpperCamelCase      :    List[str]					)    -> Optional[int]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				DPRQuestionEncoder(config=snake_case__					)
												model.to(snake_case__					)
												model.eval()
												SCREAMING_SNAKE_CASE				=				model(snake_case__		,							attention_mask=snake_case__		,							token_type_ids=snake_case__					)
												SCREAMING_SNAKE_CASE				=				model(snake_case__		,							token_type_ids=snake_case__					)
												SCREAMING_SNAKE_CASE				=				model(snake_case__					)
												self.parent.assertEqual(result.pooler_output.shape		,							(self.batch_size, self.projection_dim or self.hidden_size)					)




							def 		__snake_case(  self      :    List[Any]		,							_UpperCamelCase      :    List[str]		,							_UpperCamelCase      :    int		,							_UpperCamelCase      :    Optional[Any]		,							_UpperCamelCase      :    Dict		,							_UpperCamelCase      :    Union[str, Any]		,							_UpperCamelCase      :    Optional[int]		,							_UpperCamelCase      :    Tuple					)    -> int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				DPRReader(config=snake_case__					)
												model.to(snake_case__					)
												model.eval()
												SCREAMING_SNAKE_CASE				=				model(
												    snake_case__		,							attention_mask=snake_case__		,							)

												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 		__snake_case(  self      :    int					)    -> str:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.prepare_config_and_inputs()
												(
												    SCREAMING_SNAKE_CASE	
												)				=				config_and_inputs
												SCREAMING_SNAKE_CASE				=				{"input_ids": input_ids}
												return config, inputs_dict



@require_torch
class   lowercase			(   SCREAMING_SNAKE_CASE__ ,				SCREAMING_SNAKE_CASE__ ,				unittest.TestCase   ):
							lowercase__  :				Optional[Any]									=							(
							    (
							        DPRContextEncoder,
							        DPRQuestionEncoder,
							        DPRReader,
							    )
							    if is_torch_available()
							    else ()
							)
							lowercase__  :				Any									=							{"""feature-extraction""": DPRQuestionEncoder} if is_torch_available() else {}

							lowercase__  :				Any									=							False
							lowercase__  :				List[Any]									=							False  # why?
							lowercase__  :				Optional[int]									=							False
							lowercase__  :				List[str]									=							False




							def 		__snake_case(  self      :    Union[str, Any]					)    -> Optional[int]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				DPRModelTester(self					)
												SCREAMING_SNAKE_CASE				=				ConfigTester(self		,							config_class=snake_case__		,							hidden_size=37					)




							def 		__snake_case(  self      :    Dict					)    -> Dict:



												'''simple docstring'''

												self.config_tester.run_common_tests()




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_context_encoder(*snake_case__					)




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_question_encoder(*snake_case__					)




							def 		__snake_case(  self      :    str					)    -> Optional[Any]:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.model_tester.prepare_config_and_inputs()
												self.model_tester.create_and_check_reader(*snake_case__					)




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



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				self.model_tester.prepare_config_and_inputs()[0]

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

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

												self.assertIsNotNone(snake_case__					)





							@slow
							def 		__snake_case(  self      :    Union[str, Any]					)    -> Tuple:



												'''simple docstring'''

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

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

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

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



@require_torch
class   lowercase			(   unittest.TestCase   ):




							@slow
							def 		__snake_case(  self      :    Dict					)    -> int:



												'''simple docstring'''

												SCREAMING_SNAKE_CASE				=				DPRQuestionEncoder.from_pretrained("facebook/dpr-question_encoder-single-nq-base"		,							return_dict=snake_case__					)
												model.to(snake_case__					)

												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=snake_case__					)  # [CLS] hello, is my dog cute? [SEP]
												SCREAMING_SNAKE_CASE				=				model(snake_case__					)[0]  # embedding shape = (1, 768)
												# compare the actual values for a slice.
												SCREAMING_SNAKE_CASE				=				torch.tensor(
												    [
												        [
												            0.0_3_2_3_6_2_5_3,
												            0.1_2_7_5_3_3_3_5,
												            0.1_6_8_1_8_5_0_9,
												            0.0_0_2_7_9_7_8_6,
												            0.3_8_9_6_9_3_3,
												            0.2_4_2_6_4_9_4_5,
												            0.2_1_7_8_9_7_1,
												            -0.0_2_3_3_5_2_2_7,
												            -0.0_8_4_8_1_9_5_9,
												            -0.1_4_3_2_4_1_1_7,
												        ]
												    ]		,							dtype=torch.float		,							device=snake_case__		,							)
												self.assertTrue(torch.allclose(output[:, :10]		,							snake_case__		,							atol=1e-4					)					)





							@slow
							def 		__snake_case(  self      :    Optional[Any]					)    -> Optional[int]:



												'''simple docstring'''

												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(snake_case__					)

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

												SCREAMING_SNAKE_CASE				=				model(**snake_case__					)

												# compare the actual values for a slice.
												SCREAMING_SNAKE_CASE				=				torch.tensor(
												    [[-1_0.3_0_0_5, -1_0.7_7_6_5, -1_1.4_8_7_2, -1_1.6_8_4_1, -1_1.9_3_1_2, -1_0.3_0_0_2, -9.8_5_4_4, -1_1.7_3_7_8, -1_2.0_8_2_1, -1_0.2_9_7_5]]		,							dtype=torch.float		,							device=snake_case__		,							)

												SCREAMING_SNAKE_CASE				=				torch.tensor(
												    [[-1_1.0_6_8_4, -1_1.7_0_4_1, -1_1.5_3_9_7, -1_0.3_4_6_5, -1_0.8_7_9_1, -6.8_4_4_3, -1_1.9_9_5_9, -1_1.0_3_6_4, -1_0.0_0_9_6, -6.8_4_0_5]]		,							dtype=torch.float		,							device=snake_case__		,							)
												self.assertTrue(torch.allclose(outputs.start_logits[:, :10]		,							snake_case__		,							atol=1e-4					)					)
												self.assertTrue(torch.allclose(outputs.end_logits[:, :10]		,							snake_case__		,							atol=1e-4					)					)












"""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


if is_torch_available():
			import torch

if is_vision_available():
			from PIL import Image

			from transformers import CLIPImageProcessor


class     __UpperCAmelCase(   unittest.TestCase							):




						"""simple docstring"""




						def __init__(   self       ,  snake_case__       ,  snake_case__=7       ,  snake_case__=3       ,  snake_case__=18       ,  snake_case__=30       ,  snake_case__=400       ,  snake_case__=True       ,  snake_case__=None       ,  snake_case__=True       ,  snake_case__=None       ,  snake_case__=True       ,  snake_case__=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]       ,  snake_case__=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]       ,  snake_case__=True       ,  ):
												'''simple docstring'''
												lowercase__				:      int=       size if size is not None else {"shortest_edge": 20}
												lowercase__				:      int=       crop_size if crop_size is not None else {"height": 18, "width": 18}
												lowercase__				:      Union[str, Any]=       parent
												lowercase__				:      Optional[Any]=       batch_size
												lowercase__				:      List[str]=       num_channels
												lowercase__				:      str=       image_size
												lowercase__				:      Optional[int]=       min_resolution
												lowercase__				:      Union[str, Any]=       max_resolution
												lowercase__				:      List[Any]=       do_resize
												lowercase__				:      Any=       size
												lowercase__				:      Optional[Any]=       do_center_crop
												lowercase__				:      List[str]=       crop_size
												lowercase__				:      List[Any]=       do_normalize
												lowercase__				:      Optional[Any]=       image_mean
												lowercase__				:      Dict=       image_std
												lowercase__				:      Dict=       do_convert_rgb




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												return {
												    "do_resize": self.do_resize,
												    "size": self.size,
												    "do_center_crop": self.do_center_crop,
												    "crop_size": self.crop_size,
												    "do_normalize": self.do_normalize,
												    "image_mean": self.image_mean,
												    "image_std": self.image_std,
												    "do_convert_rgb": self.do_convert_rgb,
												}




						def 		UpperCAmelCase_       (   self       ,  snake_case__=False       ,  snake_case__=False       ,  snake_case__=False			):
												'''simple docstring'''
												assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

												if equal_resolution:
																		lowercase__				:      Optional[Any]=       []
																		for i in range(self.batch_size			):
																								image_inputs.append(
																								    np.random.randint(
																								        255       ,  size=(self.num_channels, self.max_resolution, self.max_resolution)       ,  dtype=np.uinta			)			)
												else:
																		lowercase__				:      Optional[Any]=       []
																		for i in range(self.batch_size			):
																								lowercase__,	lowercase__				:      str=       np.random.choice(np.arange(self.min_resolution       ,  self.max_resolution			)       ,  2			)
																								image_inputs.append(np.random.randint(255       ,  size=(self.num_channels, width, height)       ,  dtype=np.uinta			)			)

												if not numpify and not torchify:
																		# PIL expects the channel dimension as last dimension
																		lowercase__				:      Dict=       [Image.fromarray(np.moveaxis(snake_case__       ,  0       ,  -1			)			) for x in image_inputs]

												if torchify:
																		lowercase__				:      Tuple=       [torch.from_numpy(snake_case__			) for x in image_inputs]

												return image_inputs


@require_torch
@require_vision
class     __UpperCAmelCase(   SCREAMING_SNAKE_CASE__  ,  unittest.TestCase							):




						"""simple docstring"""




						__lowerCamelCase				       =					CLIPImageProcessor if is_vision_available() else None




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      List[Any]=       CLIPImageProcessingTester(self			)




						@property
						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												return self.image_processor_tester.prepare_image_processor_dict()




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      Dict=       self.image_processing_class(**self.image_processor_dict			)
												self.assertTrue(hasattr(snake_case__       ,  "do_resize"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "size"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "do_center_crop"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "center_crop"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "do_normalize"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "image_mean"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "image_std"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "do_convert_rgb"			)			)




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      List[str]=       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}			)

												lowercase__				:      Dict=       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 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												pass




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												# Initialize image_processing
												lowercase__				:      int=       self.image_processing_class(**self.image_processor_dict			)
												# create random PIL images
												lowercase__				:      Optional[Any]=       self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__			)
												for image in image_inputs:
																		self.assertIsInstance(snake_case__       ,  Image.Image			)

												# Test not batched input
												lowercase__				:      List[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
												lowercase__				:      Dict=       image_processing(snake_case__       ,  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 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												# Initialize image_processing
												lowercase__				:      Any=       self.image_processing_class(**self.image_processor_dict			)
												# create random numpy tensors
												lowercase__				:      Tuple=       self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__       ,  numpify=snake_case__			)
												for image in image_inputs:
																		self.assertIsInstance(snake_case__       ,  np.ndarray			)

												# Test not batched input
												lowercase__				:      Dict=       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
												lowercase__				:      int=       image_processing(snake_case__       ,  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 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												# Initialize image_processing
												lowercase__				:      Optional[Any]=       self.image_processing_class(**self.image_processor_dict			)
												# create random PyTorch tensors
												lowercase__				:      Union[str, Any]=       self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__       ,  torchify=snake_case__			)
												for image in image_inputs:
																		self.assertIsInstance(snake_case__       ,  torch.Tensor			)

												# Test not batched input
												lowercase__				:      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
												lowercase__				:      Union[str, Any]=       image_processing(snake_case__       ,  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"],
												    )       ,  )


@require_torch
@require_vision
class     __UpperCAmelCase(   SCREAMING_SNAKE_CASE__  ,  unittest.TestCase							):




						"""simple docstring"""




						__lowerCamelCase				       =					CLIPImageProcessor if is_vision_available() else None




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      Optional[int]=       CLIPImageProcessingTester(self       ,  num_channels=4			)
												lowercase__				:      Optional[Any]=       3




						@property
						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												return self.image_processor_tester.prepare_image_processor_dict()




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												lowercase__				:      List[str]=       self.image_processing_class(**self.image_processor_dict			)
												self.assertTrue(hasattr(snake_case__       ,  "do_resize"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "size"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "do_center_crop"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "center_crop"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "do_normalize"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "image_mean"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "image_std"			)			)
												self.assertTrue(hasattr(snake_case__       ,  "do_convert_rgb"			)			)




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												pass




						def 		UpperCAmelCase_       (   self			):
												'''simple docstring'''
												# Initialize image_processing
												lowercase__				:      int=       self.image_processing_class(**self.image_processor_dict			)
												# create random PIL images
												lowercase__				:      int=       self.image_processor_tester.prepare_inputs(equal_resolution=snake_case__			)
												for image in image_inputs:
																		self.assertIsInstance(snake_case__       ,  Image.Image			)

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

												# Test batched
												lowercase__				:      Any=       image_processing(snake_case__       ,  return_tensors="pt"			).pixel_values
												self.assertEqual(
												    encoded_images.shape       ,  (
												        self.image_processor_tester.batch_size,
												        self.expected_encoded_image_num_channels,
												        self.image_processor_tester.crop_size["height"],
												        self.image_processor_tester.crop_size["width"],
												    )       ,  )






