
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 ConvNextImageProcessor
class 			lowercase__(    unittest.TestCase							):



	"""simple docstring"""




	def __init__(	self  :      List[str]	,							SCREAMING_SNAKE_CASE_  :      Tuple	,							SCREAMING_SNAKE_CASE_  :      Any=7	,							SCREAMING_SNAKE_CASE_  :      List[Any]=3	,							SCREAMING_SNAKE_CASE_  :      int=1_8	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]=3_0	,							SCREAMING_SNAKE_CASE_  :      Dict=4_0_0	,							SCREAMING_SNAKE_CASE_  :      Any=True	,							SCREAMING_SNAKE_CASE_  :      str=None	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]=0.8_75	,							SCREAMING_SNAKE_CASE_  :      int=True	,							SCREAMING_SNAKE_CASE_  :      Optional[Any]=[0.5, 0.5, 0.5]	,							SCREAMING_SNAKE_CASE_  :      Any=[0.5, 0.5, 0.5]	,							)	->					str:
					lowercase_					  = size if size is not None else {'''shortest_edge''': 2_0}
					lowercase_					  = parent
					lowercase_					  = batch_size
					lowercase_					  = num_channels
					lowercase_					  = image_size
					lowercase_					  = min_resolution
					lowercase_					  = max_resolution
					lowercase_					  = do_resize
					lowercase_					  = size
					lowercase_					  = crop_pct
					lowercase_					  = do_normalize
					lowercase_					  = image_mean
					lowercase_					  = image_std




	def 						_lowercase  (	self  :      Optional[int]	)	->					int:
					return {
					    "image_mean": self.image_mean,
					    "image_std": self.image_std,
					    "do_normalize": self.do_normalize,
					    "do_resize": self.do_resize,
					    "size": self.size,
					    "crop_pct": self.crop_pct,
					}

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



	"""simple docstring"""




	a      :str   					=     ConvNextImageProcessor if is_vision_available() else None
	def 						_lowercase  (	self  :      List[str]	)	->					Any:
					lowercase_					  = ConvNextImageProcessingTester(self	)
	@property
	def 						_lowercase  (	self  :      Optional[Any]	)	->					Dict:
					return self.image_processor_tester.prepare_image_processor_dict()
	def 						_lowercase  (	self  :      int	)	->					Union[str, Any]:
					lowercase_					  = self.image_processing_class(**self.image_processor_dict	)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_	,							'''do_resize'''	)	)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_	,							'''size'''	)	)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_	,							'''crop_pct'''	)	)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_	,							'''do_normalize'''	)	)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_	,							'''image_mean'''	)	)
					self.assertTrue(hasattr(SCREAMING_SNAKE_CASE_	,							'''image_std'''	)	)
	def 						_lowercase  (	self  :      List[Any]	)	->					int:
					lowercase_					  = self.image_processing_class.from_dict(self.image_processor_dict	)
					self.assertEqual(image_processor.size	,							{'''shortest_edge''': 2_0}	)

					lowercase_					  = self.image_processing_class.from_dict(self.image_processor_dict	,							size=4_2	)
					self.assertEqual(image_processor.size	,							{'''shortest_edge''': 4_2}	)
	def 						_lowercase  (	self  :      int	)	->					Union[str, Any]:
					pass
	def 						_lowercase  (	self  :      Union[str, Any]	)	->					Optional[Any]:
					# Initialize image_processing
					lowercase_					  = self.image_processing_class(**self.image_processor_dict	)
					# create random PIL images
					lowercase_					  = prepare_image_inputs(self.image_processor_tester	,							equal_resolution=SCREAMING_SNAKE_CASE_	)
					for image in image_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_	,							Image.Image	)

					# Test not batched input
					lowercase_					  = 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.size['''shortest_edge'''],
					        self.image_processor_tester.size['''shortest_edge'''],
					    )	,							)

					# Test batched
					lowercase_					  = image_processing(SCREAMING_SNAKE_CASE_	,							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.size['''shortest_edge'''],
					        self.image_processor_tester.size['''shortest_edge'''],
					    )	,							)
	def 						_lowercase  (	self  :      Any	)	->					List[str]:
					# Initialize image_processing
					lowercase_					  = self.image_processing_class(**self.image_processor_dict	)
					# create random numpy tensors
					lowercase_					  = prepare_image_inputs(self.image_processor_tester	,							equal_resolution=SCREAMING_SNAKE_CASE_	,							numpify=SCREAMING_SNAKE_CASE_	)
					for image in image_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_	,							np.ndarray	)

					# Test not batched input
					lowercase_					  = 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.size['''shortest_edge'''],
					        self.image_processor_tester.size['''shortest_edge'''],
					    )	,							)

					# Test batched
					lowercase_					  = image_processing(SCREAMING_SNAKE_CASE_	,							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.size['''shortest_edge'''],
					        self.image_processor_tester.size['''shortest_edge'''],
					    )	,							)




	def 						_lowercase  (	self  :      int	)	->					Union[str, Any]:
					# Initialize image_processing
					lowercase_					  = self.image_processing_class(**self.image_processor_dict	)
					# create random PyTorch tensors
					lowercase_					  = prepare_image_inputs(self.image_processor_tester	,							equal_resolution=SCREAMING_SNAKE_CASE_	,							torchify=SCREAMING_SNAKE_CASE_	)
					for image in image_inputs:
									self.assertIsInstance(SCREAMING_SNAKE_CASE_	,							torch.Tensor	)

					# Test not batched input
					lowercase_					  = 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.size['''shortest_edge'''],
					        self.image_processor_tester.size['''shortest_edge'''],
					    )	,							)

					# Test batched
					lowercase_					  = image_processing(SCREAMING_SNAKE_CASE_	,							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.size['''shortest_edge'''],
					        self.image_processor_tester.size['''shortest_edge'''],
					    )	,							)






from typing import TYPE_CHECKING

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


__a        = {
    'configuration_speech_to_text_2': ['SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP', 'Speech2Text2Config'],
    'processing_speech_to_text_2': ['Speech2Text2Processor'],
    'tokenization_speech_to_text_2': ['Speech2Text2Tokenizer'],
}


try:
						if not is_torch_available():
												raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
						pass
else:
						__a        = [
						    'SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST',
						    'Speech2Text2ForCausalLM',
						    'Speech2Text2PreTrainedModel',
						]


if TYPE_CHECKING:
						from .configuration_speech_to_text_a import SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP, SpeechaTextaConfig
						from .processing_speech_to_text_a import SpeechaTextaProcessor
						from .tokenization_speech_to_text_a import SpeechaTextaTokenizer

						try:
												if not is_torch_available():
																		raise OptionalDependencyNotAvailable()
						except OptionalDependencyNotAvailable:
												pass
						else:
												from .modeling_speech_to_text_a import (
												    SPEECH_TO_TEXT_2_PRETRAINED_MODEL_ARCHIVE_LIST,
												    SpeechaTextaForCausalLM,
												    SpeechaTextaPreTrainedModel,
												)

else:
						import sys

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




