



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 ViTImageProcessor
class  _A		(  unittest.TestCase):

  def __init__(				self ,					_SCREAMING_SNAKE_CASE ,					_SCREAMING_SNAKE_CASE=13 ,					_SCREAMING_SNAKE_CASE=3 ,					_SCREAMING_SNAKE_CASE=224 ,					_SCREAMING_SNAKE_CASE=30 ,					_SCREAMING_SNAKE_CASE=400 ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=None ,					_SCREAMING_SNAKE_CASE=True ,					_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5] ,					_SCREAMING_SNAKE_CASE=[0.5, 0.5, 0.5] ,					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Tuple           =     size if size is not None else {'height': 18, 'width': 18}
        SCREAMING_SNAKE_CASE_				:  str           =     parent
        SCREAMING_SNAKE_CASE_				:  str           =     batch_size
        SCREAMING_SNAKE_CASE_				:  Dict           =     num_channels
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     image_size
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     min_resolution
        SCREAMING_SNAKE_CASE_				:  List[str]           =     max_resolution
        SCREAMING_SNAKE_CASE_				:  Optional[Any]           =     do_resize
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     size
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     do_normalize
        SCREAMING_SNAKE_CASE_				:  int           =     image_mean
        SCREAMING_SNAKE_CASE_				:  int           =     image_std



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return {
            "image_mean": self.image_mean,
            "image_std": self.image_std,
            "do_normalize": self.do_normalize,
            "do_resize": self.do_resize,
            "size": self.size,
        }

@require_torch
@require_vision
class  _A		(  lowercase_   ,     unittest.TestCase):
  SCREAMING_SNAKE_CASE    :      List[str]       =  ViTImageProcessor if is_vision_available() else None

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Dict           =     EfficientFormerImageProcessorTester(self					)

  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return self.image_proc_tester.prepare_image_processor_dict()

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     self.image_processing_class(**self.image_processor_dict					)
        self.assertTrue(hasattr(UpperCamelCase__ ,					'image_mean'					)					)
        self.assertTrue(hasattr(UpperCamelCase__ ,					'image_std'					)					)
        self.assertTrue(hasattr(UpperCamelCase__ ,					'do_normalize'					)					)
        self.assertTrue(hasattr(UpperCamelCase__ ,					'do_resize'					)					)
        self.assertTrue(hasattr(UpperCamelCase__ ,					'size'					)					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        pass

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  List[str]           =     self.image_processing_class(**self.image_processor_dict					)
        # create random PIL images
        SCREAMING_SNAKE_CASE_				:  Tuple           =     prepare_image_inputs(self.image_proc_tester ,					equal_resolution=UpperCamelCase__					)
        for image in image_inputs:
              self.assertIsInstance(UpperCamelCase__ ,					Image.Image					)

        # Test not batched input
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     image_processor(image_inputs[0] ,					return_tensors='pt'					).pixel_values
        self.assertEqual(
            encoded_images.shape ,					(
                1,
                self.image_proc_tester.num_channels,
                self.image_proc_tester.size['height'],
                self.image_proc_tester.size['width'],
            ) ,					)

        # Test batched
        SCREAMING_SNAKE_CASE_				:  Union[str, Any]           =     image_processor(UpperCamelCase__ ,					return_tensors='pt'					).pixel_values
        self.assertEqual(
            encoded_images.shape ,					(
                self.image_proc_tester.batch_size,
                self.image_proc_tester.num_channels,
                self.image_proc_tester.size['height'],
                self.image_proc_tester.size['width'],
            ) ,					)

  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     self.image_processing_class(**self.image_processor_dict					)
        # create random numpy tensors
        SCREAMING_SNAKE_CASE_				:  List[str]           =     prepare_image_inputs(self.image_proc_tester ,					equal_resolution=UpperCamelCase__ ,					numpify=UpperCamelCase__					)
        for image in image_inputs:
              self.assertIsInstance(UpperCamelCase__ ,					np.ndarray					)

        # Test not batched input
        SCREAMING_SNAKE_CASE_				:  Optional[int]           =     image_processor(image_inputs[0] ,					return_tensors='pt'					).pixel_values
        self.assertEqual(
            encoded_images.shape ,					(
                1,
                self.image_proc_tester.num_channels,
                self.image_proc_tester.size['height'],
                self.image_proc_tester.size['width'],
            ) ,					)

        # Test batched
        SCREAMING_SNAKE_CASE_				:  Any           =     image_processor(UpperCamelCase__ ,					return_tensors='pt'					).pixel_values
        self.assertEqual(
            encoded_images.shape ,					(
                self.image_proc_tester.batch_size,
                self.image_proc_tester.num_channels,
                self.image_proc_tester.size['height'],
                self.image_proc_tester.size['width'],
            ) ,					)



  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        SCREAMING_SNAKE_CASE_				:  Any           =     self.image_processing_class(**self.image_processor_dict					)
        # create random PyTorch tensors
        SCREAMING_SNAKE_CASE_				:  Dict           =     prepare_image_inputs(self.image_proc_tester ,					equal_resolution=UpperCamelCase__ ,					torchify=UpperCamelCase__					)
        for image in image_inputs:
              self.assertIsInstance(UpperCamelCase__ ,					torch.Tensor					)

        # Test not batched input
        SCREAMING_SNAKE_CASE_				:  str           =     image_processor(image_inputs[0] ,					return_tensors='pt'					).pixel_values
        self.assertEqual(
            encoded_images.shape ,					(
                1,
                self.image_proc_tester.num_channels,
                self.image_proc_tester.size['height'],
                self.image_proc_tester.size['width'],
            ) ,					)

        # Test batched
        SCREAMING_SNAKE_CASE_				:  Any           =     image_processor(UpperCamelCase__ ,					return_tensors='pt'					).pixel_values
        self.assertEqual(
            encoded_images.shape ,					(
                self.image_proc_tester.batch_size,
                self.image_proc_tester.num_channels,
                self.image_proc_tester.size['height'],
                self.image_proc_tester.size['width'],
            ) ,					)









import copy
from dataclasses import dataclass, field
from typing import ClassVar, Dict

from ..features import Audio, Features, Value
from .base import TaskTemplate
@dataclass(frozen=__magic_name__)
class  _A		(  __magic_name__):
  SCREAMING_SNAKE_CASE    :      str       =  field(default='''automatic-speech-recognition'''   ,     metadata={'''include_in_asdict_even_if_is_default''': True})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''audio''': Audio()})
  SCREAMING_SNAKE_CASE    :      ClassVar[Features]       =  Features({'''transcription''': Value('''string''')})
  SCREAMING_SNAKE_CASE    :      str       =  "audio"
  SCREAMING_SNAKE_CASE    :      str       =  "transcription"

  def  UpperCAmelCase    (				self ,					_SCREAMING_SNAKE_CASE					):





        """simple docstring"""







        if self.audio_column not in features:
              raise ValueError(f"Column {self.audio_column} is not present in features."					)
        if not isinstance(features[self.audio_column] ,					_SCREAMING_SNAKE_CASE					):
              raise ValueError(f"Column {self.audio_column} is not an Audio type."					)
        SCREAMING_SNAKE_CASE_				:  int           =     copy.deepcopy(self					)
        SCREAMING_SNAKE_CASE_				:  int           =     self.input_schema.copy()
        SCREAMING_SNAKE_CASE_				:  List[Any]           =     features[self.audio_column]
        SCREAMING_SNAKE_CASE_				:  List[str]           =     input_schema
        return task_template



  @property
  def  UpperCAmelCase    (				self					):





        """simple docstring"""







        return {self.audio_column: "audio", self.transcription_column: "transcription"}






