


"""simple docstring"""
import unittest

import numpy as np
from datasets import load_dataset

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 BeitImageProcessor





class      __A     (unittest.TestCase):





							'''simple docstring'''

							def __init__(				self							:      Tuple		,       UpperCAmelCase_							:      Optional[int]		,       UpperCAmelCase_							:      Union[str, Any]=7		,       UpperCAmelCase_							:      Dict=3		,       UpperCAmelCase_							:      List[Any]=18		,       UpperCAmelCase_							:      int=30		,       UpperCAmelCase_							:      List[Any]=400		,       UpperCAmelCase_							:      Dict=True		,       UpperCAmelCase_							:      Optional[Any]=None		,       UpperCAmelCase_							:      Optional[Any]=True		,       UpperCAmelCase_							:      Optional[Any]=None		,       UpperCAmelCase_							:      int=True		,       UpperCAmelCase_							:      Optional[int]=[0.5, 0.5, 0.5]		,       UpperCAmelCase_							:      Optional[int]=[0.5, 0.5, 0.5]		,       UpperCAmelCase_							:      int=False		,       )					->str:



														"""simple docstring"""



														snake_case_           =		size if size is not None else {"""height""": 20, """width""": 20}
														snake_case_           =		crop_size if crop_size is not None else {"""height""": 18, """width""": 18}
														snake_case_           =		parent
														snake_case_           =		batch_size
														snake_case_           =		num_channels
														snake_case_           =		image_size
														snake_case_           =		min_resolution
														snake_case_           =		max_resolution
														snake_case_           =		do_resize
														snake_case_           =		size
														snake_case_           =		do_center_crop
														snake_case_           =		crop_size
														snake_case_           =		do_normalize
														snake_case_           =		image_mean
														snake_case_           =		image_std
														snake_case_           =		do_reduce_labels



							def 		lowerCAmelCase       (				self							:      List[str]       )					->Union[str, 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_reduce_labels": self.do_reduce_labels,
														}







def 						_a				(      )    ->				List[Any]:
							snake_case_           =		load_dataset("""hf-internal-testing/fixtures_ade20k"""				, split="""test"""				)

							snake_case_           =		Image.open(dataset[0]["""file"""]				)
							snake_case_           =		Image.open(dataset[1]["""file"""]				)

							return image, map







def 						_a				(      )    ->				Dict:
							snake_case_           =		load_dataset("""hf-internal-testing/fixtures_ade20k"""				, split="""test"""				)

							snake_case_           =		Image.open(ds[0]["""file"""]				)
							snake_case_           =		Image.open(ds[1]["""file"""]				)
							snake_case_           =		Image.open(ds[2]["""file"""]				)
							snake_case_           =		Image.open(ds[3]["""file"""]				)

							return [imagea, imagea], [mapa, mapa]





@require_torch
@require_vision
class      __A     (snake_case__						,		unittest.TestCase):





							'''simple docstring'''

							__lowercase:		List[str]							      =    BeitImageProcessor if is_vision_available() else None



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



														"""simple docstring"""



														snake_case_           =		BeitImageProcessingTester(self       )



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



														"""simple docstring"""



														return self.image_processor_tester.prepare_image_processor_dict()



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



														"""simple docstring"""



														snake_case_           =		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"""       )       )



							def 		lowerCAmelCase       (				self							:      Tuple       )					->Dict:



														"""simple docstring"""



														snake_case_           =		self.image_processing_class.from_dict(self.image_processor_dict       )
														self.assertEqual(image_processor.size		,       {"""height""": 20, """width""": 20}       )
														self.assertEqual(image_processor.crop_size		,       {"""height""": 18, """width""": 18}       )
														self.assertEqual(image_processor.do_reduce_labels		,       UpperCAmelCase_       )

														snake_case_           =		self.image_processing_class.from_dict(
														    self.image_processor_dict		,       size=42		,       crop_size=84		,       reduce_labels=UpperCAmelCase_       )
														self.assertEqual(image_processor.size		,       {"""height""": 42, """width""": 42}       )
														self.assertEqual(image_processor.crop_size		,       {"""height""": 84, """width""": 84}       )
														self.assertEqual(image_processor.do_reduce_labels		,       UpperCAmelCase_       )



							def 		lowerCAmelCase       (				self							:      Tuple       )					->Dict:



														"""simple docstring"""



														pass



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



														"""simple docstring"""



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

														# Test not batched input
														snake_case_           =		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
														snake_case_           =		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]       )					->Union[str, Any]:



														"""simple docstring"""



														snake_case_           =		self.image_processing_class(**self.image_processor_dict       )
														# create random numpy tensors
														snake_case_           =		prepare_image_inputs(self.image_processor_tester		,       equal_resolution=UpperCAmelCase_		,       numpify=UpperCAmelCase_       )
														for image in image_inputs:
																					self.assertIsInstance(UpperCAmelCase_		,       np.ndarray       )

														# Test not batched input
														snake_case_           =		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
														snake_case_           =		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							:      Tuple       )					->Tuple:



														"""simple docstring"""



														snake_case_           =		self.image_processing_class(**self.image_processor_dict       )
														# create random PyTorch tensors
														snake_case_           =		prepare_image_inputs(self.image_processor_tester		,       equal_resolution=UpperCAmelCase_		,       torchify=UpperCAmelCase_       )
														for image in image_inputs:
																					self.assertIsInstance(UpperCAmelCase_		,       torch.Tensor       )

														# Test not batched input
														snake_case_           =		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
														snake_case_           =		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]       )					->Union[str, Any]:



														"""simple docstring"""



														snake_case_           =		self.image_processing_class(**self.image_processor_dict       )
														# create random PyTorch tensors
														snake_case_           =		prepare_image_inputs(self.image_processor_tester		,       equal_resolution=UpperCAmelCase_		,       torchify=UpperCAmelCase_       )
														snake_case_           =		[]
														for image in image_inputs:
																					self.assertIsInstance(UpperCAmelCase_		,       torch.Tensor       )
																					maps.append(torch.zeros(image.shape[-2:]       ).long()       )

														# Test not batched input
														snake_case_           =		image_processing(image_inputs[0]		,       maps[0]		,       return_tensors="""pt"""       )
														self.assertEqual(
														    encoding["""pixel_values"""].shape		,       (
														        1,
														        self.image_processor_tester.num_channels,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(
														    encoding["""labels"""].shape		,       (
														        1,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(encoding["""labels"""].dtype		,       torch.long       )
														self.assertTrue(encoding["""labels"""].min().item() >= 0       )
														self.assertTrue(encoding["""labels"""].max().item() <= 255       )

														# Test batched
														snake_case_           =		image_processing(UpperCAmelCase_		,       UpperCAmelCase_		,       return_tensors="""pt"""       )
														self.assertEqual(
														    encoding["""pixel_values"""].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"""],
														    )		,       )
														self.assertEqual(
														    encoding["""labels"""].shape		,       (
														        self.image_processor_tester.batch_size,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(encoding["""labels"""].dtype		,       torch.long       )
														self.assertTrue(encoding["""labels"""].min().item() >= 0       )
														self.assertTrue(encoding["""labels"""].max().item() <= 255       )

														# Test not batched input (PIL images)
														snake_case_       ,						snake_case_           =		prepare_semantic_single_inputs()

														snake_case_           =		image_processing(UpperCAmelCase_		,       UpperCAmelCase_		,       return_tensors="""pt"""       )
														self.assertEqual(
														    encoding["""pixel_values"""].shape		,       (
														        1,
														        self.image_processor_tester.num_channels,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(
														    encoding["""labels"""].shape		,       (
														        1,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(encoding["""labels"""].dtype		,       torch.long       )
														self.assertTrue(encoding["""labels"""].min().item() >= 0       )
														self.assertTrue(encoding["""labels"""].max().item() <= 255       )

														# Test batched input (PIL images)
														snake_case_       ,						snake_case_           =		prepare_semantic_batch_inputs()

														snake_case_           =		image_processing(UpperCAmelCase_		,       UpperCAmelCase_		,       return_tensors="""pt"""       )
														self.assertEqual(
														    encoding["""pixel_values"""].shape		,       (
														        2,
														        self.image_processor_tester.num_channels,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(
														    encoding["""labels"""].shape		,       (
														        2,
														        self.image_processor_tester.crop_size["""height"""],
														        self.image_processor_tester.crop_size["""width"""],
														    )		,       )
														self.assertEqual(encoding["""labels"""].dtype		,       torch.long       )
														self.assertTrue(encoding["""labels"""].min().item() >= 0       )
														self.assertTrue(encoding["""labels"""].max().item() <= 255       )



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



														"""simple docstring"""



														snake_case_           =		self.image_processing_class(**self.image_processor_dict       )

														# ADE20k has 150 classes, and the background is included, so labels should be between 0 and 150
														snake_case_       ,						snake_case_           =		prepare_semantic_single_inputs()
														snake_case_           =		image_processing(UpperCAmelCase_		,       UpperCAmelCase_		,       return_tensors="""pt"""       )
														self.assertTrue(encoding["""labels"""].min().item() >= 0       )
														self.assertTrue(encoding["""labels"""].max().item() <= 150       )

														snake_case_           =		True
														snake_case_           =		image_processing(UpperCAmelCase_		,       UpperCAmelCase_		,       return_tensors="""pt"""       )
														self.assertTrue(encoding["""labels"""].min().item() >= 0       )
														self.assertTrue(encoding["""labels"""].max().item() <= 255       )






"""simple docstring"""
from ....configuration_utils import PretrainedConfig
from ....utils import logging


__SCREAMING_SNAKE_CASE							:    str		=    logging.get_logger(__name__)

__SCREAMING_SNAKE_CASE							:    str		=    {
    'speechbrain/m-ctc-t-large': 'https://huggingface.co/speechbrain/m-ctc-t-large/resolve/main/config.json',
    # See all M-CTC-T models at https://huggingface.co/models?filter=mctct
}





class      __A     (snake_case__):





							'''simple docstring'''

							__lowercase:		Any							      =    """mctct"""



							def __init__(				self							:      Dict		,       UpperCAmelCase_							:      List[Any]=8_065		,       UpperCAmelCase_							:      Tuple=1_536		,       UpperCAmelCase_							:      Optional[Any]=36		,       UpperCAmelCase_							:      int=6_144		,       UpperCAmelCase_							:      Dict=4		,       UpperCAmelCase_							:      Any=384		,       UpperCAmelCase_							:      List[str]=920		,       UpperCAmelCase_							:      Any=1E-5		,       UpperCAmelCase_							:      Any=0.3		,       UpperCAmelCase_							:      Tuple="relu"		,       UpperCAmelCase_							:      Union[str, Any]=0.02		,       UpperCAmelCase_							:      Dict=0.3		,       UpperCAmelCase_							:      str=0.3		,       UpperCAmelCase_							:      Any=1		,       UpperCAmelCase_							:      Any=0		,       UpperCAmelCase_							:      int=2		,       UpperCAmelCase_							:      str=1		,       UpperCAmelCase_							:      Tuple=0.3		,       UpperCAmelCase_							:      Optional[Any]=1		,       UpperCAmelCase_							:      Optional[Any]=(7,)		,       UpperCAmelCase_							:      Optional[Any]=(3,)		,       UpperCAmelCase_							:      List[str]=80		,       UpperCAmelCase_							:      Tuple=1		,       UpperCAmelCase_							:      List[Any]=None		,       UpperCAmelCase_							:      List[str]="sum"		,       UpperCAmelCase_							:      Union[str, Any]=False		,       **UpperCAmelCase_							:      Any		,       )					->Dict:



														"""simple docstring"""



														super().__init__(**UpperCAmelCase_		,       pad_token_id=UpperCAmelCase_		,       bos_token_id=UpperCAmelCase_		,       eos_token_id=UpperCAmelCase_       )
														snake_case_           =		vocab_size
														snake_case_           =		hidden_size
														snake_case_           =		num_hidden_layers
														snake_case_           =		intermediate_size
														snake_case_           =		num_attention_heads
														snake_case_           =		attention_head_dim
														snake_case_           =		max_position_embeddings
														snake_case_           =		layer_norm_eps
														snake_case_           =		layerdrop
														snake_case_           =		hidden_act
														snake_case_           =		initializer_range
														snake_case_           =		hidden_dropout_prob
														snake_case_           =		attention_probs_dropout_prob
														snake_case_           =		pad_token_id
														snake_case_           =		bos_token_id
														snake_case_           =		eos_token_id
														snake_case_           =		conv_glu_dim
														snake_case_           =		conv_dropout
														snake_case_           =		num_conv_layers
														snake_case_           =		input_feat_per_channel
														snake_case_           =		input_channels
														snake_case_           =		conv_channels
														snake_case_           =		ctc_loss_reduction
														snake_case_           =		ctc_zero_infinity

														# prevents config testing fail with exporting to json
														snake_case_           =		list(UpperCAmelCase_       )
														snake_case_           =		list(UpperCAmelCase_       )

														if len(self.conv_kernel       ) != self.num_conv_layers:
																					raise ValueError(
																					    """Configuration for convolutional module is incorrect. """
																					    """It is required that `len(config.conv_kernel)` == `config.num_conv_layers` """
																					    F"""but is `len(config.conv_kernel) = {len(self.conv_kernel       )}`, """
																					    F"""`config.num_conv_layers = {self.num_conv_layers}`."""       )



