






'''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


if is_torch_available():
 import torch

if is_vision_available():
 from PIL import Image

 from transformers import ChineseCLIPImageProcessor


class        _UpperCAmelCase						(		unittest.TestCase			):




    def __init__(			self  :       Union[str, Any]  ,     a  :       Dict  ,     a  :       Optional[Any]=7  ,     a  :       List[Any]=3  ,     a  :       int=1_8  ,     a  :       Tuple=3_0  ,     a  :       Dict=4_0_0  ,     a  :       Dict=True  ,     a  :       Optional[int]=None  ,     a  :       Optional[int]=True  ,     a  :       Any=None  ,     a  :       List[str]=True  ,     a  :       Tuple=[0.4814_5466, 0.457_8275, 0.4082_1073]  ,     a  :       str=[0.2686_2954, 0.2613_0258, 0.2757_7711]  ,     a  :       Tuple=True  ,     ):






       '''simple docstring'''






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




    def 				lowerCAmelCase__				(			self  :       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 				lowerCAmelCase__				(			self  :       str  ,     a  :       Optional[Any]=False  ,     a  :       Optional[int]=False  ,     a  :       str=False			):






       '''simple docstring'''






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

       if equal_resolution:
          lowercase_	:    Union[str, Any]           =     []
          for i in range(self.batch_size			):
             image_inputs.append(
                 np.random.randint(
                     2_5_5  ,     size=(self.num_channels, self.max_resolution, self.max_resolution)  ,     dtype=np.uinta			)			)
       else:
          lowercase_	:    Tuple           =     []
          for i in range(self.batch_size			):
             lowercase_    ,		lowercase_	:    List[str]           =     np.random.choice(np.arange(self.min_resolution  ,     self.max_resolution			)  ,     2			)
             image_inputs.append(np.random.randint(2_5_5  ,     size=(self.num_channels, width, height)  ,     dtype=np.uinta			)			)

       if not numpify and not torchify:
          # PIL expects the channel dimension as last dimension
          lowercase_	:    Optional[int]           =     [Image.fromarray(np.moveaxis(a  ,     0  ,     -1			)			) for x in image_inputs]

       if torchify:
          lowercase_	:    str           =     [torch.from_numpy(a			) for x in image_inputs]

       return image_inputs


@require_torch
@require_vision
class        _UpperCAmelCase						(		snake_case				,					unittest.TestCase			):
    __lowerCamelCase:   Optional[Any]		       =    ChineseCLIPImageProcessor if is_vision_available() else None




    def 				lowerCAmelCase__				(			self  :       Dict			):






       '''simple docstring'''






       lowercase_	:    Tuple           =     ChineseCLIPImageProcessingTester(self  ,     do_center_crop=a			)




    @property
    def 				lowerCAmelCase__				(			self  :       Any			):






       '''simple docstring'''






       return self.image_processor_tester.prepare_image_processor_dict()




    def 				lowerCAmelCase__				(			self  :       Tuple			):






       '''simple docstring'''






       lowercase_	:    Tuple           =     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  :       Optional[Any]			):






       '''simple docstring'''






       lowercase_	:    Optional[Any]           =     self.image_processing_class.from_dict(self.image_processor_dict			)
       self.assertEqual(image_processor.size  ,     {"height": 2_2_4, "width": 2_2_4}			)
       self.assertEqual(image_processor.crop_size  ,     {"height": 1_8, "width": 1_8}			)

       lowercase_	:    str           =     self.image_processing_class.from_dict(self.image_processor_dict  ,     size=4_2  ,     crop_size=8_4			)
       self.assertEqual(image_processor.size  ,     {"shortest_edge": 4_2}			)
       self.assertEqual(image_processor.crop_size  ,     {"height": 8_4, "width": 8_4}			)




    def 				lowerCAmelCase__				(			self  :       str			):






       '''simple docstring'''






       pass




    def 				lowerCAmelCase__				(			self  :       str			):






       '''simple docstring'''






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

       # Test not batched input
       lowercase_	:    List[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
       lowercase_	:    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 				lowerCAmelCase__				(			self  :       List[str]			):






       '''simple docstring'''






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






       '''simple docstring'''






       lowercase_	:    Tuple           =     self.image_processing_class(**self.image_processor_dict			)
       # create random PyTorch tensors
       lowercase_	:    Union[str, Any]           =     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
       lowercase_	:    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
       lowercase_	:    List[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        _UpperCAmelCase						(		snake_case				,					unittest.TestCase			):
    __lowerCamelCase:   Dict		       =    ChineseCLIPImageProcessor if is_vision_available() else None




    def 				lowerCAmelCase__				(			self  :       Optional[int]			):






       '''simple docstring'''






       lowercase_	:    Any           =     ChineseCLIPImageProcessingTester(self  ,     num_channels=4  ,     do_center_crop=a			)
       lowercase_	:    Any           =     3




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






       '''simple docstring'''






       return self.image_processor_tester.prepare_image_processor_dict()




    def 				lowerCAmelCase__				(			self  :       Optional[Any]			):






       '''simple docstring'''






       lowercase_	:    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 				lowerCAmelCase__				(			self  :       List[Any]			):






       '''simple docstring'''






       pass





    def 				lowerCAmelCase__				(			self  :       int			):






       '''simple docstring'''






       lowercase_	:    List[Any]           =     self.image_processing_class(**self.image_processor_dict			)
       # create random PIL images
       lowercase_	:    int           =     self.image_processor_tester.prepare_inputs(equal_resolution=a			)
       for image in image_inputs:
          self.assertIsInstance(a  ,     Image.Image			)

       # Test not batched input
       lowercase_	:    List[Any]           =     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
       lowercase_	:    Dict           =     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"],
           )  ,     )












'''simple docstring'''
from typing import TYPE_CHECKING

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


UpperCamelCase__ =			{
    'configuration_encodec': [
        'ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'EncodecConfig',
    ],
    'feature_extraction_encodec': ['EncodecFeatureExtractor'],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 UpperCamelCase__ =			[
     'ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST',
     'EncodecModel',
     'EncodecPreTrainedModel',
 ]

if TYPE_CHECKING:
 from .configuration_encodec import (
     ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP,
     EncodecConfig,
 )
 from .feature_extraction_encodec import EncodecFeatureExtractor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_encodec import (
      ENCODEC_PRETRAINED_MODEL_ARCHIVE_LIST,
      EncodecModel,
      EncodecPreTrainedModel,
  )

else:
 import sys

 UpperCamelCase__ =			_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)




