





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 LevitImageProcessor



class    A__  (			unittest.TestCase     ):





      def __init__(					self			,				A_			,				A_=7			,				A_=3			,				A_=18			,				A_=30			,				A_=400			,				A_=True			,				A_=None			,				A_=True			,				A_=None			,				A_=True			,				A_=[0.5, 0.5, 0.5]			,				A_=[0.5, 0.5, 0.5]			,				):
       '''simple docstring'''




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





      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




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



@require_torch
@require_vision
class    A__  (			__snake_case			,  unittest.TestCase     ):
      _UpperCAmelCase      :Dict		       =  LevitImageProcessor if is_vision_available() else None





      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   str			      =  LevitImageProcessingTester(self  )





      @property
      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       return self.image_processor_tester.prepare_image_processor_dict()





      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Optional[Any]			      =  self.image_processing_class(**self.image_processor_dict  )
       self.assertTrue(hasattr(A_			,				"image_mean"  )  )
       self.assertTrue(hasattr(A_			,				"image_std"  )  )
       self.assertTrue(hasattr(A_			,				"do_normalize"  )  )
       self.assertTrue(hasattr(A_			,				"do_resize"  )  )
       self.assertTrue(hasattr(A_			,				"do_center_crop"  )  )
       self.assertTrue(hasattr(A_			,				"size"  )  )





      def 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Any			      =  self.image_processing_class.from_dict(self.image_processor_dict  )
       self.assertEqual(image_processor.size			,				{"shortest_edge": 18}  )
       self.assertEqual(image_processor.crop_size			,				{"height": 18, "width": 18}  )

       UpperCamelCase      :   int			      =  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'''




       UpperCamelCase      :   Union[str, Any]			      =  self.image_processing_class(**self.image_processor_dict  )
       # create random PIL images
       UpperCamelCase      :   List[Any]			      =  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      :   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
       UpperCamelCase      :   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 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   List[str]			      =  self.image_processing_class(**self.image_processor_dict  )
       # create random numpy tensors
       UpperCamelCase      :   int			      =  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      :   Union[str, 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
       UpperCamelCase      :   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 			__UpperCamelCase(					self  ):
       '''simple docstring'''




       UpperCamelCase      :   Optional[Any]			      =  self.image_processing_class(**self.image_processor_dict  )
       # create random PyTorch tensors
       UpperCamelCase      :   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      :   Union[str, 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
       UpperCamelCase      :   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"],
           )			,				)







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__lowerCamelCase			:	List[Any]					    =	{
    """configuration_chinese_clip""": [
        """CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """ChineseCLIPConfig""",
        """ChineseCLIPOnnxConfig""",
        """ChineseCLIPTextConfig""",
        """ChineseCLIPVisionConfig""",
    ],
    """processing_chinese_clip""": ["""ChineseCLIPProcessor"""],
}

try:
    if not is_vision_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase			:	Tuple					    =	["""ChineseCLIPFeatureExtractor"""]
    __lowerCamelCase			:	List[str]					    =	["""ChineseCLIPImageProcessor"""]

try:
    if not is_torch_available():
        raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
    pass
else:
    __lowerCamelCase			:	str					    =	[
        """CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
        """ChineseCLIPModel""",
        """ChineseCLIPPreTrainedModel""",
        """ChineseCLIPTextModel""",
        """ChineseCLIPVisionModel""",
    ]

if TYPE_CHECKING:
    from .configuration_chinese_clip import (
        CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
        ChineseCLIPConfig,
        ChineseCLIPOnnxConfig,
        ChineseCLIPTextConfig,
        ChineseCLIPVisionConfig,
    )
    from .processing_chinese_clip import ChineseCLIPProcessor

    try:
        if not is_vision_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .feature_extraction_chinese_clip import ChineseCLIPFeatureExtractor, ChineseCLIPImageProcessor

    try:
        if not is_torch_available():
            raise OptionalDependencyNotAvailable()
    except OptionalDependencyNotAvailable:
        pass
    else:
        from .modeling_chinese_clip import (
            CHINESE_CLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
            ChineseCLIPModel,
            ChineseCLIPPreTrainedModel,
            ChineseCLIPTextModel,
            ChineseCLIPVisionModel,
        )

else:
    import sys

    __lowerCamelCase			:	Any					    =	_LazyModule(__name__, globals()["""__file__"""], _import_structure, module_spec=__spec__)
