



'''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			,				UpperCamelCase			,				UpperCamelCase=7			,				UpperCamelCase=3			,				UpperCamelCase=18			,				UpperCamelCase=30			,				UpperCamelCase=400			,				UpperCamelCase=True			,				UpperCamelCase=None			,				UpperCamelCase=True			,				UpperCamelCase=None			,				UpperCamelCase=True			,				UpperCamelCase=[0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73]			,				UpperCamelCase=[0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11]			,				UpperCamelCase=True			,				)     ->			List[Any]:
						__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        UpperCAmelCase_ (    self     )     ->			Any:
						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        UpperCAmelCase_ (    self			,				UpperCamelCase=False			,				UpperCamelCase=False			,				UpperCamelCase=False     )     ->			Union[str, Any]:
						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 					UpperCAmelCase__	(		UpperCamelCase__							,       unittest.TestCase ):
					a      :     Any        =							ChineseCLIPImageProcessor if is_vision_available() else None



					def        UpperCAmelCase_ (    self     )     ->			Union[str, Any]:
						__lowerCAmelCase												=  ChineseCLIPImageProcessingTester(self			,				do_center_crop=UpperCamelCase     )



					@property
					def        UpperCAmelCase_ (    self     )     ->			List[Any]:
						return self.image_processor_tester.prepare_image_processor_dict()



					def        UpperCAmelCase_ (    self     )     ->			Any:
						__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        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						__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        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						pass



					def        UpperCAmelCase_ (    self     )     ->			Any:
						# Initialize image_processing
						__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        UpperCAmelCase_ (    self     )     ->			List[str]:
						# Initialize image_processing
						__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        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						# Initialize image_processing
						__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 					UpperCAmelCase__	(		UpperCamelCase__							,       unittest.TestCase ):
					a      :     int        =							ChineseCLIPImageProcessor if is_vision_available() else None



					def        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						__lowerCAmelCase												=  ChineseCLIPImageProcessingTester(self			,				num_channels=4			,				do_center_crop=UpperCamelCase     )
						__lowerCAmelCase												=  3



					@property
					def        UpperCAmelCase_ (    self     )     ->			str:
						return self.image_processor_tester.prepare_image_processor_dict()



					def        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						__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        UpperCAmelCase_ (    self     )     ->			Tuple:
						pass



					def        UpperCAmelCase_ (    self     )     ->			str:
						# Initialize image_processing
						__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"],
						    )			,				)




'''simple docstring'''



import importlib
import os
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Optional, Union

import torch

from ..utils import BaseOutput


lowerCAmelCase	:		Optional[Any]				=   '''scheduler_config.json'''






class 					UpperCAmelCase__	(		UpperCamelCase__ ):
					a      :     str        =							1
					a      :     Optional[int]        =							2
					a      :     int        =							3
					a      :     Union[str, Any]        =							4
					a      :     int        =							5
					a      :     Optional[int]        =							6
					a      :     str        =							7
					a      :     List[Any]        =							8
					a      :     List[str]        =							9
					a      :     List[str]        =							1_0
					a      :     int        =							1_1
					a      :     Any        =							1_2
					a      :     Any        =							1_3
					a      :     Tuple        =							1_4






@dataclass
class 					UpperCAmelCase__	(		UpperCamelCase__ ):
					a      :     torch.FloatTensor






class 					UpperCAmelCase__	:
					a      :     Tuple        =							SCHEDULER_CONFIG_NAME
					a      :     Union[str, Any]        =							[]
					a      :     str        =							True



					@classmethod
					def        UpperCAmelCase_ (    cls			,				UpperCamelCase = None			,				UpperCamelCase = None			,				UpperCamelCase=False			,				**UpperCamelCase			,				)     ->			int:
						__lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase												=  cls.load_config(
						    pretrained_model_name_or_path=UpperCamelCase			,				subfolder=UpperCamelCase			,				return_unused_kwargs=UpperCamelCase			,				return_commit_hash=UpperCamelCase			,				**UpperCamelCase			,				)
						return cls.from_config(UpperCamelCase			,				return_unused_kwargs=UpperCamelCase			,				**UpperCamelCase     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase = False			,				**UpperCamelCase     )     ->			Dict:
						self.save_config(save_directory=UpperCamelCase			,				push_to_hub=UpperCamelCase			,				**UpperCamelCase     )



					@property
					def        UpperCAmelCase_ (    self     )     ->			str:
						return self._get_compatibles()



					@classmethod
					def        UpperCAmelCase_ (    cls     )     ->			Tuple:
						__lowerCAmelCase												=  list(set([cls.__name__] + cls._compatibles     )     )
						__lowerCAmelCase												=  importlib.import_module(__name__.split("."     )[0]     )
						__lowerCAmelCase												=  [
						    getattr(UpperCamelCase			,				UpperCamelCase     ) for c in compatible_classes_str if hasattr(UpperCamelCase			,				UpperCamelCase     )
						]
						return compatible_classes