
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 ChineseCLIPImageProcessor







class  UpperCamelCase__		(    unittest.TestCase   ):







	'''simple docstring'''





	def __init__(			self				,       UpperCamelCase__				,       UpperCamelCase__=7				,       UpperCamelCase__=3				,       UpperCamelCase__=18				,       UpperCamelCase__=30				,       UpperCamelCase__=400				,       UpperCamelCase__=True				,       UpperCamelCase__=None				,       UpperCamelCase__=True				,       UpperCamelCase__=None				,       UpperCamelCase__=True				,       UpperCamelCase__=[0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]				,       UpperCamelCase__=[0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]				,       UpperCamelCase__=True				,       ):
					A__         =							size if size is not None else {'''height''': 224, '''width''': 224}
					A__         =							crop_size if crop_size is not None else {'''height''': 18, '''width''': 18}
					A__         =							parent
					A__         =							batch_size
					A__         =							num_channels
					A__         =							image_size
					A__         =							min_resolution
					A__         =							max_resolution
					A__         =							do_resize
					A__         =							size
					A__         =							do_center_crop
					A__         =							crop_size
					A__         =							do_normalize
					A__         =							image_mean
					A__         =							image_std
					A__         =							do_convert_rgb





	def   __snake_case				(			self		):
					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   __snake_case				(			self				,       UpperCamelCase__=False				,       UpperCamelCase__=False				,       UpperCamelCase__=False		):
					assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

					if equal_resolution:
									A__         =							[]
									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:
									A__         =							[]
									for i in range(self.batch_size		):
													A__         =							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
									A__         =							[Image.fromarray(np.moveaxis(UpperCamelCase__				,       0				,       -1		)		) for x in image_inputs]

					if torchify:
									A__         =							[torch.from_numpy(UpperCamelCase__		) for x in image_inputs]

					return image_inputs







@require_torch
@require_vision
class  UpperCamelCase__		(    SCREAMING_SNAKE_CASE_,			unittest.TestCase   ):







	'''simple docstring'''
	_lowerCAmelCase							       =				ChineseCLIPImageProcessor if is_vision_available() else None





	def   __snake_case				(			self		):
					A__         =							ChineseCLIPImageProcessingTester(self				,       do_center_crop=UpperCamelCase__		)





	@property
	def   __snake_case				(			self		):
					return self.image_processor_tester.prepare_image_processor_dict()





	def   __snake_case				(			self		):
					A__         =							self.image_processing_class(**self.image_processor_dict		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_resize'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''size'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_center_crop'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''center_crop'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_normalize'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''image_mean'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''image_std'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_convert_rgb'''		)		)





	def   __snake_case				(			self		):
					A__         =							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''': 18, '''width''': 18}		)

					A__         =							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   __snake_case				(			self		):
					pass





	def   __snake_case				(			self		):
					# Initialize image_processing
					A__         =							self.image_processing_class(**self.image_processor_dict		)
					# create random PIL images
					A__         =							self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__		)
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__				,       Image.Image		)

					# Test not batched input
					A__         =							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__         =							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   __snake_case				(			self		):
					# Initialize image_processing
					A__         =							self.image_processing_class(**self.image_processor_dict		)
					# create random numpy tensors
					A__         =							self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__				,       numpify=UpperCamelCase__		)
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__				,       np.ndarray		)

					# Test not batched input
					A__         =							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__         =							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   __snake_case				(			self		):
					# Initialize image_processing
					A__         =							self.image_processing_class(**self.image_processor_dict		)
					# create random PyTorch tensors
					A__         =							self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__				,       torchify=UpperCamelCase__		)
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__				,       torch.Tensor		)

					# Test not batched input
					A__         =							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__         =							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'''],
					    )				,       )







@require_torch
@require_vision
class  UpperCamelCase__		(    SCREAMING_SNAKE_CASE_,			unittest.TestCase   ):







	'''simple docstring'''
	_lowerCAmelCase							       =				ChineseCLIPImageProcessor if is_vision_available() else None





	def   __snake_case				(			self		):
					A__         =							ChineseCLIPImageProcessingTester(self				,       num_channels=4				,       do_center_crop=UpperCamelCase__		)
					A__         =							3





	@property
	def   __snake_case				(			self		):
					return self.image_processor_tester.prepare_image_processor_dict()





	def   __snake_case				(			self		):
					A__         =							self.image_processing_class(**self.image_processor_dict		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_resize'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''size'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_center_crop'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''center_crop'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_normalize'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''image_mean'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''image_std'''		)		)
					self.assertTrue(hasattr(UpperCamelCase__				,       '''do_convert_rgb'''		)		)





	def   __snake_case				(			self		):
					pass





	def   __snake_case				(			self		):
					# Initialize image_processing
					A__         =							self.image_processing_class(**self.image_processor_dict		)
					# create random PIL images
					A__         =							self.image_processor_tester.prepare_inputs(equal_resolution=UpperCamelCase__		)
					for image in image_inputs:
									self.assertIsInstance(UpperCamelCase__				,       Image.Image		)

					# Test not batched input
					A__         =							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
					A__         =							image_processing(UpperCamelCase__				,       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'''],
					    )				,       )

from typing import TYPE_CHECKING

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


_SCREAMING_SNAKE_CASE    :      int          =			{
    'configuration_bert': ['BERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'BertConfig', 'BertOnnxConfig'],
    'tokenization_bert': ['BasicTokenizer', 'BertTokenizer', 'WordpieceTokenizer'],
}

try:
					if not is_tokenizers_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Optional[Any]          =			['BertTokenizerFast']

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Union[str, Any]          =			[
					    'BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'BertForMaskedLM',
					    'BertForMultipleChoice',
					    'BertForNextSentencePrediction',
					    'BertForPreTraining',
					    'BertForQuestionAnswering',
					    'BertForSequenceClassification',
					    'BertForTokenClassification',
					    'BertLayer',
					    'BertLMHeadModel',
					    'BertModel',
					    'BertPreTrainedModel',
					    'load_tf_weights_in_bert',
					]

try:
					if not is_tf_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Tuple          =			[
					    'TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST',
					    'TFBertEmbeddings',
					    'TFBertForMaskedLM',
					    'TFBertForMultipleChoice',
					    'TFBertForNextSentencePrediction',
					    'TFBertForPreTraining',
					    'TFBertForQuestionAnswering',
					    'TFBertForSequenceClassification',
					    'TFBertForTokenClassification',
					    'TFBertLMHeadModel',
					    'TFBertMainLayer',
					    'TFBertModel',
					    'TFBertPreTrainedModel',
					]
try:
					if not is_tensorflow_text_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Dict          =			['TFBertTokenizer']

try:
					if not is_flax_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					_SCREAMING_SNAKE_CASE    :      Optional[int]          =			[
					    'FlaxBertForCausalLM',
					    'FlaxBertForMaskedLM',
					    'FlaxBertForMultipleChoice',
					    'FlaxBertForNextSentencePrediction',
					    'FlaxBertForPreTraining',
					    'FlaxBertForQuestionAnswering',
					    'FlaxBertForSequenceClassification',
					    'FlaxBertForTokenClassification',
					    'FlaxBertModel',
					    'FlaxBertPreTrainedModel',
					]

if TYPE_CHECKING:
					from .configuration_bert import BERT_PRETRAINED_CONFIG_ARCHIVE_MAP, BertConfig, BertOnnxConfig
					from .tokenization_bert import BasicTokenizer, BertTokenizer, WordpieceTokenizer

					try:
										if not is_tokenizers_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bert_fast import BertTokenizerFast

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_bert import (
										    BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    BertForMaskedLM,
										    BertForMultipleChoice,
										    BertForNextSentencePrediction,
										    BertForPreTraining,
										    BertForQuestionAnswering,
										    BertForSequenceClassification,
										    BertForTokenClassification,
										    BertLayer,
										    BertLMHeadModel,
										    BertModel,
										    BertPreTrainedModel,
										    load_tf_weights_in_bert,
										)

					try:
										if not is_tf_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_tf_bert import (
										    TF_BERT_PRETRAINED_MODEL_ARCHIVE_LIST,
										    TFBertEmbeddings,
										    TFBertForMaskedLM,
										    TFBertForMultipleChoice,
										    TFBertForNextSentencePrediction,
										    TFBertForPreTraining,
										    TFBertForQuestionAnswering,
										    TFBertForSequenceClassification,
										    TFBertForTokenClassification,
										    TFBertLMHeadModel,
										    TFBertMainLayer,
										    TFBertModel,
										    TFBertPreTrainedModel,
										)

					try:
										if not is_tensorflow_text_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .tokenization_bert_tf import TFBertTokenizer

					try:
										if not is_flax_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_flax_bert import (
										    FlaxBertForCausalLM,
										    FlaxBertForMaskedLM,
										    FlaxBertForMultipleChoice,
										    FlaxBertForNextSentencePrediction,
										    FlaxBertForPreTraining,
										    FlaxBertForQuestionAnswering,
										    FlaxBertForSequenceClassification,
										    FlaxBertForTokenClassification,
										    FlaxBertModel,
										    FlaxBertPreTrainedModel,
										)

else:
					import sys

					_SCREAMING_SNAKE_CASE    :      Union[str, Any]          =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)