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







   def __init__(			self		:		str					,					lowerCamelCase_		:		Optional[Any]					,					lowerCamelCase_		:		Optional[Any]=7					,					lowerCamelCase_		:		int=3					,					lowerCamelCase_		:		Optional[Any]=18					,					lowerCamelCase_		:		Any=30					,					lowerCamelCase_		:		List[str]=400					,					lowerCamelCase_		:		Any=True					,					lowerCamelCase_		:		Union[str, Any]=None					,					lowerCamelCase_		:		Tuple=True					,					lowerCamelCase_		:		Any=None					,					lowerCamelCase_		:		Optional[Any]=True					,					lowerCamelCase_		:		Optional[int]=[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]					,					lowerCamelCase_		:		Tuple=[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]					,					lowerCamelCase_		:		Dict=True					,					):





    """simple docstring"""


    UpperCamelCase          =	size if size is not None else {"""height""": 224, """width""": 224}
    UpperCamelCase          =	crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
    UpperCamelCase          =	parent
    UpperCamelCase          =	batch_size
    UpperCamelCase          =	num_channels
    UpperCamelCase          =	image_size
    UpperCamelCase          =	min_resolution
    UpperCamelCase          =	max_resolution
    UpperCamelCase          =	do_resize
    UpperCamelCase          =	size
    UpperCamelCase          =	do_center_crop
    UpperCamelCase          =	crop_size
    UpperCamelCase          =	do_normalize
    UpperCamelCase          =	image_mean
    UpperCamelCase          =	image_std
    UpperCamelCase          =	do_convert_rgb







   def 		lowerCamelCase_     (			self		:		Union[str, 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 		lowerCamelCase_     (			self		:		Tuple					,					lowerCamelCase_		:		List[str]=False					,					lowerCamelCase_		:		List[Any]=False					,					lowerCamelCase_		:		Optional[int]=False							):





    """simple docstring"""


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

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

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

    return image_inputs





@require_torch
@require_vision
class SCREAMING_SNAKE_CASE_						(	__lowerCAmelCase   ,			unittest.TestCase						):
   __lowerCAmelCase      =							ChineseCLIPImageProcessor if is_vision_available() else None







   def 		lowerCamelCase_     (			self		:		str							):





    """simple docstring"""


    UpperCamelCase          =	ChineseCLIPImageProcessingTester(self					,					do_center_crop=A__							)







   @property
   def 		lowerCamelCase_     (			self		:		Union[str, Any]							):





    """simple docstring"""


    return self.image_processor_tester.prepare_image_processor_dict()







   def 		lowerCamelCase_     (			self		:		List[Any]							):





    """simple docstring"""


    UpperCamelCase          =	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 		lowerCamelCase_     (			self		:		Any							):





    """simple docstring"""


    UpperCamelCase          =	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}							)

    UpperCamelCase          =	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 		lowerCamelCase_     (			self		:		List[str]							):





    """simple docstring"""


    pass







   def 		lowerCamelCase_     (			self		:		Optional[Any]							):





    """simple docstring"""


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

    # Test not batched input
    UpperCamelCase          =	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
    UpperCamelCase          =	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 		lowerCamelCase_     (			self		:		Dict							):





    """simple docstring"""


    UpperCamelCase          =	self.image_processing_class(**self.image_processor_dict							)
    # create random numpy tensors
    UpperCamelCase          =	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
    UpperCamelCase          =	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
    UpperCamelCase          =	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 		lowerCamelCase_     (			self		:		Optional[int]							):





    """simple docstring"""


    UpperCamelCase          =	self.image_processing_class(**self.image_processor_dict							)
    # create random PyTorch tensors
    UpperCamelCase          =	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
    UpperCamelCase          =	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
    UpperCamelCase          =	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 SCREAMING_SNAKE_CASE_						(	__lowerCAmelCase   ,			unittest.TestCase						):
   __lowerCAmelCase      =							ChineseCLIPImageProcessor if is_vision_available() else None







   def 		lowerCamelCase_     (			self		:		Union[str, Any]							):





    """simple docstring"""


    UpperCamelCase          =	ChineseCLIPImageProcessingTester(self					,					num_channels=4					,					do_center_crop=A__							)
    UpperCamelCase          =	3







   @property
   def 		lowerCamelCase_     (			self		:		List[str]							):





    """simple docstring"""


    return self.image_processor_tester.prepare_image_processor_dict()







   def 		lowerCamelCase_     (			self		:		List[str]							):





    """simple docstring"""


    UpperCamelCase          =	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 		lowerCamelCase_     (			self		:		Any							):





    """simple docstring"""


    pass







   def 		lowerCamelCase_     (			self		:		Union[str, Any]							):





    """simple docstring"""


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

    # Test not batched input
    UpperCamelCase          =	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
    UpperCamelCase          =	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 typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available


A_       : Optional[int]         =			{'configuration_ibert': ['IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP', 'IBertConfig', 'IBertOnnxConfig']}

try:
	if not is_torch_available():
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	pass
else:
	A_       : str         =			[
	    'IBERT_PRETRAINED_MODEL_ARCHIVE_LIST',
	    'IBertForMaskedLM',
	    'IBertForMultipleChoice',
	    'IBertForQuestionAnswering',
	    'IBertForSequenceClassification',
	    'IBertForTokenClassification',
	    'IBertModel',
	    'IBertPreTrainedModel',
	]

if TYPE_CHECKING:
	from .configuration_ibert import IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP, IBertConfig, IBertOnnxConfig

	try:
		if not is_torch_available():
			raise OptionalDependencyNotAvailable()
	except OptionalDependencyNotAvailable:
		pass
	else:
		from .modeling_ibert import (
		    IBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
		    IBertForMaskedLM,
		    IBertForMultipleChoice,
		    IBertForQuestionAnswering,
		    IBertForSequenceClassification,
		    IBertForTokenClassification,
		    IBertModel,
		    IBertPreTrainedModel,
		)

else:
	import sys

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



