





'''simple docstring'''


import collections
import inspect
import unittest

from transformers import DinatConfig
from transformers.testing_utils import require_natten, require_torch, require_vision, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_vision_available

from ...test_backbone_common import BackboneTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
       import torch
       from torch import nn

       from transformers import DinatBackbone, DinatForImageClassification, DinatModel
       from transformers.models.dinat.modeling_dinat import DINAT_PRETRAINED_MODEL_ARCHIVE_LIST

if is_vision_available():
       from PIL import Image

       from transformers import AutoImageProcessor

class 				lowerCAmelCase_						:




 def __init__(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase=13     ,       _lowerCAmelCase=64     ,       _lowerCAmelCase=4     ,       _lowerCAmelCase=3     ,       _lowerCAmelCase=16     ,       _lowerCAmelCase=[1, 2, 1]     ,       _lowerCAmelCase=[2, 4, 8]     ,       _lowerCAmelCase=3     ,       _lowerCAmelCase=[[3], [1, 2], [1]]     ,       _lowerCAmelCase=2.0     ,       _lowerCAmelCase=True     ,       _lowerCAmelCase=0.0     ,       _lowerCAmelCase=0.0     ,       _lowerCAmelCase=0.1     ,       _lowerCAmelCase="gelu"     ,       _lowerCAmelCase=True     ,       _lowerCAmelCase=0.02     ,       _lowerCAmelCase=1E-5     ,       _lowerCAmelCase=True     ,       _lowerCAmelCase=None     ,       _lowerCAmelCase=True     ,       _lowerCAmelCase=10     ,       _lowerCAmelCase=["stage1", "stage2"]     ,       _lowerCAmelCase=[1, 2]     ,       )      ->							Optional[int]:
     _lowerCAmelCase		     = parent
     _lowerCAmelCase		     = batch_size
     _lowerCAmelCase		     = image_size
     _lowerCAmelCase		     = patch_size
     _lowerCAmelCase		     = num_channels
     _lowerCAmelCase		     = embed_dim
     _lowerCAmelCase		     = depths
     _lowerCAmelCase		     = num_heads
     _lowerCAmelCase		     = kernel_size
     _lowerCAmelCase		     = dilations
     _lowerCAmelCase		     = mlp_ratio
     _lowerCAmelCase		     = qkv_bias
     _lowerCAmelCase		     = hidden_dropout_prob
     _lowerCAmelCase		     = attention_probs_dropout_prob
     _lowerCAmelCase		     = drop_path_rate
     _lowerCAmelCase		     = hidden_act
     _lowerCAmelCase		     = patch_norm
     _lowerCAmelCase		     = layer_norm_eps
     _lowerCAmelCase		     = initializer_range
     _lowerCAmelCase		     = is_training
     _lowerCAmelCase		     = scope
     _lowerCAmelCase		     = use_labels
     _lowerCAmelCase		     = num_labels
     _lowerCAmelCase		     = out_features
     _lowerCAmelCase		     = out_indices




 def 							_snake_case				(		self						)      ->							Optional[Any]:
     _lowerCAmelCase		     = floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

     _lowerCAmelCase		     = None
     if self.use_labels:
         _lowerCAmelCase		     = ids_tensor([self.batch_size]     ,       self.num_labels						)

     _lowerCAmelCase		     = self.get_config()

     return config, pixel_values, labels




 def 							_snake_case				(		self						)      ->							int:
     return DinatConfig(
         num_labels=self.num_labels     ,       image_size=self.image_size     ,       patch_size=self.patch_size     ,       num_channels=self.num_channels     ,       embed_dim=self.embed_dim     ,       depths=self.depths     ,       num_heads=self.num_heads     ,       kernel_size=self.kernel_size     ,       dilations=self.dilations     ,       mlp_ratio=self.mlp_ratio     ,       qkv_bias=self.qkv_bias     ,       hidden_dropout_prob=self.hidden_dropout_prob     ,       attention_probs_dropout_prob=self.attention_probs_dropout_prob     ,       drop_path_rate=self.drop_path_rate     ,       hidden_act=self.hidden_act     ,       patch_norm=self.patch_norm     ,       layer_norm_eps=self.layer_norm_eps     ,       initializer_range=self.initializer_range     ,       out_features=self.out_features     ,       out_indices=self.out_indices     ,       )




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						)      ->							Optional[int]:
     _lowerCAmelCase		     = DinatModel(config=_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.eval()
     _lowerCAmelCase		     = model(_lowerCAmelCase						)

     _lowerCAmelCase		     = _lowerCAmelCase		     = (config.image_size // config.patch_size) // (2 ** (len(config.depths						) - 1))
     _lowerCAmelCase		     = int(config.embed_dim * 2 ** (len(config.depths						) - 1)						)

     self.parent.assertEqual(
         result.last_hidden_state.shape     ,       (self.batch_size, expected_height, expected_width, expected_dim)						)




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						)      ->							str:
     _lowerCAmelCase		     = DinatForImageClassification(_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.eval()
     _lowerCAmelCase		     = model(_lowerCAmelCase     ,       labels=_lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, self.num_labels)						)

     # test greyscale images
     _lowerCAmelCase		     = 1
     _lowerCAmelCase		     = DinatForImageClassification(_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.eval()

     _lowerCAmelCase		     = floats_tensor([self.batch_size, 1, self.image_size, self.image_size]						)
     _lowerCAmelCase		     = model(_lowerCAmelCase						)
     self.parent.assertEqual(result.logits.shape     ,       (self.batch_size, self.num_labels)						)




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						)      ->							int:
     _lowerCAmelCase		     = DinatBackbone(config=_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.eval()
     _lowerCAmelCase		     = model(_lowerCAmelCase						)

     # verify hidden states
     self.parent.assertEqual(len(result.feature_maps						)     ,       len(config.out_features						)						)
     self.parent.assertListEqual(list(result.feature_maps[0].shape						)     ,       [self.batch_size, model.channels[0], 16, 16]						)

     # verify channels
     self.parent.assertEqual(len(model.channels						)     ,       len(config.out_features						)						)

     # verify backbone works with out_features=None
     _lowerCAmelCase		     = None
     _lowerCAmelCase		     = DinatBackbone(config=_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.eval()
     _lowerCAmelCase		     = model(_lowerCAmelCase						)

     # verify feature maps
     self.parent.assertEqual(len(result.feature_maps						)     ,       1						)
     self.parent.assertListEqual(list(result.feature_maps[0].shape						)     ,       [self.batch_size, model.channels[-1], 4, 4]						)

     # verify channels
     self.parent.assertEqual(len(model.channels						)     ,       1						)





 def 							_snake_case				(		self						)      ->							Union[str, Any]:
     _lowerCAmelCase		     = self.prepare_config_and_inputs()
     _lowerCAmelCase     ,     _lowerCAmelCase     ,     _lowerCAmelCase		     = config_and_inputs
     _lowerCAmelCase		     = {"pixel_values": pixel_values}
     return config, inputs_dict







@require_natten
@require_torch
class 				lowerCAmelCase_						(						__magic_name__  ,__magic_name__  ,unittest.TestCase						):
 __lowerCamelCase  :							Optional[int]    					=   (
     (
         DinatModel,
         DinatForImageClassification,
         DinatBackbone,
     )
     if is_torch_available()
     else ()
 )
 __lowerCamelCase  :							Optional[Any]    					=   (
     {"feature-extraction": DinatModel, "image-classification": DinatForImageClassification}
     if is_torch_available()
     else {}
 )
 __lowerCamelCase  :							Any    					=   False

 __lowerCamelCase  :							Optional[Any]    					=   False
 __lowerCamelCase  :							Union[str, Any]    					=   False
 __lowerCamelCase  :							List[Any]    					=   False
 __lowerCamelCase  :							Any    					=   False




 def 							_snake_case				(		self						)      ->							List[Any]:
     _lowerCAmelCase		     = DinatModelTester(self						)
     _lowerCAmelCase		     = ConfigTester(self     ,       config_class=_lowerCAmelCase     ,       embed_dim=37						)




 def 							_snake_case				(		self						)      ->							Tuple:
     self.create_and_test_config_common_properties()
     self.config_tester.create_and_test_config_to_json_string()
     self.config_tester.create_and_test_config_to_json_file()
     self.config_tester.create_and_test_config_from_and_save_pretrained()
     self.config_tester.create_and_test_config_with_num_labels()
     self.config_tester.check_config_can_be_init_without_params()
     self.config_tester.check_config_arguments_init()




 def 							_snake_case				(		self						)      ->							Dict:
     return




 def 							_snake_case				(		self						)      ->							Tuple:
     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_model(*_lowerCAmelCase						)




 def 							_snake_case				(		self						)      ->							Optional[int]:
     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_for_image_classification(*_lowerCAmelCase						)




 def 							_snake_case				(		self						)      ->							Tuple:
     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs()
     self.model_tester.create_and_check_backbone(*_lowerCAmelCase						)




 @unittest.skip(reason="Dinat does not use inputs_embeds"						)
 def 							_snake_case				(		self						)      ->							Union[str, Any]:
     pass




 @unittest.skip(reason="Dinat does not use feedforward chunking"						)
 def 							_snake_case				(		self						)      ->							Dict:
     pass




 def 							_snake_case				(		self						)      ->							Union[str, Any]:
     _lowerCAmelCase     ,     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         _lowerCAmelCase		     = model_class(_lowerCAmelCase						)
         self.assertIsInstance(model.get_input_embeddings()     ,       (nn.Module)						)
         _lowerCAmelCase		     = model.get_output_embeddings()
         self.assertTrue(x is None or isinstance(_lowerCAmelCase     ,       nn.Linear						)						)




 def 							_snake_case				(		self						)      ->							Any:
     _lowerCAmelCase     ,     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs_for_common()

     for model_class in self.all_model_classes:
         _lowerCAmelCase		     = model_class(_lowerCAmelCase						)
         _lowerCAmelCase		     = inspect.signature(model.forward						)
         # signature.parameters is an OrderedDict => so arg_names order is deterministic
         _lowerCAmelCase		     = [*signature.parameters.keys()]

         _lowerCAmelCase		     = ["pixel_values"]
         self.assertListEqual(arg_names[:1]     ,       _lowerCAmelCase						)




 def 							_snake_case				(		self						)      ->							Dict:
     self.skipTest("Dinat's attention operation is handled entirely by NATTEN."						)




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						)      ->							int:
     _lowerCAmelCase		     = model_class(_lowerCAmelCase						)
     model.to(_lowerCAmelCase						)
     model.eval()

     with torch.no_grad():
         _lowerCAmelCase		     = model(**self._prepare_for_class(_lowerCAmelCase     ,       _lowerCAmelCase						)						)

     _lowerCAmelCase		     = outputs.hidden_states

     _lowerCAmelCase		     = getattr(
         self.model_tester     ,       "expected_num_hidden_layers"     ,       len(self.model_tester.depths						) + 1						)
     self.assertEqual(len(_lowerCAmelCase						)     ,       _lowerCAmelCase						)

     # Dinat has a different seq_length
     _lowerCAmelCase		     = (
         config.patch_size
         if isinstance(config.patch_size     ,       collections.abc.Iterable						)
         else (config.patch_size, config.patch_size)
     )

     _lowerCAmelCase		     = image_size[0] // patch_size[0]
     _lowerCAmelCase		     = image_size[1] // patch_size[1]

     self.assertListEqual(
         list(hidden_states[0].shape[-3:]						)     ,       [height, width, self.model_tester.embed_dim]     ,       )

     if model_class.__name__ != "DinatBackbone":
         _lowerCAmelCase		     = outputs.reshaped_hidden_states
         self.assertEqual(len(_lowerCAmelCase						)     ,       _lowerCAmelCase						)

         _lowerCAmelCase     ,     _lowerCAmelCase     ,     _lowerCAmelCase     ,     _lowerCAmelCase		     = reshaped_hidden_states[0].shape
         _lowerCAmelCase		     = (
             reshaped_hidden_states[0].view(_lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						).permute(0     ,       2     ,       3     ,       1						)
         )
         self.assertListEqual(
             list(reshaped_hidden_states.shape[-3:]						)     ,       [height, width, self.model_tester.embed_dim]     ,       )




 def 							_snake_case				(		self						)      ->							List[Any]:
     _lowerCAmelCase     ,     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs_for_common()

     _lowerCAmelCase		     = (
         self.model_tester.image_size
         if isinstance(self.model_tester.image_size     ,       collections.abc.Iterable						)
         else (self.model_tester.image_size, self.model_tester.image_size)
     )

     for model_class in self.all_model_classes:
         _lowerCAmelCase		     = True
         self.check_hidden_states_output(_lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						)

         # check that output_hidden_states also work using config
         del inputs_dict["output_hidden_states"]
         _lowerCAmelCase		     = True

         self.check_hidden_states_output(_lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase						)




 @slow
 def 							_snake_case				(		self						)      ->							List[Any]:
     for model_name in DINAT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
         _lowerCAmelCase		     = DinatModel.from_pretrained(_lowerCAmelCase						)
         self.assertIsNotNone(_lowerCAmelCase						)





 def 							_snake_case				(		self						)      ->							List[Any]:
     _lowerCAmelCase     ,     _lowerCAmelCase		     = self.model_tester.prepare_config_and_inputs_for_common()

     _lowerCAmelCase		     = _config_zero_init(_lowerCAmelCase						)
     for model_class in self.all_model_classes:
         _lowerCAmelCase		     = model_class(config=_lowerCAmelCase						)
         for name, param in model.named_parameters():
             if "embeddings" not in name and param.requires_grad:
                 self.assertIn(
                     ((param.data.mean() * 1E9).round() / 1E9).item()     ,       [0.0, 1.0]     ,       msg=f'''Parameter {name} of model {model_class} seems not properly initialized'''     ,       )







@require_natten
@require_vision
@require_torch
class 				lowerCAmelCase_						(						unittest.TestCase						):




 @cached_property
 def 							_snake_case				(		self						)      ->							List[str]:
     return AutoImageProcessor.from_pretrained("shi-labs/dinat-mini-in1k-224"						) if is_vision_available() else None





 @slow
 def 							_snake_case				(		self						)      ->							Any:
     _lowerCAmelCase		     = DinatForImageClassification.from_pretrained("shi-labs/dinat-mini-in1k-224"						).to(_lowerCAmelCase						)
     _lowerCAmelCase		     = self.default_image_processor

     _lowerCAmelCase		     = Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"						)
     _lowerCAmelCase		     = image_processor(images=_lowerCAmelCase     ,       return_tensors="pt"						).to(_lowerCAmelCase						)

     # forward pass
     with torch.no_grad():
         _lowerCAmelCase		     = model(**_lowerCAmelCase						)

     # verify the logits
     _lowerCAmelCase		     = torch.Size((1, 1000)						)
     self.assertEqual(outputs.logits.shape     ,       _lowerCAmelCase						)
     _lowerCAmelCase		     = torch.tensor([-0.1545, -0.7667, 0.4642]						).to(_lowerCAmelCase						)
     self.assertTrue(torch.allclose(outputs.logits[0, :3]     ,       _lowerCAmelCase     ,       atol=1E-4						)						)







@require_torch
@require_natten
class 				lowerCAmelCase_						(						unittest.TestCase  ,__magic_name__						):
 __lowerCamelCase  :							Optional[int]    					=   (DinatBackbone,) if is_torch_available() else ()
 __lowerCamelCase  :							Any    					=   DinatConfig




 def 							_snake_case				(		self						)      ->							Dict:
     _lowerCAmelCase		     = DinatModelTester(self						)









'''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, normalize, rescale, resize, to_channel_dimension_format
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


if is_vision_available():
       import PIL


_SCREAMING_SNAKE_CASE			=							logging.get_logger(__name__)

class 				lowerCAmelCase_						(						__magic_name__						):
 __lowerCamelCase  :							Optional[int]    					=   ["pixel_values"]




 def __init__(		self     ,       _lowerCAmelCase = True     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = PIL.Image.NEAREST     ,       _lowerCAmelCase = False     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = 1 / 255     ,       _lowerCAmelCase = False     ,       _lowerCAmelCase = True     ,       _lowerCAmelCase = True     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = True     ,       **_lowerCAmelCase     ,       )      ->							None:
     super().__init__(**_lowerCAmelCase						)
     _lowerCAmelCase		     = size if size is not None else {"height": 346, "width": 346}
     _lowerCAmelCase		     = get_size_dict(_lowerCAmelCase						)
     _lowerCAmelCase		     = crop_size if crop_size is not None else {"height": 289, "width": 289}
     _lowerCAmelCase		     = get_size_dict(_lowerCAmelCase     ,       param_name="crop_size"						)

     _lowerCAmelCase		     = do_resize
     _lowerCAmelCase		     = size
     _lowerCAmelCase		     = resample
     _lowerCAmelCase		     = do_center_crop
     _lowerCAmelCase		     = crop_size
     _lowerCAmelCase		     = do_rescale
     _lowerCAmelCase		     = rescale_factor
     _lowerCAmelCase		     = rescale_offset
     _lowerCAmelCase		     = do_normalize
     _lowerCAmelCase		     = image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
     _lowerCAmelCase		     = image_std if image_std is not None else IMAGENET_STANDARD_STD
     _lowerCAmelCase		     = include_top




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase = PIL.Image.NEAREST     ,       _lowerCAmelCase = None     ,       **_lowerCAmelCase     ,       )      ->							np.ndarray:
     _lowerCAmelCase		     = get_size_dict(_lowerCAmelCase						)
     if "height" not in size or "width" not in size:
         raise ValueError(f'''The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'''						)
     return resize(
         _lowerCAmelCase     ,       size=(size["height"], size["width"])     ,       resample=_lowerCAmelCase     ,       data_format=_lowerCAmelCase     ,       **_lowerCAmelCase						)




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase = None     ,       **_lowerCAmelCase     ,       )      ->							np.ndarray:
     _lowerCAmelCase		     = get_size_dict(_lowerCAmelCase						)
     if "height" not in size or "width" not in size:
         raise ValueError(f'''The size dictionary must have keys \'height\' and \'width\'. Got {size.keys()}'''						)
     return center_crop(_lowerCAmelCase     ,       size=(size["height"], size["width"])     ,       data_format=_lowerCAmelCase     ,       **_lowerCAmelCase						)




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase = True     ,       _lowerCAmelCase = None     ,       **_lowerCAmelCase     ,       )      ->							List[str]:
     if offset:
         _lowerCAmelCase		     = (image - 127.5) * scale
         if data_format is not None:
             _lowerCAmelCase		     = to_channel_dimension_format(_lowerCAmelCase     ,       _lowerCAmelCase						)
         _lowerCAmelCase		     = rescaled_image.astype(np.floataa						)
     else:
         _lowerCAmelCase		     = rescale(_lowerCAmelCase     ,       scale=_lowerCAmelCase     ,       data_format=_lowerCAmelCase     ,       **_lowerCAmelCase						)
     return rescaled_image




 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase     ,       _lowerCAmelCase = None     ,       **_lowerCAmelCase     ,       )      ->							np.ndarray:
     return normalize(_lowerCAmelCase     ,       mean=_lowerCAmelCase     ,       std=_lowerCAmelCase     ,       data_format=_lowerCAmelCase     ,       **_lowerCAmelCase						)





 def 							_snake_case				(		self     ,       _lowerCAmelCase     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase=None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = None     ,       _lowerCAmelCase = ChannelDimension.FIRST     ,       **_lowerCAmelCase     ,       )      ->							PIL.Image.Image:
     _lowerCAmelCase		     = do_resize if do_resize is not None else self.do_resize
     _lowerCAmelCase		     = resample if resample is not None else self.resample
     _lowerCAmelCase		     = do_center_crop if do_center_crop is not None else self.do_center_crop
     _lowerCAmelCase		     = do_rescale if do_rescale is not None else self.do_rescale
     _lowerCAmelCase		     = rescale_factor if rescale_factor is not None else self.rescale_factor
     _lowerCAmelCase		     = rescale_offset if rescale_offset is not None else self.rescale_offset
     _lowerCAmelCase		     = do_normalize if do_normalize is not None else self.do_normalize
     _lowerCAmelCase		     = image_mean if image_mean is not None else self.image_mean
     _lowerCAmelCase		     = image_std if image_std is not None else self.image_std
     _lowerCAmelCase		     = include_top if include_top is not None else self.include_top

     _lowerCAmelCase		     = size if size is not None else self.size
     _lowerCAmelCase		     = get_size_dict(_lowerCAmelCase						)
     _lowerCAmelCase		     = crop_size if crop_size is not None else self.crop_size
     _lowerCAmelCase		     = get_size_dict(_lowerCAmelCase     ,       param_name="crop_size"						)

     _lowerCAmelCase		     = make_list_of_images(_lowerCAmelCase						)

     if not valid_images(_lowerCAmelCase						):
         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 or resample is None:
         raise ValueError("Size and resample 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."						)

     if do_normalize and (image_mean is None or image_std is None):
         raise ValueError("Image mean and std must be specified if do_normalize is True."						)

     # All transformations expect numpy arrays.
     _lowerCAmelCase		     = [to_numpy_array(_lowerCAmelCase						) for image in images]

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

     if do_center_crop:
         _lowerCAmelCase		     = [self.center_crop(image=_lowerCAmelCase     ,       size=_lowerCAmelCase						) for image in images]

     if do_rescale:
         _lowerCAmelCase		     = [self.rescale(image=_lowerCAmelCase     ,       scale=_lowerCAmelCase     ,       offset=_lowerCAmelCase						) for image in images]

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

     if include_top:
         _lowerCAmelCase		     = [self.normalize(image=_lowerCAmelCase     ,       mean=[0, 0, 0]     ,       std=_lowerCAmelCase						) for image in images]

     _lowerCAmelCase		     = [to_channel_dimension_format(_lowerCAmelCase     ,       _lowerCAmelCase						) for image in images]

     _lowerCAmelCase		     = {"pixel_values": images}
     return BatchFeature(data=_lowerCAmelCase     ,       tensor_type=_lowerCAmelCase						)


