






"""simple docstring"""







import inspect
import unittest

from transformers import SegformerConfig, is_torch_available, is_vision_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

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


if is_torch_available():
						import torch

						from transformers import (
						    MODEL_MAPPING,
						    SegformerForImageClassification,
						    SegformerForSemanticSegmentation,
						    SegformerModel,
						)
						from transformers.models.segformer.modeling_segformer import SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


if is_vision_available():
						from PIL import Image

						from transformers import SegformerImageProcessor



class  _lowerCamelCase			(__UpperCAmelCase     ):







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							self.config_class(**self.inputs_dict						)
					self.parent.assertTrue(hasattr(lowerCamelCase_			,					'hidden_sizes'						)						)
					self.parent.assertTrue(hasattr(lowerCamelCase_			,					'num_attention_heads'						)						)
					self.parent.assertTrue(hasattr(lowerCamelCase_			,					'num_encoder_blocks'						)						)



class  _lowerCamelCase			:







				def __init__( self    :       Tuple			,					lowerCamelCase_    :       Tuple			,					lowerCamelCase_    :       Union[str, Any]=1_3			,					lowerCamelCase_    :       List[str]=6_4			,					lowerCamelCase_    :       Tuple=3			,					lowerCamelCase_    :       int=4			,					lowerCamelCase_    :       Optional[Any]=[2, 2, 2, 2]			,					lowerCamelCase_    :       Any=[8, 4, 2, 1]			,					lowerCamelCase_    :       Optional[Any]=[1_6, 3_2, 6_4, 1_2_8]			,					lowerCamelCase_    :       Optional[Any]=[1, 4, 8, 1_6]			,					lowerCamelCase_    :       Any=[1, 2, 4, 8]			,					lowerCamelCase_    :       Tuple=True			,					lowerCamelCase_    :       List[Any]=True			,					lowerCamelCase_    :       List[Any]="gelu"			,					lowerCamelCase_    :       List[str]=0.1			,					lowerCamelCase_    :       str=0.1			,					lowerCamelCase_    :       str=0.02			,					lowerCamelCase_    :       Tuple=3			,					lowerCamelCase_    :       List[str]=None			,					):

					"""simple docstring"""






					_lowercase :    List[str]							=							parent
					_lowercase :    int							=							batch_size
					_lowercase :    Any							=							image_size
					_lowercase :    str							=							num_channels
					_lowercase :    Optional[Any]							=							num_encoder_blocks
					_lowercase :    Any							=							sr_ratios
					_lowercase :    Tuple							=							depths
					_lowercase :    int							=							hidden_sizes
					_lowercase :    Tuple							=							downsampling_rates
					_lowercase :    Optional[Any]							=							num_attention_heads
					_lowercase :    int							=							is_training
					_lowercase :    List[str]							=							use_labels
					_lowercase :    Any							=							hidden_act
					_lowercase :    Tuple							=							hidden_dropout_prob
					_lowercase :    Dict							=							attention_probs_dropout_prob
					_lowercase :    Tuple							=							initializer_range
					_lowercase :    Union[str, Any]							=							num_labels
					_lowercase :    Tuple							=							scope







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]						)

					_lowercase :    List[Any]							=							None
					if self.use_labels:
						_lowercase :    List[Any]							=							ids_tensor([self.batch_size, self.image_size, self.image_size]			,					self.num_labels						)

					_lowercase :    Dict							=							self.get_config()
					return config, pixel_values, labels







				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					return SegformerConfig(
					    image_size=self.image_size			,					num_channels=self.num_channels			,					num_encoder_blocks=self.num_encoder_blocks			,					depths=self.depths			,					hidden_sizes=self.hidden_sizes			,					num_attention_heads=self.num_attention_heads			,					hidden_act=self.hidden_act			,					hidden_dropout_prob=self.hidden_dropout_prob			,					attention_probs_dropout_prob=self.attention_probs_dropout_prob			,					initializer_range=self.initializer_range			,					)







				def 							__UpperCAmelCase					( self    :       Union[str, Any]			,					lowerCamelCase_    :       Any			,					lowerCamelCase_    :       List[Any]			,					lowerCamelCase_    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    List[str]							=							SegformerModel(config=lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()
					_lowercase :    List[str]							=							model(lowerCamelCase_						)
					_lowercase :    Union[str, Any]							=							self.image_size // (self.downsampling_rates[-1] * 2)
					self.parent.assertEqual(
					    result.last_hidden_state.shape			,					(self.batch_size, self.hidden_sizes[-1], expected_height, expected_width)						)







				def 							__UpperCAmelCase					( self    :       Dict			,					lowerCamelCase_    :       int			,					lowerCamelCase_    :       int			,					lowerCamelCase_    :       Dict						):

					"""simple docstring"""






					_lowercase :    List[Any]							=							self.num_labels
					_lowercase :    List[Any]							=							SegformerForSemanticSegmentation(lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()
					_lowercase :    Optional[Any]							=							model(lowerCamelCase_						)
					self.parent.assertEqual(
					    result.logits.shape			,					(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)						)
					_lowercase :    Tuple							=							model(lowerCamelCase_			,					labels=lowerCamelCase_						)
					self.parent.assertEqual(
					    result.logits.shape			,					(self.batch_size, self.num_labels, self.image_size // 4, self.image_size // 4)						)
					self.parent.assertGreater(result.loss			,					0.0						)







				def 							__UpperCAmelCase					( self    :       int			,					lowerCamelCase_    :       str			,					lowerCamelCase_    :       str			,					lowerCamelCase_    :       Any						):

					"""simple docstring"""






					_lowercase :    Tuple							=							1
					_lowercase :    Any							=							SegformerForSemanticSegmentation(config=lowerCamelCase_						)
					model.to(lowerCamelCase_						)
					model.eval()
					_lowercase :    Tuple							=							torch.randint(0			,					1			,					(self.batch_size, self.image_size, self.image_size)						).to(lowerCamelCase_						)
					_lowercase :    Any							=							model(lowerCamelCase_			,					labels=lowerCamelCase_						)
					self.parent.assertGreater(result.loss			,					0.0						)







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					_lowercase :    List[str]							=							self.prepare_config_and_inputs()
					_lowercase				,      _lowercase				,      _lowercase :    List[Any]							=							config_and_inputs
					_lowercase :    Any							=							{'pixel_values': pixel_values}
					return config, inputs_dict



@require_torch
class  _lowerCamelCase			(__UpperCAmelCase						,							__UpperCAmelCase						,							unittest.TestCase     ):
				_snake_case     =  (
				    (
				        SegformerModel,
				        SegformerForSemanticSegmentation,
				        SegformerForImageClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				_snake_case     =  (
				    {
				        "feature-extraction": SegformerModel,
				        "image-classification": SegformerForImageClassification,
				        "image-segmentation": SegformerForSemanticSegmentation,
				    }
				    if is_torch_available()
				    else {}
				)

				_snake_case     =  True
				_snake_case     =  False
				_snake_case     =  False
				_snake_case     =  False







				def 							__UpperCAmelCase					( self    :       List[Any]						):

					"""simple docstring"""






					_lowercase :    Union[str, Any]							=							SegformerModelTester(self						)
					_lowercase :    Dict							=							SegformerConfigTester(self			,					config_class=lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Any						):

					"""simple docstring"""






					self.config_tester.run_common_tests()







				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase :    Dict							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_model(*lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       List[str]						):

					"""simple docstring"""






					_lowercase :    List[Any]							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_binary_image_segmentation(*lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       str						):

					"""simple docstring"""






					_lowercase :    Dict							=							self.model_tester.prepare_config_and_inputs()
					self.model_tester.create_and_check_for_image_segmentation(*lowerCamelCase_						)







				@unittest.skip('SegFormer does not use inputs_embeds'						)
				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					pass







				@unittest.skip('SegFormer does not have get_input_embeddings method and get_output_embeddings methods'						)
				def 							__UpperCAmelCase					( self    :       List[Any]						):

					"""simple docstring"""






					pass







				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					_lowercase				,      _lowercase :    Union[str, Any]							=							self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						_lowercase :    str							=							model_class(lowerCamelCase_						)
						_lowercase :    List[str]							=							inspect.signature(model.forward						)
						# signature.parameters is an OrderedDict => so arg_names order is deterministic
						_lowercase :    Union[str, Any]							=							[*signature.parameters.keys()]

						_lowercase :    List[Any]							=							['pixel_values']
						self.assertListEqual(arg_names[:1]			,					lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Tuple						):

					"""simple docstring"""






					_lowercase				,      _lowercase :    Any							=							self.model_tester.prepare_config_and_inputs_for_common()
					_lowercase :    str							=							True

					for model_class in self.all_model_classes:
						_lowercase :    Optional[int]							=							True
						_lowercase :    Optional[int]							=							False
						_lowercase :    int							=							True
						_lowercase :    Union[str, Any]							=							model_class(lowerCamelCase_						)
						model.to(lowerCamelCase_						)
						model.eval()
						with torch.no_grad():
							_lowercase :    Any							=							model(**self._prepare_for_class(lowerCamelCase_			,					lowerCamelCase_						)						)
						_lowercase :    Tuple							=							outputs.attentions

						_lowercase :    int							=							sum(self.model_tester.depths						)
						self.assertEqual(len(lowerCamelCase_						)			,					lowerCamelCase_						)

						# check that output_attentions also work using config
						del inputs_dict["output_attentions"]
						_lowercase :    Optional[Any]							=							True
						_lowercase :    List[str]							=							model_class(lowerCamelCase_						)
						model.to(lowerCamelCase_						)
						model.eval()
						with torch.no_grad():
							_lowercase :    str							=							model(**self._prepare_for_class(lowerCamelCase_			,					lowerCamelCase_						)						)
						_lowercase :    Tuple							=							outputs.attentions

						self.assertEqual(len(lowerCamelCase_						)			,					lowerCamelCase_						)

						# verify the first attentions (first block, first layer)
						_lowercase :    Tuple							=							(self.model_tester.image_size // 4) ** 2
						_lowercase :    str							=							(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
						self.assertListEqual(
						    list(attentions[0].shape[-3:]						)			,					[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]			,					)

						# verify the last attentions (last block, last layer)
						_lowercase :    Optional[Any]							=							(self.model_tester.image_size // 3_2) ** 2
						_lowercase :    str							=							(self.model_tester.image_size // (3_2 * self.model_tester.sr_ratios[-1])) ** 2
						self.assertListEqual(
						    list(attentions[-1].shape[-3:]						)			,					[self.model_tester.num_attention_heads[-1], expected_seq_len, expected_reduced_seq_len]			,					)
						_lowercase :    str							=							len(lowerCamelCase_						)

						# Check attention is always last and order is fine
						_lowercase :    Tuple							=							True
						_lowercase :    Tuple							=							True
						_lowercase :    Tuple							=							model_class(lowerCamelCase_						)
						model.to(lowerCamelCase_						)
						model.eval()
						with torch.no_grad():
							_lowercase :    Any							=							model(**self._prepare_for_class(lowerCamelCase_			,					lowerCamelCase_						)						)

						self.assertEqual(out_len + 1			,					len(lowerCamelCase_						)						)

						_lowercase :    Tuple							=							outputs.attentions

						self.assertEqual(len(lowerCamelCase_						)			,					lowerCamelCase_						)
						# verify the first attentions (first block, first layer)
						_lowercase :    Any							=							(self.model_tester.image_size // 4) ** 2
						_lowercase :    str							=							(self.model_tester.image_size // (4 * self.model_tester.sr_ratios[0])) ** 2
						self.assertListEqual(
						    list(self_attentions[0].shape[-3:]						)			,					[self.model_tester.num_attention_heads[0], expected_seq_len, expected_reduced_seq_len]			,					)







				def 							__UpperCAmelCase					( self    :       Union[str, Any]						):

					"""simple docstring"""






					def check_hidden_states_output(lowerCamelCase_    :       Union[str, Any]			,					lowerCamelCase_    :       int			,					lowerCamelCase_    :       Dict						):
						_lowercase :    Dict							=							model_class(lowerCamelCase_						)
						model.to(lowerCamelCase_						)
						model.eval()

						with torch.no_grad():
							_lowercase :    int							=							model(**self._prepare_for_class(lowerCamelCase_			,					lowerCamelCase_						)						)

						_lowercase :    Tuple							=							outputs.hidden_states

						_lowercase :    List[Any]							=							self.model_tester.num_encoder_blocks
						self.assertEqual(len(lowerCamelCase_						)			,					lowerCamelCase_						)

						# verify the first hidden states (first block)
						self.assertListEqual(
						    list(hidden_states[0].shape[-3:]						)			,					[
						        self.model_tester.hidden_sizes[0],
						        self.model_tester.image_size // 4,
						        self.model_tester.image_size // 4,
						    ]			,					)

					_lowercase				,      _lowercase :    List[str]							=							self.model_tester.prepare_config_and_inputs_for_common()

					for model_class in self.all_model_classes:
						_lowercase :    Dict							=							True
						check_hidden_states_output(lowerCamelCase_			,					lowerCamelCase_			,					lowerCamelCase_						)

						# check that output_hidden_states also work using config
						del inputs_dict["output_hidden_states"]
						_lowercase :    int							=							True

						check_hidden_states_output(lowerCamelCase_			,					lowerCamelCase_			,					lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       List[str]						):

					"""simple docstring"""






					if not self.model_tester.is_training:
						return

					_lowercase				,      _lowercase :    List[Any]							=							self.model_tester.prepare_config_and_inputs_for_common()
					_lowercase :    Tuple							=							True

					for model_class in self.all_model_classes:
						if model_class in get_values(lowerCamelCase_						):
							continue

						_lowercase :    Optional[int]							=							model_class(lowerCamelCase_						)
						model.to(lowerCamelCase_						)
						model.train()
						_lowercase :    Dict							=							self._prepare_for_class(lowerCamelCase_			,					lowerCamelCase_			,					return_labels=lowerCamelCase_						)
						_lowercase :    Optional[int]							=							model(**lowerCamelCase_						).loss
						loss.backward()







				@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'						)
				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					pass







				@slow
				def 							__UpperCAmelCase					( self    :       int						):

					"""simple docstring"""






					for model_name in SEGFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
						_lowercase :    Optional[Any]							=							SegformerModel.from_pretrained(lowerCamelCase_						)
						self.assertIsNotNone(lowerCamelCase_						)



def      __lowerCAmelCase(		):






	"""simple docstring"""





	_lowercase :    Optional[int]							=							Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'			)
	return image







@require_torch
class  _lowerCamelCase			(unittest.TestCase     ):







				@slow
				def 							__UpperCAmelCase					( self    :       Optional[int]						):

					"""simple docstring"""






					_lowercase :    str							=							SegformerImageProcessor(
					    image_scale=(5_1_2, 5_1_2)			,					keep_ratio=lowerCamelCase_			,					align=lowerCamelCase_			,					do_random_crop=lowerCamelCase_						)
					_lowercase :    Dict							=							SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512'						).to(
					    lowerCamelCase_						)

					_lowercase :    List[Any]							=							prepare_img()
					_lowercase :    Any							=							image_processor(images=lowerCamelCase_			,					return_tensors='pt'						)
					_lowercase :    Any							=							encoded_inputs.pixel_values.to(lowerCamelCase_						)

					with torch.no_grad():
						_lowercase :    Tuple							=							model(lowerCamelCase_						)

					_lowercase :    List[Any]							=							torch.Size((1, model.config.num_labels, 1_2_8, 1_2_8)						)
					self.assertEqual(outputs.logits.shape			,					lowerCamelCase_						)

					_lowercase :    List[str]							=							torch.tensor(
					    [
					        [[-4.6310, -5.5232, -6.2356], [-5.1921, -6.1444, -6.5996], [-5.4424, -6.2790, -6.7574]],
					        [[-12.1391, -13.3122, -13.9554], [-12.8732, -13.9352, -14.3563], [-12.9438, -13.8226, -14.2513]],
					        [[-12.5134, -13.4686, -14.4915], [-12.8669, -14.4343, -14.7758], [-13.2523, -14.5819, -15.0694]],
					    ]						).to(lowerCamelCase_						)
					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]			,					lowerCamelCase_			,					atol=1E-4						)						)







				@slow
				def 							__UpperCAmelCase					( self    :       Optional[Any]						):

					"""simple docstring"""






					_lowercase :    Any							=							SegformerImageProcessor(
					    image_scale=(5_1_2, 5_1_2)			,					keep_ratio=lowerCamelCase_			,					align=lowerCamelCase_			,					do_random_crop=lowerCamelCase_						)
					_lowercase :    Dict							=							SegformerForSemanticSegmentation.from_pretrained(
					    'nvidia/segformer-b1-finetuned-cityscapes-1024-1024'						).to(lowerCamelCase_						)

					_lowercase :    int							=							prepare_img()
					_lowercase :    str							=							image_processor(images=lowerCamelCase_			,					return_tensors='pt'						)
					_lowercase :    Tuple							=							encoded_inputs.pixel_values.to(lowerCamelCase_						)

					with torch.no_grad():
						_lowercase :    List[str]							=							model(lowerCamelCase_						)

					_lowercase :    Any							=							torch.Size((1, model.config.num_labels, 1_2_8, 1_2_8)						)
					self.assertEqual(outputs.logits.shape			,					lowerCamelCase_						)

					_lowercase :    Any							=							torch.tensor(
					    [
					        [[-13.5748, -13.9111, -12.6500], [-14.3500, -15.3683, -14.2328], [-14.7532, -16.0424, -15.6087]],
					        [[-17.1651, -15.8725, -12.9653], [-17.2580, -17.3718, -14.8223], [-16.6058, -16.8783, -16.7452]],
					        [[-3.6456, -3.0209, -1.4203], [-3.0797, -3.1959, -2.0000], [-1.8757, -1.9217, -1.6997]],
					    ]						).to(lowerCamelCase_						)
					self.assertTrue(torch.allclose(outputs.logits[0, :3, :3, :3]			,					lowerCamelCase_			,					atol=1E-1						)						)







				@slow
				def 							__UpperCAmelCase					( self    :       Dict						):

					"""simple docstring"""






					_lowercase :    int							=							SegformerImageProcessor(
					    image_scale=(5_1_2, 5_1_2)			,					keep_ratio=lowerCamelCase_			,					align=lowerCamelCase_			,					do_random_crop=lowerCamelCase_						)
					_lowercase :    List[str]							=							SegformerForSemanticSegmentation.from_pretrained('nvidia/segformer-b0-finetuned-ade-512-512'						).to(
					    lowerCamelCase_						)

					_lowercase :    int							=							prepare_img()
					_lowercase :    int							=							image_processor(images=lowerCamelCase_			,					return_tensors='pt'						)
					_lowercase :    Optional[int]							=							encoded_inputs.pixel_values.to(lowerCamelCase_						)

					with torch.no_grad():
						_lowercase :    List[Any]							=							model(lowerCamelCase_						)

					_lowercase :    int							=							outputs.logits.detach().cpu()

					_lowercase :    Union[str, Any]							=							image_processor.post_process_semantic_segmentation(outputs=lowerCamelCase_			,					target_sizes=[(5_0_0, 3_0_0)]						)
					_lowercase :    List[Any]							=							torch.Size((5_0_0, 3_0_0)						)
					self.assertEqual(segmentation[0].shape			,					lowerCamelCase_						)

					_lowercase :    Optional[int]							=							image_processor.post_process_semantic_segmentation(outputs=lowerCamelCase_						)
					_lowercase :    Dict							=							torch.Size((1_2_8, 1_2_8)						)
					self.assertEqual(segmentation[0].shape			,					lowerCamelCase_						)




"""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_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging


SCREAMING_SNAKE_CASE									=						logging.get_logger(__name__)



class  _lowerCamelCase			(__lowerCamelCase     ):
				_snake_case     =  ["pixel_values"]







				def __init__( self    :       Optional[int]			,					lowerCamelCase_    :       bool = True			,					lowerCamelCase_    :       Optional[Dict[str, int]] = None			,					lowerCamelCase_    :       PILImageResampling = PILImageResampling.BILINEAR			,					lowerCamelCase_    :       bool = True			,					lowerCamelCase_    :       Dict[str, int] = None			,					lowerCamelCase_    :       bool = True			,					lowerCamelCase_    :       Union[int, float] = 1 / 2_5_5			,					lowerCamelCase_    :       bool = True			,					lowerCamelCase_    :       Optional[Union[float, List[float]]] = None			,					lowerCamelCase_    :       Optional[Union[float, List[float]]] = None			,					**lowerCamelCase_    :       int			,					):

					"""simple docstring"""






					super().__init__(**lowerCamelCase_						)
					_lowercase :    Optional[Any]							=							size if size is not None else {'shortest_edge': 2_5_6}
					_lowercase :    Optional[int]							=							get_size_dict(lowerCamelCase_			,					default_to_square=lowerCamelCase_						)
					_lowercase :    List[str]							=							crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
					_lowercase :    Any							=							get_size_dict(lowerCamelCase_						)
					_lowercase :    Optional[int]							=							do_resize
					_lowercase :    Optional[int]							=							size
					_lowercase :    Union[str, Any]							=							resample
					_lowercase :    Optional[Any]							=							do_center_crop
					_lowercase :    Union[str, Any]							=							crop_size
					_lowercase :    Any							=							do_rescale
					_lowercase :    Tuple							=							rescale_factor
					_lowercase :    Optional[int]							=							do_normalize
					_lowercase :    int							=							image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
					_lowercase :    Any							=							image_std if image_std is not None else IMAGENET_STANDARD_STD







				def 							__UpperCAmelCase					( self    :       List[Any]			,					lowerCamelCase_    :       np.ndarray			,					lowerCamelCase_    :       Dict[str, int]			,					lowerCamelCase_    :       PILImageResampling = PILImageResampling.BICUBIC			,					lowerCamelCase_    :       Optional[Union[str, ChannelDimension]] = None			,					**lowerCamelCase_    :       Tuple			,					):

					"""simple docstring"""






					_lowercase :    Optional[Any]							=							get_size_dict(lowerCamelCase_			,					default_to_square=lowerCamelCase_						)
					if "shortest_edge" not in size:
						raise ValueError(F'''The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'''						)
					_lowercase :    Dict							=							get_resize_output_image_size(lowerCamelCase_			,					size=size['shortest_edge']			,					default_to_square=lowerCamelCase_						)
					return resize(lowerCamelCase_			,					size=lowerCamelCase_			,					resample=lowerCamelCase_			,					data_format=lowerCamelCase_			,					**lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Dict			,					lowerCamelCase_    :       np.ndarray			,					lowerCamelCase_    :       Dict[str, int]			,					lowerCamelCase_    :       Optional[Union[str, ChannelDimension]] = None			,					**lowerCamelCase_    :       str			,					):

					"""simple docstring"""






					_lowercase :    Tuple							=							get_size_dict(lowerCamelCase_						)
					return center_crop(lowerCamelCase_			,					size=(size['height'], size['width'])			,					data_format=lowerCamelCase_			,					**lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Any			,					lowerCamelCase_    :       np.ndarray			,					lowerCamelCase_    :       float			,					lowerCamelCase_    :       Optional[Union[str, ChannelDimension]] = None			,					**lowerCamelCase_    :       Optional[Any]						):

					"""simple docstring"""






					return rescale(lowerCamelCase_			,					scale=lowerCamelCase_			,					data_format=lowerCamelCase_			,					**lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       List[Any]			,					lowerCamelCase_    :       np.ndarray			,					lowerCamelCase_    :       Union[float, List[float]]			,					lowerCamelCase_    :       Union[float, List[float]]			,					lowerCamelCase_    :       Optional[Union[str, ChannelDimension]] = None			,					**lowerCamelCase_    :       List[Any]			,					):

					"""simple docstring"""






					return normalize(lowerCamelCase_			,					mean=lowerCamelCase_			,					std=lowerCamelCase_			,					data_format=lowerCamelCase_			,					**lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       List[Any]			,					lowerCamelCase_    :       ImageInput			,					lowerCamelCase_    :       Optional[bool] = None			,					lowerCamelCase_    :       Dict[str, int] = None			,					lowerCamelCase_    :       PILImageResampling = None			,					lowerCamelCase_    :       bool = None			,					lowerCamelCase_    :       Dict[str, int] = None			,					lowerCamelCase_    :       Optional[bool] = None			,					lowerCamelCase_    :       Optional[float] = None			,					lowerCamelCase_    :       Optional[bool] = None			,					lowerCamelCase_    :       Optional[Union[float, List[float]]] = None			,					lowerCamelCase_    :       Optional[Union[float, List[float]]] = None			,					lowerCamelCase_    :       Optional[Union[str, TensorType]] = None			,					lowerCamelCase_    :       Union[str, ChannelDimension] = ChannelDimension.FIRST			,					**lowerCamelCase_    :       int			,					):

					"""simple docstring"""






					_lowercase :    Optional[Any]							=							do_resize if do_resize is not None else self.do_resize
					_lowercase :    List[Any]							=							size if size is not None else self.size
					_lowercase :    Union[str, Any]							=							get_size_dict(lowerCamelCase_			,					default_to_square=lowerCamelCase_						)
					_lowercase :    Any							=							resample if resample is not None else self.resample
					_lowercase :    Tuple							=							do_center_crop if do_center_crop is not None else self.do_center_crop
					_lowercase :    List[Any]							=							crop_size if crop_size is not None else self.crop_size
					_lowercase :    Tuple							=							get_size_dict(lowerCamelCase_						)
					_lowercase :    List[Any]							=							do_rescale if do_rescale is not None else self.do_rescale
					_lowercase :    int							=							rescale_factor if rescale_factor is not None else self.rescale_factor
					_lowercase :    int							=							do_normalize if do_normalize is not None else self.do_normalize
					_lowercase :    str							=							image_mean if image_mean is not None else self.image_mean
					_lowercase :    List[Any]							=							image_std if image_std is not None else self.image_std

					_lowercase :    Union[str, Any]							=							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:
						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.'						)

					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.
					_lowercase :    Optional[Any]							=							[to_numpy_array(lowerCamelCase_						) for image in images]

					if do_resize:
						_lowercase :    Optional[Any]							=							[self.resize(image=lowerCamelCase_			,					size=lowerCamelCase_			,					resample=lowerCamelCase_						) for image in images]

					if do_center_crop:
						_lowercase :    List[Any]							=							[self.center_crop(image=lowerCamelCase_			,					size=lowerCamelCase_						) for image in images]

					if do_rescale:
						_lowercase :    str							=							[self.rescale(image=lowerCamelCase_			,					scale=lowerCamelCase_						) for image in images]

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

					_lowercase :    int							=							[to_channel_dimension_format(lowerCamelCase_			,					lowerCamelCase_						) for image in images]

					_lowercase :    Tuple							=							{'pixel_values': images}
					return BatchFeature(data=lowerCamelCase_			,					tensor_type=lowerCamelCase_						)



