



"""simple docstring"""







from __future__ import annotations

import unittest

from transformers import EsmConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
     import numpy
     import tensorflow as tf

     from transformers.models.esm.modeling_tf_esm import (
         TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
         TFEsmForMaskedLM,
         TFEsmForSequenceClassification,
         TFEsmForTokenClassification,
         TFEsmModel,
     )







class 				UpperCamelCase__       :




      """simple docstring"""




      def __init__(				self    :				Union[str, Any]   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]   ,      ):
        lowerCAmelCase_       :    int								=			parent
        lowerCAmelCase_       :    int								=			1_3
        lowerCAmelCase_       :    Dict								=			7
        lowerCAmelCase_       :    List[Any]								=			True
        lowerCAmelCase_       :    int								=			True
        lowerCAmelCase_       :    List[str]								=			True
        lowerCAmelCase_       :    str								=			9_9
        lowerCAmelCase_       :    List[Any]								=			3_2
        lowerCAmelCase_       :    Tuple								=			2
        lowerCAmelCase_       :    Optional[int]								=			4
        lowerCAmelCase_       :    Any								=			3_7
        lowerCAmelCase_       :    Optional[int]								=			'gelu'
        lowerCAmelCase_       :    int								=			0.1
        lowerCAmelCase_       :    int								=			0.1
        lowerCAmelCase_       :    Optional[int]								=			5_1_2
        lowerCAmelCase_       :    Optional[Any]								=			1_6
        lowerCAmelCase_       :    int								=			2
        lowerCAmelCase_       :    Dict								=			0.02
        lowerCAmelCase_       :    Optional[int]								=			3
        lowerCAmelCase_       :    Tuple								=			4
        lowerCAmelCase_       :    Any								=			None



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        lowerCAmelCase_       :    List[Any]								=			ids_tensor([self.batch_size, self.seq_length]   ,      self.vocab_size	)

        lowerCAmelCase_       :    List[Any]								=			None
        if self.use_input_mask:
          lowerCAmelCase_       :    List[Any]								=			random_attention_mask([self.batch_size, self.seq_length]	)

        lowerCAmelCase_       :    Tuple								=			None
        lowerCAmelCase_       :    Tuple								=			None
        lowerCAmelCase_       :    List[str]								=			None
        if self.use_labels:
          lowerCAmelCase_       :    Tuple								=			ids_tensor([self.batch_size]   ,      self.type_sequence_label_size	)
          lowerCAmelCase_       :    Any								=			ids_tensor([self.batch_size, self.seq_length]   ,      self.num_labels	)
          lowerCAmelCase_       :    Optional[int]								=			ids_tensor([self.batch_size]   ,      self.num_choices	)

        lowerCAmelCase_       :    int								=			EsmConfig(
            vocab_size=self.vocab_size   ,      hidden_size=self.hidden_size   ,      num_hidden_layers=self.num_hidden_layers   ,      pad_token_id=1   ,      num_attention_heads=self.num_attention_heads   ,      intermediate_size=self.intermediate_size   ,      hidden_act=self.hidden_act   ,      hidden_dropout_prob=self.hidden_dropout_prob   ,      attention_probs_dropout_prob=self.attention_probs_dropout_prob   ,      max_position_embeddings=self.max_position_embeddings   ,      type_vocab_size=self.type_vocab_size   ,      initializer_range=self.initializer_range   ,      )

        return config, input_ids, input_mask, sequence_labels, token_labels, choice_labels



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[str]	):
        (
            (
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,			
        )       :    Union[str, Any]								=			self.prepare_config_and_inputs()

        lowerCAmelCase_       :    Union[str, Any]								=			True
        lowerCAmelCase_       :    Optional[Any]								=			floats_tensor([self.batch_size, self.seq_length, self.hidden_size]	)
        lowerCAmelCase_       :    Tuple								=			ids_tensor([self.batch_size, self.seq_length]   ,      vocab_size=2	)

        return (
            config,
            input_ids,
            input_mask,
            sequence_labels,
            token_labels,
            choice_labels,
            encoder_hidden_states,
            encoder_attention_mask,
        )



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple   ,      SCREAMING_SNAKE_CASE_    :				Dict   ,      SCREAMING_SNAKE_CASE_    :				List[str]   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      SCREAMING_SNAKE_CASE_    :				Tuple   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]	):
        lowerCAmelCase_       :    Optional[Any]								=			TFEsmModel(config=_lowerCAmelCase	)
        lowerCAmelCase_       :    List[str]								=			{'input_ids': input_ids, 'attention_mask': input_mask}
        lowerCAmelCase_       :    Any								=			model(_lowerCAmelCase	)

        lowerCAmelCase_       :    int								=			[input_ids, input_mask]
        lowerCAmelCase_       :    Optional[int]								=			model(_lowerCAmelCase	)

        lowerCAmelCase_       :    Optional[int]								=			model(_lowerCAmelCase	)

        self.parent.assertEqual(result.last_hidden_state.shape   ,      (self.batch_size, self.seq_length, self.hidden_size)	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				str   ,      SCREAMING_SNAKE_CASE_    :				List[str]   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]   ,      SCREAMING_SNAKE_CASE_    :				str   ,      SCREAMING_SNAKE_CASE_    :				List[str]   ,      SCREAMING_SNAKE_CASE_    :				int   ,      SCREAMING_SNAKE_CASE_    :				str   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      ):
        lowerCAmelCase_       :    Optional[Any]								=			True

        lowerCAmelCase_       :    Any								=			TFEsmModel(config=_lowerCAmelCase	)
        lowerCAmelCase_       :    List[str]								=			{
            'input_ids': input_ids,
            'attention_mask': input_mask,
            'encoder_hidden_states': encoder_hidden_states,
            'encoder_attention_mask': encoder_attention_mask,
        }
        lowerCAmelCase_       :    Optional[Any]								=			model(_lowerCAmelCase	)

        lowerCAmelCase_       :    Any								=			[input_ids, input_mask]
        lowerCAmelCase_       :    Optional[Any]								=			model(_lowerCAmelCase   ,      encoder_hidden_states=_lowerCAmelCase	)

        # Also check the case where encoder outputs are not passed
        lowerCAmelCase_       :    Optional[int]								=			model(_lowerCAmelCase   ,      attention_mask=_lowerCAmelCase	)

        self.parent.assertEqual(result.last_hidden_state.shape   ,      (self.batch_size, self.seq_length, self.hidden_size)	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]   ,      SCREAMING_SNAKE_CASE_    :				Union[str, Any]   ,      SCREAMING_SNAKE_CASE_    :				Dict   ,      SCREAMING_SNAKE_CASE_    :				str   ,      SCREAMING_SNAKE_CASE_    :				Dict   ,      SCREAMING_SNAKE_CASE_    :				Optional[int]	):
        lowerCAmelCase_       :    Dict								=			TFEsmForMaskedLM(config=_lowerCAmelCase	)
        lowerCAmelCase_       :    Tuple								=			model([input_ids, input_mask]	)
        self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.vocab_size)	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      SCREAMING_SNAKE_CASE_    :				Any   ,      SCREAMING_SNAKE_CASE_    :				str   ,      SCREAMING_SNAKE_CASE_    :				Tuple   ,      SCREAMING_SNAKE_CASE_    :				Dict	):
        lowerCAmelCase_       :    List[Any]								=			self.num_labels
        lowerCAmelCase_       :    Optional[int]								=			TFEsmForTokenClassification(config=_lowerCAmelCase	)
        lowerCAmelCase_       :    Optional[int]								=			{'input_ids': input_ids, 'attention_mask': input_mask}
        lowerCAmelCase_       :    Optional[Any]								=			model(_lowerCAmelCase	)
        self.parent.assertEqual(result.logits.shape   ,      (self.batch_size, self.seq_length, self.num_labels)	)





      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[str]	):
        lowerCAmelCase_       :    Union[str, Any]								=			self.prepare_config_and_inputs()
        (
            (
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,(
            lowerCAmelCase_			
        )						,			
        )       :    List[Any]								=			config_and_inputs
        lowerCAmelCase_       :    Dict								=			{'input_ids': input_ids, 'attention_mask': input_mask}
        return config, inputs_dict







@require_tf
class 				UpperCamelCase__       (     lowercase_, lowercase_, unittest.TestCase  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					(
          (
              TFEsmModel,
              TFEsmForMaskedLM,
              TFEsmForSequenceClassification,
              TFEsmForTokenClassification,
          )
          if is_tf_available()
          else ()
      )
      _SCREAMING_SNAKE_CASE      =					(
          {
              """feature-extraction""": TFEsmModel,
              """fill-mask""": TFEsmForMaskedLM,
              """text-classification""": TFEsmForSequenceClassification,
              """token-classification""": TFEsmForTokenClassification,
              """zero-shot""": TFEsmForSequenceClassification,
          }
          if is_tf_available()
          else {}
      )
      _SCREAMING_SNAKE_CASE      =					False
      _SCREAMING_SNAKE_CASE      =					False



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]	):
        lowerCAmelCase_       :    Tuple								=			TFEsmModelTester(self	)
        lowerCAmelCase_       :    Tuple								=			ConfigTester(self   ,      config_class=_lowerCAmelCase   ,      hidden_size=3_7	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        self.config_tester.run_common_tests()



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        lowerCAmelCase_       :    Optional[int]								=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_lowerCAmelCase	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):
        lowerCAmelCase_       :    Tuple								=			self.model_tester.prepare_config_and_inputs_for_decoder()
        self.model_tester.create_and_check_model_as_decoder(*_lowerCAmelCase	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Optional[int]	):
        lowerCAmelCase_       :    Any								=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*_lowerCAmelCase	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[str]	):
        lowerCAmelCase_       :    Optional[int]								=			self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_lowerCAmelCase	)



      @slow
      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple	):

        for model_name in TF_ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
          lowerCAmelCase_       :    Tuple								=			TFEsmModel.from_pretrained(_lowerCAmelCase	)
          self.assertIsNotNone(_lowerCAmelCase	)



      @unittest.skip('Protein models do not support embedding resizing.'	)
      def 					SCREAMING_SNAKE_CASE__			(				self    :				Union[str, Any]	):
        pass



      @unittest.skip('Protein models do not support embedding resizing.'	)
      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[str]	):
        pass





      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[str]	):
        lowerCAmelCase_						,lowerCAmelCase_       :    Optional[Any]								=			self.model_tester.prepare_config_and_inputs_for_common()

        for model_class in self.all_model_classes:
          lowerCAmelCase_       :    Any								=			model_class(_lowerCAmelCase	)
          assert isinstance(model.get_input_embeddings()   ,      tf.keras.layers.Layer	)
          if model_class is TFEsmForMaskedLM:
            # Output embedding test differs from the main test because they're a matrix, not a layer
            lowerCAmelCase_       :    Optional[Any]								=			model.get_bias()
            assert isinstance(_lowerCAmelCase   ,      _lowerCAmelCase	)
            for k, v in name.items():
              assert isinstance(_lowerCAmelCase   ,      tf.Variable	)
          else:
            lowerCAmelCase_       :    int								=			model.get_output_embeddings()
            assert x is None
            lowerCAmelCase_       :    Any								=			model.get_bias()
            assert name is None







@require_tf
class 				UpperCamelCase__       (     unittest.TestCase  ):




      """simple docstring"""




      @slow
      def 					SCREAMING_SNAKE_CASE__			(				self    :				str	):
        lowerCAmelCase_       :    Any								=			TFEsmForMaskedLM.from_pretrained('facebook/esm2_t6_8M_UR50D'	)

        lowerCAmelCase_       :    List[Any]								=			tf.constant([[0, 1, 2, 3, 4, 5]]	)
        lowerCAmelCase_       :    int								=			model(_lowerCAmelCase	)[0]
        lowerCAmelCase_       :    Tuple								=			[1, 6, 3_3]
        self.assertEqual(list(output.numpy().shape	)   ,      _lowerCAmelCase	)
        # compare the actual values for a slice.
        lowerCAmelCase_       :    Union[str, Any]								=			tf.constant(
            [
                [
                    [8.92_15_18, -10.58_98_14, -6.4_67_13_07],
                    [-6.3_96_71_56, -13.91_13_77, -1.1_21_19_15],
                    [-7.78_12_47, -13.95_15_57, -3.74_05_92],
                ]
            ]	)
        self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()   ,      expected_slice.numpy()   ,      atol=1E-2	)	)





      @slow
      def 					SCREAMING_SNAKE_CASE__			(				self    :				Union[str, Any]	):
        lowerCAmelCase_       :    Optional[int]								=			TFEsmModel.from_pretrained('facebook/esm2_t6_8M_UR50D'	)

        lowerCAmelCase_       :    Tuple								=			tf.constant([[0, 6, 4, 1_3, 5, 4, 1_6, 1_2, 1_1, 7, 2]]	)
        lowerCAmelCase_       :    Optional[Any]								=			model(_lowerCAmelCase	)[0]
        # compare the actual values for a slice.
        lowerCAmelCase_       :    str								=			tf.constant(
            [
                [
                    [0.14_44_30_92, 0.54_12_53_27, 0.3_24_77_39],
                    [0.30_34_04_84, 0.00_52_66_76, 0.31_07_77_22],
                    [0.32_27_80_43, -0.24_98_70_96, 0.3_41_46_28],
                ]
            ]	)
        self.assertTrue(numpy.allclose(output[:, :3, :3].numpy()   ,      expected_slice.numpy()   ,      atol=1E-4	)	)





"""simple docstring"""







from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    center_crop,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_DEFAULT_MEAN,
    IMAGENET_DEFAULT_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    is_batched,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


lowercase__		:    Tuple				   =     logging.get_logger(__name__)







class 				UpperCamelCase__       (     lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE      =					["""pixel_values"""]



      def __init__(				self    :				Any   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				Optional[Dict[str, int]] = None   ,      SCREAMING_SNAKE_CASE_    :				PILImageResampling = PILImageResampling.BICUBIC   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				Union[int, float] = 1 / 2_5_5   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int] = None   ,      SCREAMING_SNAKE_CASE_    :				bool = True   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      **SCREAMING_SNAKE_CASE_    :				int   ,      ):
        super().__init__(**SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Dict								=			size if size is not None else {'height': 2_2_4, 'width': 2_2_4}
        lowerCAmelCase_       :    List[Any]								=			get_size_dict(SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Tuple								=			crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
        lowerCAmelCase_       :    List[str]								=			get_size_dict(SCREAMING_SNAKE_CASE_   ,      default_to_square=SCREAMING_SNAKE_CASE_   ,      param_name='crop_size'	)

        lowerCAmelCase_       :    List[Any]								=			do_resize
        lowerCAmelCase_       :    Any								=			do_rescale
        lowerCAmelCase_       :    int								=			do_normalize
        lowerCAmelCase_       :    List[str]								=			do_center_crop
        lowerCAmelCase_       :    Dict								=			crop_size
        lowerCAmelCase_       :    Optional[Any]								=			size
        lowerCAmelCase_       :    Tuple								=			resample
        lowerCAmelCase_       :    Optional[int]								=			rescale_factor
        lowerCAmelCase_       :    Optional[Any]								=			image_mean if image_mean is not None else IMAGENET_DEFAULT_MEAN
        lowerCAmelCase_       :    List[str]								=			image_std if image_std is not None else IMAGENET_DEFAULT_STD



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Any   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int]   ,      SCREAMING_SNAKE_CASE_    :				PILImageResampling = PILImageResampling.BILINEAR   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				str   ,      ):
        lowerCAmelCase_       :    str								=			get_size_dict(SCREAMING_SNAKE_CASE_	)

        if "shortest_edge" in size:
          lowerCAmelCase_       :    Any								=			get_resize_output_image_size(SCREAMING_SNAKE_CASE_   ,      size=size['shortest_edge']   ,      default_to_square=SCREAMING_SNAKE_CASE_	)
          # size = get_resize_output_image_size(image, size["shortest_edge"], size["longest_edge"])
        elif "height" in size and "width" in size:
          lowerCAmelCase_       :    Union[str, Any]								=			(size['height'], size['width'])
        else:
          raise ValueError(F"Size must contain 'height' and 'width' keys or 'shortest_edge' key. Got {size.keys()}"	)
        return resize(SCREAMING_SNAKE_CASE_   ,      size=SCREAMING_SNAKE_CASE_   ,      resample=SCREAMING_SNAKE_CASE_   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				Optional[int]   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int]   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				int   ,      ):
        lowerCAmelCase_       :    Any								=			get_size_dict(SCREAMING_SNAKE_CASE_	)
        if "height" not in size or "width" not in size:
          raise ValueError(F"The `size` parameter must contain the keys (height, width). Got {size.keys()}"	)
        return center_crop(SCREAMING_SNAKE_CASE_   ,      size=(size['height'], size['width'])   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				int   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				float   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				Optional[int]	):
        return rescale(SCREAMING_SNAKE_CASE_   ,      scale=SCREAMING_SNAKE_CASE_   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)



      def 					SCREAMING_SNAKE_CASE__			(				self    :				List[Any]   ,      SCREAMING_SNAKE_CASE_    :				np.ndarray   ,      SCREAMING_SNAKE_CASE_    :				Union[float, List[float]]   ,      SCREAMING_SNAKE_CASE_    :				Union[float, List[float]]   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, ChannelDimension]] = None   ,      **SCREAMING_SNAKE_CASE_    :				str   ,      ):
        return normalize(SCREAMING_SNAKE_CASE_   ,      mean=SCREAMING_SNAKE_CASE_   ,      std=SCREAMING_SNAKE_CASE_   ,      data_format=SCREAMING_SNAKE_CASE_   ,      **SCREAMING_SNAKE_CASE_	)





      def 					SCREAMING_SNAKE_CASE__			(				self    :				Tuple   ,      SCREAMING_SNAKE_CASE_    :				ImageInput   ,      SCREAMING_SNAKE_CASE_    :				Optional[bool] = None   ,      SCREAMING_SNAKE_CASE_    :				Dict[str, int] = None   ,      SCREAMING_SNAKE_CASE_    :				PILImageResampling = None   ,      SCREAMING_SNAKE_CASE_    :				bool = None   ,      SCREAMING_SNAKE_CASE_    :				int = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[bool] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[float] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[bool] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[float, List[float]]] = None   ,      SCREAMING_SNAKE_CASE_    :				Optional[Union[str, TensorType]] = None   ,      SCREAMING_SNAKE_CASE_    :				Union[str, ChannelDimension] = ChannelDimension.FIRST   ,      **SCREAMING_SNAKE_CASE_    :				Optional[int]   ,      ):
        lowerCAmelCase_       :    Optional[int]								=			do_resize if do_resize is not None else self.do_resize
        lowerCAmelCase_       :    Optional[int]								=			do_rescale if do_rescale is not None else self.do_rescale
        lowerCAmelCase_       :    Optional[Any]								=			do_normalize if do_normalize is not None else self.do_normalize
        lowerCAmelCase_       :    Dict								=			do_center_crop if do_center_crop is not None else self.do_center_crop
        lowerCAmelCase_       :    Dict								=			crop_size if crop_size is not None else self.crop_size
        lowerCAmelCase_       :    Optional[Any]								=			get_size_dict(SCREAMING_SNAKE_CASE_   ,      param_name='crop_size'   ,      default_to_square=SCREAMING_SNAKE_CASE_	)
        lowerCAmelCase_       :    Union[str, Any]								=			resample if resample is not None else self.resample
        lowerCAmelCase_       :    Optional[Any]								=			rescale_factor if rescale_factor is not None else self.rescale_factor
        lowerCAmelCase_       :    str								=			image_mean if image_mean is not None else self.image_mean
        lowerCAmelCase_       :    List[str]								=			image_std if image_std is not None else self.image_std

        lowerCAmelCase_       :    Tuple								=			size if size is not None else self.size
        lowerCAmelCase_       :    str								=			get_size_dict(SCREAMING_SNAKE_CASE_	)

        if not is_batched(SCREAMING_SNAKE_CASE_	):
          lowerCAmelCase_       :    List[Any]								=			[images]

        if not valid_images(SCREAMING_SNAKE_CASE_	):
          raise ValueError(
              'Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, '
              'torch.Tensor, tf.Tensor or jax.ndarray.'	)

        if do_resize and size is None:
          raise ValueError('Size must be specified if do_resize is True.'	)

        if do_center_crop and crop_size is None:
          raise ValueError('Crop size must be specified if do_center_crop is True.'	)

        if do_rescale and rescale_factor is None:
          raise ValueError('Rescale factor must be specified if do_rescale is True.'	)

        # All transformations expect numpy arrays.
        lowerCAmelCase_       :    str								=			[to_numpy_array(SCREAMING_SNAKE_CASE_	) for image in images]

        if do_resize:
          lowerCAmelCase_       :    Any								=			[self.resize(image=SCREAMING_SNAKE_CASE_   ,      size=SCREAMING_SNAKE_CASE_   ,      resample=SCREAMING_SNAKE_CASE_	) for image in images]

        if do_center_crop:
          lowerCAmelCase_       :    Optional[int]								=			[self.center_crop(image=SCREAMING_SNAKE_CASE_   ,      size=SCREAMING_SNAKE_CASE_	) for image in images]

        if do_rescale:
          lowerCAmelCase_       :    Tuple								=			[self.rescale(image=SCREAMING_SNAKE_CASE_   ,      scale=SCREAMING_SNAKE_CASE_	) for image in images]

        if do_normalize:
          lowerCAmelCase_       :    str								=			[self.normalize(image=SCREAMING_SNAKE_CASE_   ,      mean=SCREAMING_SNAKE_CASE_   ,      std=SCREAMING_SNAKE_CASE_	) for image in images]

        lowerCAmelCase_       :    Any								=			[to_channel_dimension_format(SCREAMING_SNAKE_CASE_   ,      SCREAMING_SNAKE_CASE_	) for image in images]

        lowerCAmelCase_       :    Optional[Any]								=			{'pixel_values': images}
        return BatchFeature(data=SCREAMING_SNAKE_CASE_   ,      tensor_type=SCREAMING_SNAKE_CASE_	)





