




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 CLIPImageProcessor




class     A					(				unittest.TestCase       ):







							def __init__(    self   :	Any   ,     __UpperCAmelCase   :	Optional[int]   ,     __UpperCAmelCase   :	List[Any]=7   ,     __UpperCAmelCase   :	Union[str, Any]=3   ,     __UpperCAmelCase   :	Optional[Any]=18   ,     __UpperCAmelCase   :	List[str]=30   ,     __UpperCAmelCase   :	int=400   ,     __UpperCAmelCase   :	List[Any]=True   ,     __UpperCAmelCase   :	Tuple=None   ,     __UpperCAmelCase   :	Optional[Any]=True   ,     __UpperCAmelCase   :	Any=None   ,     __UpperCAmelCase   :	Optional[int]=True   ,     __UpperCAmelCase   :	List[str]=[0.48_145_466, 0.4_578_275, 0.40_821_073]   ,     __UpperCAmelCase   :	List[Any]=[0.26_862_954, 0.26_130_258, 0.27_577_711]   ,     __UpperCAmelCase   :	Dict=True   ,     )		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= size if size is not None else {'shortest_edge': 20}
										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        lowercase__							(    self   :	Tuple				)		->					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        lowercase__							(    self   :	List[Any]   ,     __UpperCAmelCase   :	str=False   ,     __UpperCAmelCase   :	Tuple=False   ,     __UpperCAmelCase   :	Optional[int]=False				)		->					Any:

										"""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_				,   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(__UpperCAmelCase   ,     0   ,     -1				)				) for x in image_inputs]

										if torchify:
													UpperCamelCase_     				= [torch.from_numpy(__UpperCAmelCase				) for x in image_inputs]

										return image_inputs







@require_torch
@require_vision
class     A					(				lowerCamelCase_  ,						unittest.TestCase       ):
							_SCREAMING_SNAKE_CASE  :		Any			  =       CLIPImageProcessor if is_vision_available() else None







							def        lowercase__							(    self   :	Dict				)		->					List[str]:

										"""simple docstring"""



										UpperCamelCase_     				= CLIPImageProcessingTester(self				)







							@property
							def        lowercase__							(    self   :	Optional[int]				)		->					Optional[Any]:

										"""simple docstring"""



										return self.image_processor_tester.prepare_image_processor_dict()







							def        lowercase__							(    self   :	Tuple				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= 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        lowercase__							(    self   :	Optional[int]				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class.from_dict(self.image_processor_dict				)
										self.assertEqual(image_processor.size   ,     {'shortest_edge': 20}				)
										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        lowercase__							(    self   :	Union[str, Any]				)		->					Optional[int]:

										"""simple docstring"""



										pass







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

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										# create random PIL images
										UpperCamelCase_     				= self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase				)
										for image in image_inputs:
													self.assertIsInstance(__UpperCAmelCase   ,     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(__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        lowercase__							(    self   :	Optional[Any]				)		->					Tuple:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										# create random numpy tensors
										UpperCamelCase_     				= 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
										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(__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        lowercase__							(    self   :	Optional[Any]				)		->					Any:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										# create random PyTorch tensors
										UpperCamelCase_     				= 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
										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(__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     A					(				lowerCamelCase_  ,						unittest.TestCase       ):
							_SCREAMING_SNAKE_CASE  :		str			  =       CLIPImageProcessor if is_vision_available() else None







							def        lowercase__							(    self   :	str				)		->					Any:

										"""simple docstring"""



										UpperCamelCase_     				= CLIPImageProcessingTester(self   ,     num_channels=4				)
										UpperCamelCase_     				= 3







							@property
							def        lowercase__							(    self   :	Dict				)		->					str:

										"""simple docstring"""



										return self.image_processor_tester.prepare_image_processor_dict()







							def        lowercase__							(    self   :	Optional[int]				)		->					List[str]:

										"""simple docstring"""



										UpperCamelCase_     				= 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        lowercase__							(    self   :	int				)		->					Any:

										"""simple docstring"""



										pass







							def        lowercase__							(    self   :	Any				)		->					Optional[int]:

										"""simple docstring"""



										UpperCamelCase_     				= self.image_processing_class(**self.image_processor_dict				)
										# create random PIL images
										UpperCamelCase_     				= self.image_processor_tester.prepare_inputs(equal_resolution=__UpperCAmelCase				)
										for image in image_inputs:
													self.assertIsInstance(__UpperCAmelCase   ,     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(__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'],
										    )   ,     )






from typing import TYPE_CHECKING

from ..utils import OptionalDependencyNotAvailable, _LazyModule, is_flax_available, is_tf_available, is_torch_available


__a			:	List[Any]							     =		{
    """configuration_utils""": ["""GenerationConfig"""],
    """streamers""": ["""TextIteratorStreamer""", """TextStreamer"""],
}

try:
				if not is_torch_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__a			:	Dict							     =		[
				    """Constraint""",
				    """ConstraintListState""",
				    """DisjunctiveConstraint""",
				    """PhrasalConstraint""",
				]
				__a			:	int							     =		[
				    """BeamHypotheses""",
				    """BeamScorer""",
				    """BeamSearchScorer""",
				    """ConstrainedBeamSearchScorer""",
				]
				__a			:	List[Any]							     =		[
				    """EpsilonLogitsWarper""",
				    """EtaLogitsWarper""",
				    """ForcedBOSTokenLogitsProcessor""",
				    """ForcedEOSTokenLogitsProcessor""",
				    """HammingDiversityLogitsProcessor""",
				    """InfNanRemoveLogitsProcessor""",
				    """LogitsProcessor""",
				    """LogitsProcessorList""",
				    """LogitsWarper""",
				    """MinLengthLogitsProcessor""",
				    """MinNewTokensLengthLogitsProcessor""",
				    """NoBadWordsLogitsProcessor""",
				    """NoRepeatNGramLogitsProcessor""",
				    """PrefixConstrainedLogitsProcessor""",
				    """RepetitionPenaltyLogitsProcessor""",
				    """SequenceBiasLogitsProcessor""",
				    """EncoderRepetitionPenaltyLogitsProcessor""",
				    """TemperatureLogitsWarper""",
				    """TopKLogitsWarper""",
				    """TopPLogitsWarper""",
				    """TypicalLogitsWarper""",
				    """EncoderNoRepeatNGramLogitsProcessor""",
				    """ExponentialDecayLengthPenalty""",
				    """LogitNormalization""",
				]
				__a			:	Any							     =		[
				    """MaxNewTokensCriteria""",
				    """MaxLengthCriteria""",
				    """MaxTimeCriteria""",
				    """StoppingCriteria""",
				    """StoppingCriteriaList""",
				    """validate_stopping_criteria""",
				]
				__a			:	str							     =		[
				    """GenerationMixin""",
				    """top_k_top_p_filtering""",
				    """GreedySearchEncoderDecoderOutput""",
				    """GreedySearchDecoderOnlyOutput""",
				    """SampleEncoderDecoderOutput""",
				    """SampleDecoderOnlyOutput""",
				    """BeamSearchEncoderDecoderOutput""",
				    """BeamSearchDecoderOnlyOutput""",
				    """BeamSampleEncoderDecoderOutput""",
				    """BeamSampleDecoderOnlyOutput""",
				    """ContrastiveSearchEncoderDecoderOutput""",
				    """ContrastiveSearchDecoderOnlyOutput""",
				]

try:
				if not is_tf_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__a			:	List[Any]							     =		[
				    """TFForcedBOSTokenLogitsProcessor""",
				    """TFForcedEOSTokenLogitsProcessor""",
				    """TFLogitsProcessor""",
				    """TFLogitsProcessorList""",
				    """TFLogitsWarper""",
				    """TFMinLengthLogitsProcessor""",
				    """TFNoBadWordsLogitsProcessor""",
				    """TFNoRepeatNGramLogitsProcessor""",
				    """TFRepetitionPenaltyLogitsProcessor""",
				    """TFTemperatureLogitsWarper""",
				    """TFTopKLogitsWarper""",
				    """TFTopPLogitsWarper""",
				    """TFForceTokensLogitsProcessor""",
				    """TFSuppressTokensAtBeginLogitsProcessor""",
				    """TFSuppressTokensLogitsProcessor""",
				]
				__a			:	Any							     =		[
				    """TFGenerationMixin""",
				    """tf_top_k_top_p_filtering""",
				    """TFGreedySearchDecoderOnlyOutput""",
				    """TFGreedySearchEncoderDecoderOutput""",
				    """TFSampleEncoderDecoderOutput""",
				    """TFSampleDecoderOnlyOutput""",
				    """TFBeamSearchEncoderDecoderOutput""",
				    """TFBeamSearchDecoderOnlyOutput""",
				    """TFBeamSampleEncoderDecoderOutput""",
				    """TFBeamSampleDecoderOnlyOutput""",
				    """TFContrastiveSearchEncoderDecoderOutput""",
				    """TFContrastiveSearchDecoderOnlyOutput""",
				]

try:
				if not is_flax_available():
								raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
				pass
else:
				__a			:	str							     =		[
				    """FlaxForcedBOSTokenLogitsProcessor""",
				    """FlaxForcedEOSTokenLogitsProcessor""",
				    """FlaxLogitsProcessor""",
				    """FlaxLogitsProcessorList""",
				    """FlaxLogitsWarper""",
				    """FlaxMinLengthLogitsProcessor""",
				    """FlaxTemperatureLogitsWarper""",
				    """FlaxTopKLogitsWarper""",
				    """FlaxTopPLogitsWarper""",
				]
				__a			:	Tuple							     =		[
				    """FlaxGenerationMixin""",
				    """FlaxGreedySearchOutput""",
				    """FlaxSampleOutput""",
				    """FlaxBeamSearchOutput""",
				]

if TYPE_CHECKING:
				from .configuration_utils import GenerationConfig
				from .streamers import TextIteratorStreamer, TextStreamer

				try:
								if not is_torch_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .beam_constraints import Constraint, ConstraintListState, DisjunctiveConstraint, PhrasalConstraint
								from .beam_search import BeamHypotheses, BeamScorer, BeamSearchScorer, ConstrainedBeamSearchScorer
								from .logits_process import (
								    EncoderNoRepeatNGramLogitsProcessor,
								    EncoderRepetitionPenaltyLogitsProcessor,
								    EpsilonLogitsWarper,
								    EtaLogitsWarper,
								    ExponentialDecayLengthPenalty,
								    ForcedBOSTokenLogitsProcessor,
								    ForcedEOSTokenLogitsProcessor,
								    HammingDiversityLogitsProcessor,
								    InfNanRemoveLogitsProcessor,
								    LogitNormalization,
								    LogitsProcessor,
								    LogitsProcessorList,
								    LogitsWarper,
								    MinLengthLogitsProcessor,
								    MinNewTokensLengthLogitsProcessor,
								    NoBadWordsLogitsProcessor,
								    NoRepeatNGramLogitsProcessor,
								    PrefixConstrainedLogitsProcessor,
								    RepetitionPenaltyLogitsProcessor,
								    SequenceBiasLogitsProcessor,
								    TemperatureLogitsWarper,
								    TopKLogitsWarper,
								    TopPLogitsWarper,
								    TypicalLogitsWarper,
								)
								from .stopping_criteria import (
								    MaxLengthCriteria,
								    MaxNewTokensCriteria,
								    MaxTimeCriteria,
								    StoppingCriteria,
								    StoppingCriteriaList,
								    validate_stopping_criteria,
								)
								from .utils import (
								    BeamSampleDecoderOnlyOutput,
								    BeamSampleEncoderDecoderOutput,
								    BeamSearchDecoderOnlyOutput,
								    BeamSearchEncoderDecoderOutput,
								    ContrastiveSearchDecoderOnlyOutput,
								    ContrastiveSearchEncoderDecoderOutput,
								    GenerationMixin,
								    GreedySearchDecoderOnlyOutput,
								    GreedySearchEncoderDecoderOutput,
								    SampleDecoderOnlyOutput,
								    SampleEncoderDecoderOutput,
								    top_k_top_p_filtering,
								)

				try:
								if not is_tf_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .tf_logits_process import (
								    TFForcedBOSTokenLogitsProcessor,
								    TFForcedEOSTokenLogitsProcessor,
								    TFForceTokensLogitsProcessor,
								    TFLogitsProcessor,
								    TFLogitsProcessorList,
								    TFLogitsWarper,
								    TFMinLengthLogitsProcessor,
								    TFNoBadWordsLogitsProcessor,
								    TFNoRepeatNGramLogitsProcessor,
								    TFRepetitionPenaltyLogitsProcessor,
								    TFSuppressTokensAtBeginLogitsProcessor,
								    TFSuppressTokensLogitsProcessor,
								    TFTemperatureLogitsWarper,
								    TFTopKLogitsWarper,
								    TFTopPLogitsWarper,
								)
								from .tf_utils import (
								    TFBeamSampleDecoderOnlyOutput,
								    TFBeamSampleEncoderDecoderOutput,
								    TFBeamSearchDecoderOnlyOutput,
								    TFBeamSearchEncoderDecoderOutput,
								    TFContrastiveSearchDecoderOnlyOutput,
								    TFContrastiveSearchEncoderDecoderOutput,
								    TFGenerationMixin,
								    TFGreedySearchDecoderOnlyOutput,
								    TFGreedySearchEncoderDecoderOutput,
								    TFSampleDecoderOnlyOutput,
								    TFSampleEncoderDecoderOutput,
								    tf_top_k_top_p_filtering,
								)

				try:
								if not is_flax_available():
												raise OptionalDependencyNotAvailable()
				except OptionalDependencyNotAvailable:
								pass
				else:
								from .flax_logits_process import (
								    FlaxForcedBOSTokenLogitsProcessor,
								    FlaxForcedEOSTokenLogitsProcessor,
								    FlaxLogitsProcessor,
								    FlaxLogitsProcessorList,
								    FlaxLogitsWarper,
								    FlaxMinLengthLogitsProcessor,
								    FlaxTemperatureLogitsWarper,
								    FlaxTopKLogitsWarper,
								    FlaxTopPLogitsWarper,
								)
								from .flax_utils import FlaxBeamSearchOutput, FlaxGenerationMixin, FlaxGreedySearchOutput, FlaxSampleOutput
else:
				import sys

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