


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






class     _UpperCAmelCase			(		unittest.TestCase):
			def __init__(		self      ,		_A      ,		_A=7      ,		_A=3      ,		_A=18      ,		_A=30      ,		_A=4_00      ,		_A=True      ,		_A=None      ,		_A=0.875      ,		_A=True      ,		_A=[0.5, 0.5, 0.5]      ,		_A=[0.5, 0.5, 0.5]      ,		)    ->    Optional[Any]:






				'''simple docstring'''







				_UpperCAmelCase    :							Tuple									=					size if size is not None else {"shortest_edge": 20}
				_UpperCAmelCase    :							Union[str, Any]									=					parent
				_UpperCAmelCase    :							Optional[int]									=					batch_size
				_UpperCAmelCase    :							Optional[Any]									=					num_channels
				_UpperCAmelCase    :							List[str]									=					image_size
				_UpperCAmelCase    :							Optional[Any]									=					min_resolution
				_UpperCAmelCase    :							Tuple									=					max_resolution
				_UpperCAmelCase    :							Dict									=					do_resize
				_UpperCAmelCase    :							Tuple									=					size
				_UpperCAmelCase    :							Any									=					crop_pct
				_UpperCAmelCase    :							Optional[int]									=					do_normalize
				_UpperCAmelCase    :							List[Any]									=					image_mean
				_UpperCAmelCase    :							List[Any]									=					image_std
			def 							__snake_case (		self     )    ->    Optional[Any]:






				'''simple docstring'''







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






@require_torch
@require_vision
class     _UpperCAmelCase			(		a__    ,     unittest.TestCase):
			__a :       Union[str, Any]									=							ConvNextImageProcessor if is_vision_available() else None
			def 							__snake_case (		self     )    ->    str:






				'''simple docstring'''







				_UpperCAmelCase    :							List[str]									=					ConvNextImageProcessingTester(self     )
			@property
			def 							__snake_case (		self     )    ->    int:






				'''simple docstring'''







				return self.image_processor_tester.prepare_image_processor_dict()
			def 							__snake_case (		self     )    ->    Any:






				'''simple docstring'''







				_UpperCAmelCase    :							str									=					self.image_processing_class(**self.image_processor_dict     )
				self.assertTrue(hasattr(__A      ,		"""do_resize"""     )     )
				self.assertTrue(hasattr(__A      ,		"""size"""     )     )
				self.assertTrue(hasattr(__A      ,		"""crop_pct"""     )     )
				self.assertTrue(hasattr(__A      ,		"""do_normalize"""     )     )
				self.assertTrue(hasattr(__A      ,		"""image_mean"""     )     )
				self.assertTrue(hasattr(__A      ,		"""image_std"""     )     )
			def 							__snake_case (		self     )    ->    Optional[int]:






				'''simple docstring'''







				_UpperCAmelCase    :							Optional[Any]									=					self.image_processing_class.from_dict(self.image_processor_dict     )
				self.assertEqual(image_processor.size      ,		{"""shortest_edge""": 20}     )

				_UpperCAmelCase    :							List[Any]									=					self.image_processing_class.from_dict(self.image_processor_dict      ,		size=42     )
				self.assertEqual(image_processor.size      ,		{"""shortest_edge""": 42}     )
			def 							__snake_case (		self     )    ->    Union[str, Any]:






				'''simple docstring'''







				pass
			def 							__snake_case (		self     )    ->    Any:






				'''simple docstring'''







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

				# Test not batched input
				_UpperCAmelCase    :							int									=					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.size["""shortest_edge"""],
				        self.image_processor_tester.size["""shortest_edge"""],
				    )      ,		)

				# Test batched
				_UpperCAmelCase    :							Tuple									=					image_processing(__A      ,		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.size["""shortest_edge"""],
				        self.image_processor_tester.size["""shortest_edge"""],
				    )      ,		)
			def 							__snake_case (		self     )    ->    Any:






				'''simple docstring'''







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

				# Test not batched input
				_UpperCAmelCase    :							int									=					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.size["""shortest_edge"""],
				        self.image_processor_tester.size["""shortest_edge"""],
				    )      ,		)

				# Test batched
				_UpperCAmelCase    :							Union[str, Any]									=					image_processing(__A      ,		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.size["""shortest_edge"""],
				        self.image_processor_tester.size["""shortest_edge"""],
				    )      ,		)
			def 							__snake_case (		self     )    ->    Optional[int]:






				'''simple docstring'''







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

				# Test not batched input
				_UpperCAmelCase    :							Optional[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.size["""shortest_edge"""],
				        self.image_processor_tester.size["""shortest_edge"""],
				    )      ,		)

				# Test batched
				_UpperCAmelCase    :							Any									=					image_processing(__A      ,		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.size["""shortest_edge"""],
				        self.image_processor_tester.size["""shortest_edge"""],
				    )      ,		)








"""simple docstring"""






from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_tokenizers_available,
    is_torch_available,
)


lowerCamelCase__				:  Union[str, Any]													=  {
    '''configuration_dpr''': ['''DPR_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''DPRConfig'''],
    '''tokenization_dpr''': [
        '''DPRContextEncoderTokenizer''',
        '''DPRQuestionEncoderTokenizer''',
        '''DPRReaderOutput''',
        '''DPRReaderTokenizer''',
    ],
}


try:
						if not is_tokenizers_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__				:  List[Any]													=  [
						    '''DPRContextEncoderTokenizerFast''',
						    '''DPRQuestionEncoderTokenizerFast''',
						    '''DPRReaderTokenizerFast''',
						]

try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__				:  Dict													=  [
						    '''DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''DPRContextEncoder''',
						    '''DPRPretrainedContextEncoder''',
						    '''DPRPreTrainedModel''',
						    '''DPRPretrainedQuestionEncoder''',
						    '''DPRPretrainedReader''',
						    '''DPRQuestionEncoder''',
						    '''DPRReader''',
						]

try:
						if not is_tf_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						lowerCamelCase__				:  Any													=  [
						    '''TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST''',
						    '''TFDPRContextEncoder''',
						    '''TFDPRPretrainedContextEncoder''',
						    '''TFDPRPretrainedQuestionEncoder''',
						    '''TFDPRPretrainedReader''',
						    '''TFDPRQuestionEncoder''',
						    '''TFDPRReader''',
						]


if TYPE_CHECKING:
						from .configuration_dpr import DPR_PRETRAINED_CONFIG_ARCHIVE_MAP, DPRConfig
						from .tokenization_dpr import (
						    DPRContextEncoderTokenizer,
						    DPRQuestionEncoderTokenizer,
						    DPRReaderOutput,
						    DPRReaderTokenizer,
						)

						try:
												if not is_tokenizers_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .tokenization_dpr_fast import (
												    DPRContextEncoderTokenizerFast,
												    DPRQuestionEncoderTokenizerFast,
												    DPRReaderTokenizerFast,
												)

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_dpr import (
												    DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    DPRContextEncoder,
												    DPRPretrainedContextEncoder,
												    DPRPreTrainedModel,
												    DPRPretrainedQuestionEncoder,
												    DPRPretrainedReader,
												    DPRQuestionEncoder,
												    DPRReader,
												)

						try:
												if not is_tf_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_tf_dpr import (
												    TF_DPR_CONTEXT_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TF_DPR_QUESTION_ENCODER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TF_DPR_READER_PRETRAINED_MODEL_ARCHIVE_LIST,
												    TFDPRContextEncoder,
												    TFDPRPretrainedContextEncoder,
												    TFDPRPretrainedQuestionEncoder,
												    TFDPRPretrainedReader,
												    TFDPRQuestionEncoder,
												    TFDPRReader,
												)

else:
						import sys

						lowerCamelCase__				:  Optional[Any]													=  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)





