


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 					lowerCAmelCase_ (       unittest.TestCase):




						def __init__(	self						:   Tuple   ,     __A						:   Optional[Any]   ,     __A						:   Optional[Any]=7   ,     __A						:   Any=3   ,     __A						:   Tuple=18   ,     __A						:   int=30   ,     __A						:   Union[str, Any]=400   ,     __A						:   List[Any]=True   ,     __A						:   int=None   ,     __A						:   Optional[Any]=True   ,     __A						:   List[str]=None   ,     __A						:   Optional[Any]=True   ,     __A						:   Tuple=[0.48_145_466, 0.4_578_275, 0.40_821_073]   ,     __A						:   Optional[int]=[0.26_862_954, 0.26_130_258, 0.27_577_711]   ,     __A						:   Union[str, Any]=True   ,     )      ->Optional[int]:






									"""simple docstring"""






									a__ :str						  =    size if size is not None else {"""height""": 224, """width""": 224}
									a__ :str						  =    crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
									a__ :Tuple						  =    parent
									a__ :List[str]						  =    batch_size
									a__ :Tuple						  =    num_channels
									a__ :int						  =    image_size
									a__ :Dict						  =    min_resolution
									a__ :Optional[Any]						  =    max_resolution
									a__ :Any						  =    do_resize
									a__ :Tuple						  =    size
									a__ :int						  =    do_center_crop
									a__ :List[Any]						  =    crop_size
									a__ :Optional[Any]						  =    do_normalize
									a__ :Optional[Any]						  =    image_mean
									a__ :Dict						  =    image_std
									a__ :str						  =    do_convert_rgb




						def  _snake_case					(	self						:   List[Any]						)      ->List[Any]:






									"""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  _snake_case					(	self						:   Union[str, Any]   ,     __A						:   Any=False   ,     __A						:   List[str]=False   ,     __A						:   Union[str, Any]=False						)      ->List[Any]:






									"""simple docstring"""






									assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

									if equal_resolution:
												a__ :List[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:
												a__ :Any						  =    []
												for i in range(self.batch_size						):
															a__ :Union[str, Any]						  =    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__ :str						  =    [Image.fromarray(np.moveaxis(a_   ,     0   ,     -1						)						) for x in image_inputs]

									if torchify:
												a__ :Dict						  =    [torch.from_numpy(a_						) for x in image_inputs]

									return image_inputs






@require_torch
@require_vision
class 					lowerCAmelCase_ (       __a			,unittest.TestCase):
						lowerCamelCase_         =     ChineseCLIPImageProcessor if is_vision_available() else None




						def  _snake_case					(	self						:   Any						)      ->Dict:






									"""simple docstring"""






									a__ :Tuple						  =    ChineseCLIPImageProcessingTester(self   ,     do_center_crop=a_						)




						@property
						def  _snake_case					(	self						:   List[str]						)      ->Dict:






									"""simple docstring"""






									return self.image_processor_tester.prepare_image_processor_dict()




						def  _snake_case					(	self						:   List[Any]						)      ->Dict:






									"""simple docstring"""






									a__ :str						  =    self.image_processing_class(**self.image_processor_dict						)
									self.assertTrue(hasattr(a_   ,     "do_resize"						)						)
									self.assertTrue(hasattr(a_   ,     "size"						)						)
									self.assertTrue(hasattr(a_   ,     "do_center_crop"						)						)
									self.assertTrue(hasattr(a_   ,     "center_crop"						)						)
									self.assertTrue(hasattr(a_   ,     "do_normalize"						)						)
									self.assertTrue(hasattr(a_   ,     "image_mean"						)						)
									self.assertTrue(hasattr(a_   ,     "image_std"						)						)
									self.assertTrue(hasattr(a_   ,     "do_convert_rgb"						)						)




						def  _snake_case					(	self						:   List[str]						)      ->List[str]:






									"""simple docstring"""






									a__ :Optional[int]						  =    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__ :Union[str, Any]						  =    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						:   Dict						)      ->List[str]:






									"""simple docstring"""






									pass




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






									"""simple docstring"""






									a__ :int						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random PIL images
									a__ :Any						  =    self.image_processor_tester.prepare_inputs(equal_resolution=a_						)
									for image in image_inputs:
												self.assertIsInstance(a_   ,     Image.Image						)

									# Test not batched input
									a__ :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.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )   ,     )

									# Test batched
									a__ :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.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )   ,     )




						def  _snake_case					(	self						:   Optional[int]						)      ->List[Any]:






									"""simple docstring"""






									a__ :Dict						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random numpy tensors
									a__ :Any						  =    self.image_processor_tester.prepare_inputs(equal_resolution=a_   ,     numpify=a_						)
									for image in image_inputs:
												self.assertIsInstance(a_   ,     np.ndarray						)

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

									# Test batched
									a__ :Optional[int]						  =    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.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )   ,     )






						def  _snake_case					(	self						:   int						)      ->Any:






									"""simple docstring"""






									a__ :int						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random PyTorch tensors
									a__ :str						  =    self.image_processor_tester.prepare_inputs(equal_resolution=a_   ,     torchify=a_						)
									for image in image_inputs:
												self.assertIsInstance(a_   ,     torch.Tensor						)

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

									# Test batched
									a__ :str						  =    image_processing(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.crop_size["height"],
									        self.image_processor_tester.crop_size["width"],
									    )   ,     )






@require_torch
@require_vision
class 					lowerCAmelCase_ (       __a			,unittest.TestCase):
						lowerCamelCase_         =     ChineseCLIPImageProcessor if is_vision_available() else None




						def  _snake_case					(	self						:   str						)      ->Tuple:






									"""simple docstring"""






									a__ :List[str]						  =    ChineseCLIPImageProcessingTester(self   ,     num_channels=4   ,     do_center_crop=a_						)
									a__ :Optional[int]						  =    3




						@property
						def  _snake_case					(	self						:   Optional[int]						)      ->Dict:






									"""simple docstring"""






									return self.image_processor_tester.prepare_image_processor_dict()




						def  _snake_case					(	self						:   List[Any]						)      ->int:






									"""simple docstring"""






									a__ :List[str]						  =    self.image_processing_class(**self.image_processor_dict						)
									self.assertTrue(hasattr(a_   ,     "do_resize"						)						)
									self.assertTrue(hasattr(a_   ,     "size"						)						)
									self.assertTrue(hasattr(a_   ,     "do_center_crop"						)						)
									self.assertTrue(hasattr(a_   ,     "center_crop"						)						)
									self.assertTrue(hasattr(a_   ,     "do_normalize"						)						)
									self.assertTrue(hasattr(a_   ,     "image_mean"						)						)
									self.assertTrue(hasattr(a_   ,     "image_std"						)						)
									self.assertTrue(hasattr(a_   ,     "do_convert_rgb"						)						)




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






									"""simple docstring"""






									pass






						def  _snake_case					(	self						:   Tuple						)      ->List[Any]:






									"""simple docstring"""






									a__ :Tuple						  =    self.image_processing_class(**self.image_processor_dict						)
									# create random PIL images
									a__ :List[str]						  =    self.image_processor_tester.prepare_inputs(equal_resolution=a_						)
									for image in image_inputs:
												self.assertIsInstance(a_   ,     Image.Image						)

									# Test not batched input
									a__ :Dict						  =    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__ :List[str]						  =    image_processing(a_   ,     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 .configuration_bert_masked import MaskedBertConfig
from .modeling_bert_masked import (
    MaskedBertForMultipleChoice,
    MaskedBertForQuestionAnswering,
    MaskedBertForSequenceClassification,
    MaskedBertForTokenClassification,
    MaskedBertModel,
)
from .modules import *


