
"""simple docstring"""



import importlib
import inspect
import json
import os
import re
import shutil
import sys
from pathlib import Path
from typing import Dict, Optional, Union
from urllib import request

from huggingface_hub import HfFolder, cached_download, hf_hub_download, model_info
from packaging import version

from .. import __version__
from . import DIFFUSERS_DYNAMIC_MODULE_NAME, HF_MODULES_CACHE, logging


_snake_case          =						(
    '''https://raw.githubusercontent.com/huggingface/diffusers/{revision}/examples/community/{pipeline}.py'''
)


_snake_case          =						logging.get_logger(__name__)  # pylint: disable=invalid-name






def 	__snake_case  (    ):






							"""simple docstring"""



							_lowerCAmelCase  	=			'https://pypi.org/pypi/diffusers/json'
							_lowerCAmelCase  	=			json.loads(request.urlopen(SCREAMING_SNAKE_CASE						).read()						)['releases'].keys()
							return sorted(SCREAMING_SNAKE_CASE     ,  key=lambda SCREAMING_SNAKE_CASE						: version.Version(SCREAMING_SNAKE_CASE						)						)






def 	__snake_case  (    ):






							"""simple docstring"""



							if HF_MODULES_CACHE in sys.path:
														return

							sys.path.append(SCREAMING_SNAKE_CASE						)
							os.makedirs(SCREAMING_SNAKE_CASE     ,  exist_ok=SCREAMING_SNAKE_CASE						)
							_lowerCAmelCase  	=			Path(SCREAMING_SNAKE_CASE						) / '__init__.py'
							if not init_path.exists():
														init_path.touch()






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Union[str, os.PathLike]						):






							"""simple docstring"""



							init_hf_modules()
							_lowerCAmelCase  	=			Path(SCREAMING_SNAKE_CASE						) / name
							# If the parent module does not exist yet, recursively create it.
							if not dynamic_module_path.parent.exists():
														create_dynamic_module(dynamic_module_path.parent						)
							os.makedirs(SCREAMING_SNAKE_CASE     ,  exist_ok=SCREAMING_SNAKE_CASE						)
							_lowerCAmelCase  	=			dynamic_module_path / '__init__.py'
							if not init_path.exists():
														init_path.touch()






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Union[str, Any]						):






							"""simple docstring"""



							with open(SCREAMING_SNAKE_CASE     ,  'r'     ,  encoding='utf-8'						) as f:
														_lowerCAmelCase  	=			f.read()

							# Imports of the form `import .xxx`
							_lowerCAmelCase  	=			re.findall('^\s*import\s+\.(\S+)\s*$'     ,  SCREAMING_SNAKE_CASE     ,  flags=re.MULTILINE						)
							# Imports of the form `from .xxx import yyy`
							relative_imports += re.findall('^\s*from\s+\.(\S+)\s+import'     ,  SCREAMING_SNAKE_CASE     ,  flags=re.MULTILINE						)
							# Unique-ify
							return list(set(SCREAMING_SNAKE_CASE						)						)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					str						):






							"""simple docstring"""



							_lowerCAmelCase  	=			False
							_lowerCAmelCase  	=			[module_file]
							_lowerCAmelCase  	=			[]

							# Let's recurse through all relative imports
							while not no_change:
														_lowerCAmelCase  	=			[]
														for f in files_to_check:
																					new_imports.extend(get_relative_imports(SCREAMING_SNAKE_CASE						)						)

														_lowerCAmelCase  	=			Path(SCREAMING_SNAKE_CASE						).parent
														_lowerCAmelCase  	=			[str(module_path / m						) for m in new_imports]
														_lowerCAmelCase  	=			[f for f in new_import_files if f not in all_relative_imports]
														_lowerCAmelCase  	=			[f"""{f}.py""" for f in new_import_files]

														_lowerCAmelCase  	=			len(SCREAMING_SNAKE_CASE						) == 0
														all_relative_imports.extend(SCREAMING_SNAKE_CASE						)

							return all_relative_imports






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Dict						):






							"""simple docstring"""



							with open(SCREAMING_SNAKE_CASE     ,  'r'     ,  encoding='utf-8'						) as f:
														_lowerCAmelCase  	=			f.read()

							# Imports of the form `import xxx`
							_lowerCAmelCase  	=			re.findall('^\s*import\s+(\S+)\s*$'     ,  SCREAMING_SNAKE_CASE     ,  flags=re.MULTILINE						)
							# Imports of the form `from xxx import yyy`
							imports += re.findall('^\s*from\s+(\S+)\s+import'     ,  SCREAMING_SNAKE_CASE     ,  flags=re.MULTILINE						)
							# Only keep the top-level module
							_lowerCAmelCase  	=			[imp.split('.'						)[0] for imp in imports if not imp.startswith('.'						)]

							# Unique-ify and test we got them all
							_lowerCAmelCase  	=			list(set(SCREAMING_SNAKE_CASE						)						)
							_lowerCAmelCase  	=			[]
							for imp in imports:
														try:
																					importlib.import_module(SCREAMING_SNAKE_CASE						)
														except ImportError:
																					missing_packages.append(SCREAMING_SNAKE_CASE						)

							if len(SCREAMING_SNAKE_CASE						) > 0:
														raise ImportError(
														    'This modeling file requires the following packages that were not found in your environment: '
														    f"""{', '.join(SCREAMING_SNAKE_CASE						)}. Run `pip install {' '.join(SCREAMING_SNAKE_CASE						)}`"""						)

							return get_relative_imports(SCREAMING_SNAKE_CASE						)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					List[str]     ,  SCREAMING_SNAKE_CASE:					Tuple						):






							"""simple docstring"""



							_lowerCAmelCase  	=			module_path.replace(os.path.sep     ,  '.'						)
							_lowerCAmelCase  	=			importlib.import_module(SCREAMING_SNAKE_CASE						)

							if class_name is None:
														return find_pipeline_class(SCREAMING_SNAKE_CASE						)
							return getattr(SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE						)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					List[Any]						):






							"""simple docstring"""



							from ..pipelines import DiffusionPipeline

							_lowerCAmelCase  	=			dict(inspect.getmembers(SCREAMING_SNAKE_CASE     ,  inspect.isclass						)						)

							_lowerCAmelCase  	=			None
							for cls_name, cls in cls_members.items():
														if (
														    cls_name != DiffusionPipeline.__name__
														    and issubclass(cls     ,  SCREAMING_SNAKE_CASE						)
														    and cls.__module__.split('.'						)[0] != "diffusers"
														):
																					if pipeline_class is not None:
																												raise ValueError(
																												    f"""Multiple classes that inherit from {DiffusionPipeline.__name__} have been found:"""
																												    f""" {pipeline_class.__name__}, and {cls_name}. Please make sure to define only one in"""
																												    f""" {loaded_module}."""						)
																					_lowerCAmelCase  	=			cls

							return pipeline_class






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Union[str, os.PathLike]     ,  SCREAMING_SNAKE_CASE:					str     ,  SCREAMING_SNAKE_CASE:					Optional[Union[str, os.PathLike]] = None     ,  SCREAMING_SNAKE_CASE:					bool = False     ,  SCREAMING_SNAKE_CASE:					bool = False     ,  SCREAMING_SNAKE_CASE:					Optional[Dict[str, str]] = None     ,  SCREAMING_SNAKE_CASE:					Optional[Union[bool, str]] = None     ,  SCREAMING_SNAKE_CASE:					Optional[str] = None     ,  SCREAMING_SNAKE_CASE:					bool = False     ,  ):






							"""simple docstring"""



							_lowerCAmelCase  	=			str(SCREAMING_SNAKE_CASE						)

							_lowerCAmelCase  	=			os.path.join(SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE						)

							if os.path.isfile(SCREAMING_SNAKE_CASE						):
														_lowerCAmelCase  	=			module_file_or_url
														_lowerCAmelCase  	=			'local'
							elif pretrained_model_name_or_path.count('/'						) == 0:
														_lowerCAmelCase  	=			get_diffusers_versions()
														# cut ".dev0"
														_lowerCAmelCase  	=			'v' + '.'.join(__version__.split('.'						)[:3]						)

														# retrieve github version that matches
														if revision is None:
																					_lowerCAmelCase  	=			latest_version if latest_version[1:] in available_versions else 'main'
																					logger.info(f"""Defaulting to latest_version: {revision}."""						)
														elif revision in available_versions:
																					_lowerCAmelCase  	=			f"""v{revision}"""
														elif revision == "main":
																					_lowerCAmelCase  	=			revision
														else:
																					raise ValueError(
																					    f"""`custom_revision`: {revision} does not exist. Please make sure to choose one of"""
																					    f""" {', '.join(available_versions + ['main']						)}."""						)

														# community pipeline on GitHub
														_lowerCAmelCase  	=			COMMUNITY_PIPELINES_URL.format(revision=SCREAMING_SNAKE_CASE     ,  pipeline=SCREAMING_SNAKE_CASE						)
														try:
																					_lowerCAmelCase  	=			cached_download(
																					    SCREAMING_SNAKE_CASE     ,  cache_dir=SCREAMING_SNAKE_CASE     ,  force_download=SCREAMING_SNAKE_CASE     ,  proxies=SCREAMING_SNAKE_CASE     ,  resume_download=SCREAMING_SNAKE_CASE     ,  local_files_only=SCREAMING_SNAKE_CASE     ,  use_auth_token=SCREAMING_SNAKE_CASE     ,  )
																					_lowerCAmelCase  	=			'git'
																					_lowerCAmelCase  	=			pretrained_model_name_or_path + '.py'
														except EnvironmentError:
																					logger.error(f"""Could not locate the {module_file} inside {pretrained_model_name_or_path}."""						)
																					raise
							else:
														try:
																					# Load from URL or cache if already cached
																					_lowerCAmelCase  	=			hf_hub_download(
																					    SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE     ,  cache_dir=SCREAMING_SNAKE_CASE     ,  force_download=SCREAMING_SNAKE_CASE     ,  proxies=SCREAMING_SNAKE_CASE     ,  resume_download=SCREAMING_SNAKE_CASE     ,  local_files_only=SCREAMING_SNAKE_CASE     ,  use_auth_token=SCREAMING_SNAKE_CASE     ,  )
																					_lowerCAmelCase  	=			os.path.join('local'     ,  '--'.join(pretrained_model_name_or_path.split('/'						)						)						)
														except EnvironmentError:
																					logger.error(f"""Could not locate the {module_file} inside {pretrained_model_name_or_path}."""						)
																					raise

    # Check we have all the requirements in our environment
							_lowerCAmelCase  	=			check_imports(SCREAMING_SNAKE_CASE						)

							# Now we move the module inside our cached dynamic modules.
							_lowerCAmelCase  	=			DIFFUSERS_DYNAMIC_MODULE_NAME + os.path.sep + submodule
							create_dynamic_module(SCREAMING_SNAKE_CASE						)
							_lowerCAmelCase  	=			Path(SCREAMING_SNAKE_CASE						) / full_submodule
							if submodule == "local" or submodule == "git":
														# We always copy local files (we could hash the file to see if there was a change, and give them the name of
														# that hash, to only copy when there is a modification but it seems overkill for now).
														# The only reason we do the copy is to avoid putting too many folders in sys.path.
														shutil.copy(SCREAMING_SNAKE_CASE     ,  submodule_path / module_file						)
														for module_needed in modules_needed:
																					_lowerCAmelCase  	=			f"""{module_needed}.py"""
																					shutil.copy(os.path.join(SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE						)     ,  submodule_path / module_needed						)
							else:
														# Get the commit hash
														# TODO: we will get this info in the etag soon, so retrieve it from there and not here.
														if isinstance(SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE						):
																					_lowerCAmelCase  	=			use_auth_token
														elif use_auth_token is True:
																					_lowerCAmelCase  	=			HfFolder.get_token()
														else:
																					_lowerCAmelCase  	=			None

														_lowerCAmelCase  	=			model_info(SCREAMING_SNAKE_CASE     ,  revision=SCREAMING_SNAKE_CASE     ,  token=SCREAMING_SNAKE_CASE						).sha

														# The module file will end up being placed in a subfolder with the git hash of the repo. This way we get the
														# benefit of versioning.
														_lowerCAmelCase  	=			submodule_path / commit_hash
														_lowerCAmelCase  	=			full_submodule + os.path.sep + commit_hash
														create_dynamic_module(SCREAMING_SNAKE_CASE						)

														if not (submodule_path / module_file).exists():
																					shutil.copy(SCREAMING_SNAKE_CASE     ,  submodule_path / module_file						)
														# Make sure we also have every file with relative
														for module_needed in modules_needed:
																					if not (submodule_path / module_needed).exists():
																												get_cached_module_file(
																												    SCREAMING_SNAKE_CASE     ,  f"""{module_needed}.py"""     ,  cache_dir=SCREAMING_SNAKE_CASE     ,  force_download=SCREAMING_SNAKE_CASE     ,  resume_download=SCREAMING_SNAKE_CASE     ,  proxies=SCREAMING_SNAKE_CASE     ,  use_auth_token=SCREAMING_SNAKE_CASE     ,  revision=SCREAMING_SNAKE_CASE     ,  local_files_only=SCREAMING_SNAKE_CASE     ,  )
							return os.path.join(SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE						)






def 	__snake_case  (    SCREAMING_SNAKE_CASE:					Union[str, os.PathLike]     ,  SCREAMING_SNAKE_CASE:					str     ,  SCREAMING_SNAKE_CASE:					Optional[str] = None     ,  SCREAMING_SNAKE_CASE:					Optional[Union[str, os.PathLike]] = None     ,  SCREAMING_SNAKE_CASE:					bool = False     ,  SCREAMING_SNAKE_CASE:					bool = False     ,  SCREAMING_SNAKE_CASE:					Optional[Dict[str, str]] = None     ,  SCREAMING_SNAKE_CASE:					Optional[Union[bool, str]] = None     ,  SCREAMING_SNAKE_CASE:					Optional[str] = None     ,  SCREAMING_SNAKE_CASE:					bool = False     ,  **SCREAMING_SNAKE_CASE:					Optional[Any]     ,  ):






							"""simple docstring"""



							_lowerCAmelCase  	=			get_cached_module_file(
							    SCREAMING_SNAKE_CASE     ,  SCREAMING_SNAKE_CASE     ,  cache_dir=SCREAMING_SNAKE_CASE     ,  force_download=SCREAMING_SNAKE_CASE     ,  resume_download=SCREAMING_SNAKE_CASE     ,  proxies=SCREAMING_SNAKE_CASE     ,  use_auth_token=SCREAMING_SNAKE_CASE     ,  revision=SCREAMING_SNAKE_CASE     ,  local_files_only=SCREAMING_SNAKE_CASE     ,  )
							return get_class_in_module(SCREAMING_SNAKE_CASE     ,  final_module.replace('.py'     ,  ''						)						)








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






				'''simple docstring'''



				def __init__(					self	:			Optional[Any]				,     UpperCAmelCase_	:			int				,     UpperCAmelCase_	:			Dict=7				,     UpperCAmelCase_	:			List[Any]=3				,     UpperCAmelCase_	:			Tuple=18				,     UpperCAmelCase_	:			List[str]=30				,     UpperCAmelCase_	:			Union[str, Any]=400				,     UpperCAmelCase_	:			Optional[Any]=True				,     UpperCAmelCase_	:			Tuple=None				,     UpperCAmelCase_	:			Optional[int]=True				,     UpperCAmelCase_	:			Any=None				,     UpperCAmelCase_	:			Tuple=True				,     UpperCAmelCase_	:			List[Any]=[0.48145466, 0.4578275, 0.40821073]				,     UpperCAmelCase_	:			List[Any]=[0.26862954, 0.26130258, 0.27577711]				,     UpperCAmelCase_	:			Optional[int]=True				,     )		->  Tuple:







											"""simple docstring"""




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


				def 				__lowerCamelCase	(					self	:			Optional[int]  )		->  int:







											"""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	:			Dict				,     UpperCAmelCase_	:			Dict=False				,     UpperCAmelCase_	:			int=False				,     UpperCAmelCase_	:			Dict=False  )		->  str:







											"""simple docstring"""




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

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

											if torchify:
																		_lowerCAmelCase  	=			[torch.from_numpy(UpperCAmelCase_  ) for x in image_inputs]

											return image_inputs






@require_torch
@require_vision
class        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase      ,				unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							List[Any]							=					ChineseCLIPImageProcessor if is_vision_available() else None


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







											"""simple docstring"""




											_lowerCAmelCase  	=			ChineseCLIPImageProcessingTester(self				,     do_center_crop=UpperCAmelCase_  )


				@property
				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  int:







											"""simple docstring"""




											return self.image_processor_tester.prepare_image_processor_dict()


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  Optional[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			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 				__lowerCamelCase	(					self	:			Dict  )		->  Tuple:







											"""simple docstring"""




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

											_lowerCAmelCase  	=			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	:			Union[str, Any]  )		->  List[str]:







											"""simple docstring"""




											pass


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Optional[Any]:







											"""simple docstring"""




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

											# Test not batched input
											_lowerCAmelCase  	=			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
											_lowerCAmelCase  	=			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 				__lowerCamelCase	(					self	:			List[str]  )		->  int:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											# create random numpy tensors
											_lowerCAmelCase  	=			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
											_lowerCAmelCase  	=			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
											_lowerCAmelCase  	=			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 				__lowerCamelCase	(					self	:			List[Any]  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			self.image_processing_class(**self.image_processor_dict  )
											# create random PyTorch tensors
											_lowerCAmelCase  	=			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
											_lowerCAmelCase  	=			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
											_lowerCAmelCase  	=			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        _SCREAMING_SNAKE_CASE  (  UpperCAmelCase      ,				unittest.TestCase							):






				'''simple docstring'''



				SCREAMING_SNAKE_CASE_:							str							=					ChineseCLIPImageProcessor if is_vision_available() else None


				def 				__lowerCamelCase	(					self	:			List[str]  )		->  List[Any]:







											"""simple docstring"""




											_lowerCAmelCase  	=			ChineseCLIPImageProcessingTester(self				,     num_channels=4				,     do_center_crop=UpperCAmelCase_  )
											_lowerCAmelCase  	=			3


				@property
				def 				__lowerCamelCase	(					self	:			Union[str, Any]  )		->  Dict:







											"""simple docstring"""




											return self.image_processor_tester.prepare_image_processor_dict()


				def 				__lowerCamelCase	(					self	:			Optional[Any]  )		->  Dict:







											"""simple docstring"""




											_lowerCAmelCase  	=			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 				__lowerCamelCase	(					self	:			List[Any]  )		->  Optional[int]:







											"""simple docstring"""




											pass







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







											"""simple docstring"""




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

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






