




import unittest
from typing import Dict, List, Optional, Union

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 BridgeTowerImageProcessor

class  _lowerCamelCase						(			unittest.TestCase   ):

      """simple docstring"""

      def __init__(     self					: Any ,       snake_case					: List[Any] ,       snake_case					: bool = True ,       snake_case					: Dict[str, int] = None ,       snake_case					: int = 32 ,       snake_case					: bool = True ,       snake_case					: Union[int, float] = 1 / 255 ,       snake_case					: bool = True ,       snake_case					: bool = True ,       snake_case					: Optional[Union[float, List[float]]] = [0.48_14_54_66, 0.4_57_82_75, 0.40_82_10_73] ,       snake_case					: Optional[Union[float, List[float]]] = [0.26_86_29_54, 0.26_13_02_58, 0.27_57_77_11] ,       snake_case					: bool = True ,       snake_case					: Any=7 ,       snake_case					: str=30 ,       snake_case					: int=400 ,       snake_case					: Tuple=3 ,       ):
          __UpperCamelCase  		=						parent
          __UpperCamelCase  		=						do_resize
          __UpperCamelCase  		=						size if size is not None else {'''shortest_edge''': 288}
          __UpperCamelCase  		=						size_divisor
          __UpperCamelCase  		=						do_rescale
          __UpperCamelCase  		=						rescale_factor
          __UpperCamelCase  		=						do_normalize
          __UpperCamelCase  		=						do_center_crop
          __UpperCamelCase  		=						image_mean
          __UpperCamelCase  		=						image_std
          __UpperCamelCase  		=						do_pad
          __UpperCamelCase  		=						batch_size
          __UpperCamelCase  		=						num_channels
          __UpperCamelCase  		=						min_resolution
          __UpperCamelCase  		=						max_resolution







      def       snake_case	(     self					: Optional[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,
              "size_divisor": self.size_divisor,
          }







      def       snake_case	(     self					: int ,       snake_case					: Optional[int] ,       snake_case					: Any=False				):
          if not batched:
              __UpperCamelCase  		=						self.size['''shortest_edge''']
              __UpperCamelCase  		=						image_inputs[0]
              if isinstance(snake_case ,       Image.Image				):
                  __UpperCamelCase		,      __UpperCamelCase  		=						image.size
              else:
                  __UpperCamelCase		,      __UpperCamelCase  		=						image.shape[1], image.shape[2]
              __UpperCamelCase  		=						size / min(snake_case ,       snake_case				)
              if h < w:
                  __UpperCamelCase		,      __UpperCamelCase  		=						size, scale * w
              else:
                  __UpperCamelCase		,      __UpperCamelCase  		=						scale * h, size

              __UpperCamelCase  		=						int((1333 / 800) * size				)
              if max(snake_case ,       snake_case				) > max_size:
                  __UpperCamelCase  		=						max_size / max(snake_case ,       snake_case				)
                  __UpperCamelCase  		=						newh * scale
                  __UpperCamelCase  		=						neww * scale

              __UpperCamelCase		,      __UpperCamelCase  		=						int(newh + 0.5				), int(neww + 0.5				)
              __UpperCamelCase		,      __UpperCamelCase  		=						(
                  newh // self.size_divisor * self.size_divisor,
                  neww // self.size_divisor * self.size_divisor,
              )

          else:
              __UpperCamelCase  		=						[]
              for image in image_inputs:
                  __UpperCamelCase		,      __UpperCamelCase  		=						self.get_expected_values([image]				)
                  expected_values.append((expected_height, expected_width)				)
              __UpperCamelCase  		=						max(snake_case ,       key=lambda snake_case				: item[0]				)[0]
              __UpperCamelCase  		=						max(snake_case ,       key=lambda snake_case				: item[1]				)[1]

          return expected_height, expected_width







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

      """simple docstring"""

      lowerCAmelCase__			: Optional[Any]    =					BridgeTowerImageProcessor if is_vision_available() else None







      def       snake_case	(     self					: Optional[Any]				):
          __UpperCamelCase  		=						BridgeTowerImageProcessingTester(self				)







      @property
      def       snake_case	(     self					: Optional[int]				):
          return self.image_processor_tester.prepare_image_processor_dict()







      def       snake_case	(     self					: Union[str, Any]				):
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          self.assertTrue(hasattr(snake_case ,       '''image_mean'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''image_std'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''do_normalize'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''do_resize'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''size'''				)				)
          self.assertTrue(hasattr(snake_case ,       '''size_divisor'''				)				)







      def       snake_case	(     self					: Dict				):
          pass







      def       snake_case	(     self					: Dict				):
          # Initialize image processor
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          # create random PIL images
          __UpperCamelCase  		=						prepare_image_inputs(self.image_processor_tester ,       equal_resolution=snake_case				)
          for image in image_inputs:
              self.assertIsInstance(snake_case ,       Image.Image				)

          # Test not batched input
          __UpperCamelCase  		=						image_processing(image_inputs[0] ,       return_tensors='''pt'''				).pixel_values

          __UpperCamelCase		,      __UpperCamelCase  		=						self.image_processor_tester.get_expected_values(snake_case				)
          self.assertEqual(
              encoded_images.shape ,       (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,       )

          # Test batched
          __UpperCamelCase  		=						image_processing(snake_case ,       return_tensors='''pt'''				).pixel_values

          __UpperCamelCase		,      __UpperCamelCase  		=						self.image_processor_tester.get_expected_values(snake_case ,       batched=snake_case				)
          self.assertEqual(
              encoded_images.shape ,       (
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              ) ,       )







      def       snake_case	(     self					: Optional[int]				):
          # Initialize image processor
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          # create random numpy tensors
          __UpperCamelCase  		=						prepare_image_inputs(self.image_processor_tester ,       equal_resolution=snake_case ,       numpify=snake_case				)
          for image in image_inputs:
              self.assertIsInstance(snake_case ,       np.ndarray				)

          # Test not batched input
          __UpperCamelCase  		=						image_processing(image_inputs[0] ,       return_tensors='''pt'''				).pixel_values

          __UpperCamelCase		,      __UpperCamelCase  		=						self.image_processor_tester.get_expected_values(snake_case				)
          self.assertEqual(
              encoded_images.shape ,       (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,       )

          # Test batched
          __UpperCamelCase  		=						image_processing(snake_case ,       return_tensors='''pt'''				).pixel_values

          __UpperCamelCase		,      __UpperCamelCase  		=						self.image_processor_tester.get_expected_values(snake_case ,       batched=snake_case				)
          self.assertEqual(
              encoded_images.shape ,       (
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              ) ,       )







      def       snake_case	(     self					: List[Any]				):
          # Initialize image processor
          __UpperCamelCase  		=						self.image_processing_class(**self.image_processor_dict				)
          # create random PyTorch tensors
          __UpperCamelCase  		=						prepare_image_inputs(self.image_processor_tester ,       equal_resolution=snake_case ,       torchify=snake_case				)
          for image in image_inputs:
              self.assertIsInstance(snake_case ,       torch.Tensor				)

          # Test not batched input
          __UpperCamelCase  		=						image_processing(image_inputs[0] ,       return_tensors='''pt'''				).pixel_values

          __UpperCamelCase		,      __UpperCamelCase  		=						self.image_processor_tester.get_expected_values(snake_case				)
          self.assertEqual(
              encoded_images.shape ,       (1, self.image_processor_tester.num_channels, expected_height, expected_width) ,       )

          # Test batched
          __UpperCamelCase  		=						image_processing(snake_case ,       return_tensors='''pt'''				).pixel_values

          __UpperCamelCase		,      __UpperCamelCase  		=						self.image_processor_tester.get_expected_values(snake_case ,       batched=snake_case				)
          self.assertEqual(
              encoded_images.shape ,       (
                  self.image_processor_tester.batch_size,
                  self.image_processor_tester.num_channels,
                  expected_height,
                  expected_width,
              ) ,       )








from ....configuration_utils import PretrainedConfig
from ....utils import logging


a_   		=     logging.get_logger(__name__)

a_   		=     {
    "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  _lowerCamelCase						(			_SCREAMING_SNAKE_CASE   ):

      """simple docstring"""

      lowerCAmelCase__			: int    =					"mctct"







      def __init__(     self					: List[Any] ,       snake_case					: Optional[Any]=8065 ,       snake_case					: Optional[int]=1536 ,       snake_case					: Any=36 ,       snake_case					: List[str]=6144 ,       snake_case					: Dict=4 ,       snake_case					: str=384 ,       snake_case					: List[str]=920 ,       snake_case					: Dict=1E-5 ,       snake_case					: Union[str, Any]=0.3 ,       snake_case					: Optional[Any]="relu" ,       snake_case					: str=0.02 ,       snake_case					: Optional[int]=0.3 ,       snake_case					: int=0.3 ,       snake_case					: Any=1 ,       snake_case					: int=0 ,       snake_case					: Union[str, Any]=2 ,       snake_case					: List[Any]=1 ,       snake_case					: Dict=0.3 ,       snake_case					: int=1 ,       snake_case					: Optional[int]=(7,) ,       snake_case					: List[Any]=(3,) ,       snake_case					: Optional[int]=80 ,       snake_case					: List[str]=1 ,       snake_case					: int=None ,       snake_case					: List[str]="sum" ,       snake_case					: Tuple=False ,       **snake_case					: List[str] ,       ):
          super().__init__(**snake_case ,       pad_token_id=snake_case ,       bos_token_id=snake_case ,       eos_token_id=snake_case				)
          __UpperCamelCase  		=						vocab_size
          __UpperCamelCase  		=						hidden_size
          __UpperCamelCase  		=						num_hidden_layers
          __UpperCamelCase  		=						intermediate_size
          __UpperCamelCase  		=						num_attention_heads
          __UpperCamelCase  		=						attention_head_dim
          __UpperCamelCase  		=						max_position_embeddings
          __UpperCamelCase  		=						layer_norm_eps
          __UpperCamelCase  		=						layerdrop
          __UpperCamelCase  		=						hidden_act
          __UpperCamelCase  		=						initializer_range
          __UpperCamelCase  		=						hidden_dropout_prob
          __UpperCamelCase  		=						attention_probs_dropout_prob
          __UpperCamelCase  		=						pad_token_id
          __UpperCamelCase  		=						bos_token_id
          __UpperCamelCase  		=						eos_token_id
          __UpperCamelCase  		=						conv_glu_dim
          __UpperCamelCase  		=						conv_dropout
          __UpperCamelCase  		=						num_conv_layers
          __UpperCamelCase  		=						input_feat_per_channel
          __UpperCamelCase  		=						input_channels
          __UpperCamelCase  		=						conv_channels
          __UpperCamelCase  		=						ctc_loss_reduction
          __UpperCamelCase  		=						ctc_zero_infinity

          # prevents config testing fail with exporting to json
          __UpperCamelCase  		=						list(snake_case				)
          __UpperCamelCase  		=						list(snake_case				)

          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}`."				)






