

"""simple docstring"""





import torch
from torch import nn
from torch.nn import CrossEntropyLoss, MSELoss

from transformers.file_utils import add_start_docstrings, add_start_docstrings_to_model_forward
from transformers.models.bert.modeling_bert import (
    BERT_INPUTS_DOCSTRING,
    BERT_START_DOCSTRING,
    BertEmbeddings,
    BertLayer,
    BertPooler,
    BertPreTrainedModel,
)

def   __SCREAMING_SNAKE_CASE  (      A_ ):
	lowerCAmelCase__	:						List[str]  				=	torch.exp(A_ )
	lowerCAmelCase__	:						Tuple  				=	torch.sum(A_						,     dim=1 )  # sum of exp(x_i)
	lowerCAmelCase__	:						Any  				=	torch.sum(x * exp_x						,     dim=1 )  # sum of x_i * exp(x_i)
	return torch.log(A_ ) - B / A







class 				SCREAMING_SNAKE_CASE					(		nn.Module       ):






					"""simple docstring"""



					def __init__(       self			:				str   ,lowercase_			:				Optional[int]		):
						super().__init__()
						lowerCAmelCase__	:						Tuple  				=	config.output_attentions
						lowerCAmelCase__	:						List[str]  				=	config.output_hidden_states
						lowerCAmelCase__	:						Union[str, Any]  				=	nn.ModuleList([BertLayer(lowercase_		) for _ in range(config.num_hidden_layers		)]		)
						lowerCAmelCase__	:						int  				=	nn.ModuleList([BertHighway(lowercase_		) for _ in range(config.num_hidden_layers		)]		)

						lowerCAmelCase__	:						Any  				=	[-1 for _ in range(config.num_hidden_layers		)]







					def        __lowerCAmelCase (       self			:				List[str]   ,lowercase_			:				List[Any]		):
						if (type(lowercase_		) is float) or (type(lowercase_		) is int):
							for i in range(len(self.early_exit_entropy		)		):
								lowerCAmelCase__	:						List[str]  				=	x
						else:
							lowerCAmelCase__	:						Optional[Any]  				=	x







					def        __lowerCAmelCase (       self			:				Any   ,lowercase_			:				int		):
						lowerCAmelCase__	:						Any  				=	pooler.state_dict()
						for highway in self.highway:
							for name, param in highway.pooler.state_dict().items():
								param.copy_(loaded_model[name]		)







					def        __lowerCAmelCase (       self			:				str   ,lowercase_			:				Optional[int]   ,lowercase_			:				Union[str, Any]=None   ,lowercase_			:				Any=None   ,lowercase_			:				Union[str, Any]=None   ,lowercase_			:				Optional[Any]=None   ,):
						lowerCAmelCase__	:						Tuple  				=	()
						lowerCAmelCase__	:						Optional[int]  				=	()
						lowerCAmelCase__	:						str  				=	()
						for i, layer_module in enumerate(self.layer		):
							if self.output_hidden_states:
								lowerCAmelCase__	:						Dict  				=	all_hidden_states + (hidden_states,)

							lowerCAmelCase__	:						str  				=	layer_module(
							    lowercase_   ,lowercase_   ,head_mask[i]   ,lowercase_   ,lowercase_		)
							lowerCAmelCase__	:						int  				=	layer_outputs[0]

							if self.output_attentions:
								lowerCAmelCase__	:						Optional[int]  				=	all_attentions + (layer_outputs[1],)

							lowerCAmelCase__	:						str  				=	(hidden_states,)
							if self.output_hidden_states:
								lowerCAmelCase__	:						Tuple  				=	current_outputs + (all_hidden_states,)
							if self.output_attentions:
								lowerCAmelCase__	:						Any  				=	current_outputs + (all_attentions,)

							lowerCAmelCase__	:						Dict  				=	self.highway[i](lowercase_		)
							# logits, pooled_output

							if not self.training:
								lowerCAmelCase__	:						str  				=	highway_exit[0]
								lowerCAmelCase__	:						str  				=	entropy(lowercase_		)
								lowerCAmelCase__	:						str  				=	highway_exit + (highway_entropy,)  # logits, hidden_states(?), entropy
								lowerCAmelCase__	:						Dict  				=	all_highway_exits + (highway_exit,)

								if highway_entropy < self.early_exit_entropy[i]:
									lowerCAmelCase__	:						str  				=	(highway_logits,) + current_outputs[1:] + (all_highway_exits,)
									raise HighwayException(lowercase_   ,i + 1		)
							else:
								lowerCAmelCase__	:						Union[str, Any]  				=	all_highway_exits + (highway_exit,)

        # Add last layer
						if self.output_hidden_states:
							lowerCAmelCase__	:						List[Any]  				=	all_hidden_states + (hidden_states,)

						lowerCAmelCase__	:						Dict  				=	(hidden_states,)
						if self.output_hidden_states:
							lowerCAmelCase__	:						List[Any]  				=	outputs + (all_hidden_states,)
						if self.output_attentions:
							lowerCAmelCase__	:						List[Any]  				=	outputs + (all_attentions,)

						lowerCAmelCase__	:						List[Any]  				=	outputs + (all_highway_exits,)
						return outputs  # last-layer hidden state, (all hidden states), (all attentions), all highway exits







@add_start_docstrings(
    "The Bert Model transformer with early exiting (DeeBERT). "    ,							a_    ,							)
class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					def __init__(       self			:				List[str]   ,lowercase_			:				Tuple		):
						super().__init__(lowercase_		)
						lowerCAmelCase__	:						List[Any]  				=	config

						lowerCAmelCase__	:						int  				=	BertEmbeddings(lowercase_		)
						lowerCAmelCase__	:						Union[str, Any]  				=	DeeBertEncoder(lowercase_		)
						lowerCAmelCase__	:						Union[str, Any]  				=	BertPooler(lowercase_		)

						self.init_weights()







					def        __lowerCAmelCase (       self			:				str		):
						self.encoder.init_highway_pooler(self.pooler		)







					def        __lowerCAmelCase (       self			:				Tuple		):
						return self.embeddings.word_embeddings







					def        __lowerCAmelCase (       self			:				List[str]   ,lowercase_			:				Optional[Any]		):
						lowerCAmelCase__	:						Any  				=	value







					def        __lowerCAmelCase (       self			:				str   ,lowercase_			:				Tuple		):
						for layer, heads in heads_to_prune.items():
							self.encoder.layer[layer].attention.prune_heads(lowercase_		)







					@add_start_docstrings_to_model_forward(lowercase_		)
					def        __lowerCAmelCase (       self			:				Tuple   ,lowercase_			:				int=None   ,lowercase_			:				int=None   ,lowercase_			:				Tuple=None   ,lowercase_			:				Dict=None   ,lowercase_			:				Dict=None   ,lowercase_			:				Optional[int]=None   ,lowercase_			:				Optional[int]=None   ,lowercase_			:				str=None   ,):
						if input_ids is not None and inputs_embeds is not None:
							raise ValueError('''You cannot specify both input_ids and inputs_embeds at the same time'''		)
						elif input_ids is not None:
							lowerCAmelCase__	:						List[str]  				=	input_ids.size()
						elif inputs_embeds is not None:
							lowerCAmelCase__	:						Optional[Any]  				=	inputs_embeds.size()[:-1]
						else:
							raise ValueError('''You have to specify either input_ids or inputs_embeds'''		)

						lowerCAmelCase__	:						Union[str, Any]  				=	input_ids.device if input_ids is not None else inputs_embeds.device

						if attention_mask is None:
							lowerCAmelCase__	:						Union[str, Any]  				=	torch.ones(lowercase_   ,device=lowercase_		)
						if encoder_attention_mask is None:
							lowerCAmelCase__	:						Tuple  				=	torch.ones(lowercase_   ,device=lowercase_		)
						if token_type_ids is None:
							lowerCAmelCase__	:						int  				=	torch.zeros(lowercase_   ,dtype=torch.long   ,device=lowercase_		)

						# We can provide a self-attention mask of dimensions [batch_size, from_seq_length, to_seq_length]
						# ourselves in which case we just need to make it broadcastable to all heads.
						lowerCAmelCase__	:						torch.Tensor  				=	self.get_extended_attention_mask(lowercase_   ,lowercase_   ,lowercase_		)

						# If a 2D ou 3D attention mask is provided for the cross-attention
						# we need to make broadcastable to [batch_size, num_heads, seq_length, seq_length]
						if encoder_attention_mask.dim() == 3:
							lowerCAmelCase__	:						Union[str, Any]  				=	encoder_attention_mask[:, None, :, :]
						if encoder_attention_mask.dim() == 2:
							lowerCAmelCase__	:						Dict  				=	encoder_attention_mask[:, None, None, :]

						lowerCAmelCase__	:						List[Any]  				=	encoder_extended_attention_mask.to(
						    dtype=next(self.parameters()		).dtype		)  # fp16 compatibility
						lowerCAmelCase__	:						Any  				=	(1.0 - encoder_extended_attention_mask) * -1_0000.0

						# Prepare head mask if needed
						# 1.0 in head_mask indicate we keep the head
						# attention_probs has shape bsz x n_heads x N x N
						# input head_mask has shape [num_heads] or [num_hidden_layers x num_heads]
						# and head_mask is converted to shape [num_hidden_layers x batch x num_heads x seq_length x seq_length]
						lowerCAmelCase__	:						Tuple  				=	self.get_head_mask(lowercase_   ,self.config.num_hidden_layers		)

						lowerCAmelCase__	:						Any  				=	self.embeddings(
						    input_ids=lowercase_   ,position_ids=lowercase_   ,token_type_ids=lowercase_   ,inputs_embeds=lowercase_		)
						lowerCAmelCase__	:						Tuple  				=	self.encoder(
						    lowercase_   ,attention_mask=lowercase_   ,head_mask=lowercase_   ,encoder_hidden_states=lowercase_   ,encoder_attention_mask=lowercase_   ,)
						lowerCAmelCase__	:						str  				=	encoder_outputs[0]
						lowerCAmelCase__	:						Dict  				=	self.pooler(lowercase_		)

						lowerCAmelCase__	:						Any  				=	(
						    sequence_output,
						    pooled_output,
						) + encoder_outputs[
						    1:
						]  # add hidden_states and attentions if they are here
						return outputs  # sequence_output, pooled_output, (hidden_states), (attentions), highway exits







class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					def __init__(       self			:				Tuple   ,lowercase_			:				Any   ,lowercase_			:				int		):
						lowerCAmelCase__	:						List[Any]  				=	message
						lowerCAmelCase__	:						Any  				=	exit_layer  # start from 1!







class 				SCREAMING_SNAKE_CASE					(		nn.Module       ):






					"""simple docstring"""



					def __init__(       self			:				Optional[Any]   ,lowercase_			:				Any		):
						super().__init__()
						lowerCAmelCase__	:						Optional[int]  				=	BertPooler(lowercase_		)
						lowerCAmelCase__	:						Optional[int]  				=	nn.Dropout(config.hidden_dropout_prob		)
						lowerCAmelCase__	:						str  				=	nn.Linear(config.hidden_size   ,config.num_labels		)







					def        __lowerCAmelCase (       self			:				Tuple   ,lowercase_			:				int		):
						# Pooler
						lowerCAmelCase__	:						Tuple  				=	encoder_outputs[0]
						lowerCAmelCase__	:						Optional[int]  				=	self.pooler(lowercase_		)
						# "return" pooler_output

						# BertModel
						lowerCAmelCase__	:						List[str]  				=	(pooler_input, pooler_output) + encoder_outputs[1:]
						# "return" bmodel_output

						# Dropout and classification
						lowerCAmelCase__	:						List[str]  				=	bmodel_output[1]

						lowerCAmelCase__	:						str  				=	self.dropout(lowercase_		)
						lowerCAmelCase__	:						List[str]  				=	self.classifier(lowercase_		)

						return logits, pooled_output







@add_start_docstrings(
    "Bert Model (with early exiting - DeeBERT) with a classifier on top,\n    also takes care of multi-layer training. "    ,							a_    ,							)
class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					def __init__(       self			:				Optional[Any]   ,lowercase_			:				str		):
						super().__init__(lowercase_		)
						lowerCAmelCase__	:						Union[str, Any]  				=	config.num_labels
						lowerCAmelCase__	:						Optional[int]  				=	config.num_hidden_layers

						lowerCAmelCase__	:						Any  				=	DeeBertModel(lowercase_		)
						lowerCAmelCase__	:						str  				=	nn.Dropout(config.hidden_dropout_prob		)
						lowerCAmelCase__	:						Union[str, Any]  				=	nn.Linear(config.hidden_size   ,self.config.num_labels		)

						self.init_weights()







					@add_start_docstrings_to_model_forward(lowercase_		)
					def        __lowerCAmelCase (       self			:				Any   ,lowercase_			:				Tuple=None   ,lowercase_			:				Optional[int]=None   ,lowercase_			:				List[Any]=None   ,lowercase_			:				int=None   ,lowercase_			:				Tuple=None   ,lowercase_			:				Optional[Any]=None   ,lowercase_			:				Optional[int]=None   ,lowercase_			:				Dict=-1   ,lowercase_			:				Dict=False   ,):
						lowerCAmelCase__	:						Tuple  				=	self.num_layers
						try:
							lowerCAmelCase__	:						Dict  				=	self.bert(
							    lowercase_   ,attention_mask=lowercase_   ,token_type_ids=lowercase_   ,position_ids=lowercase_   ,head_mask=lowercase_   ,inputs_embeds=lowercase_   ,)
							# sequence_output, pooled_output, (hidden_states), (attentions), highway exits

							lowerCAmelCase__	:						Any  				=	outputs[1]

							lowerCAmelCase__	:						str  				=	self.dropout(lowercase_		)
							lowerCAmelCase__	:						List[Any]  				=	self.classifier(lowercase_		)
							lowerCAmelCase__	:						Dict  				=	(logits,) + outputs[2:]  # add hidden states and attention if they are here
						except HighwayException as e:
							lowerCAmelCase__	:						Dict  				=	e.message
							lowerCAmelCase__	:						Dict  				=	e.exit_layer
							lowerCAmelCase__	:						int  				=	outputs[0]

						if not self.training:
							lowerCAmelCase__	:						Union[str, Any]  				=	entropy(lowercase_		)
							lowerCAmelCase__	:						str  				=	[]
							lowerCAmelCase__	:						Optional[int]  				=	[]
						if labels is not None:
							if self.num_labels == 1:
								#  We are doing regression
								lowerCAmelCase__	:						Optional[Any]  				=	MSELoss()
								lowerCAmelCase__	:						str  				=	loss_fct(logits.view(-1		)   ,labels.view(-1		)		)
							else:
								lowerCAmelCase__	:						int  				=	CrossEntropyLoss()
								lowerCAmelCase__	:						Union[str, Any]  				=	loss_fct(logits.view(-1   ,self.num_labels		)   ,labels.view(-1		)		)

							# work with highway exits
							lowerCAmelCase__	:						Union[str, Any]  				=	[]
							for highway_exit in outputs[-1]:
								lowerCAmelCase__	:						List[Any]  				=	highway_exit[0]
								if not self.training:
									highway_logits_all.append(lowercase_		)
									highway_entropy.append(highway_exit[2]		)
								if self.num_labels == 1:
									#  We are doing regression
									lowerCAmelCase__	:						int  				=	MSELoss()
									lowerCAmelCase__	:						str  				=	loss_fct(highway_logits.view(-1		)   ,labels.view(-1		)		)
								else:
									lowerCAmelCase__	:						Optional[int]  				=	CrossEntropyLoss()
									lowerCAmelCase__	:						Optional[int]  				=	loss_fct(highway_logits.view(-1   ,self.num_labels		)   ,labels.view(-1		)		)
								highway_losses.append(lowercase_		)

							if train_highway:
								lowerCAmelCase__	:						Optional[int]  				=	(sum(highway_losses[:-1]		),) + outputs
								# exclude the final highway, of course
							else:
								lowerCAmelCase__	:						Any  				=	(loss,) + outputs
						if not self.training:
							lowerCAmelCase__	:						Union[str, Any]  				=	outputs + ((original_entropy, highway_entropy), exit_layer)
							if output_layer >= 0:
								lowerCAmelCase__	:						Optional[Any]  				=	(
								    (outputs[0],) + (highway_logits_all[output_layer],) + outputs[2:]
								)  # use the highway of the last layer

						return outputs  # (loss), logits, (hidden_states), (attentions), (highway_exits)







"""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,
    convert_to_rgb,
    get_resize_output_image_size,
    normalize,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    OPENAI_CLIP_MEAN,
    OPENAI_CLIP_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, is_vision_available, logging


__UpperCamelCase  :      Optional[Any]							      =		logging.get_logger(__name__)


if is_vision_available():
							import PIL







class 				SCREAMING_SNAKE_CASE					(		a_       ):






					"""simple docstring"""



					lowercase__				 =       ["pixel_values"]







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

						lowerCAmelCase__	:						Dict  				=	do_resize
						lowerCAmelCase__	:						Optional[int]  				=	size
						lowerCAmelCase__	:						Dict  				=	resample
						lowerCAmelCase__	:						Optional[Any]  				=	do_center_crop
						lowerCAmelCase__	:						Dict  				=	crop_size
						lowerCAmelCase__	:						Tuple  				=	do_rescale
						lowerCAmelCase__	:						str  				=	rescale_factor
						lowerCAmelCase__	:						List[str]  				=	do_normalize
						lowerCAmelCase__	:						Tuple  				=	image_mean if image_mean is not None else OPENAI_CLIP_MEAN
						lowerCAmelCase__	:						Optional[Any]  				=	image_std if image_std is not None else OPENAI_CLIP_STD
						lowerCAmelCase__	:						Optional[Any]  				=	do_convert_rgb







					def        __lowerCAmelCase (       self			:				Dict   ,lowercase_			:				np.ndarray   ,lowercase_			:				Dict[str, int]   ,lowercase_			:				PILImageResampling = PILImageResampling.BICUBIC   ,lowercase_			:				Optional[Union[str, ChannelDimension]] = None   ,**lowercase_			:				Optional[Any]   ,):
						lowerCAmelCase__	:						Dict  				=	get_size_dict(lowercase_   ,default_to_square=lowercase_		)
						if "shortest_edge" not in size:
							raise ValueError(F'The `size` parameter must contain the key `shortest_edge`. Got {size.keys()}'		)
						lowerCAmelCase__	:						Optional[Any]  				=	get_resize_output_image_size(lowercase_   ,size=size['''shortest_edge''']   ,default_to_square=lowercase_		)
						return resize(lowercase_   ,size=lowercase_   ,resample=lowercase_   ,data_format=lowercase_   ,**lowercase_		)







					def        __lowerCAmelCase (       self			:				Tuple   ,lowercase_			:				np.ndarray   ,lowercase_			:				Dict[str, int]   ,lowercase_			:				Optional[Union[str, ChannelDimension]] = None   ,**lowercase_			:				str   ,):
						lowerCAmelCase__	:						List[str]  				=	get_size_dict(lowercase_		)
						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(lowercase_   ,size=(size['''height'''], size['''width'''])   ,data_format=lowercase_   ,**lowercase_		)







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







					def        __lowerCAmelCase (       self			:				Dict   ,lowercase_			:				np.ndarray   ,lowercase_			:				Union[float, List[float]]   ,lowercase_			:				Union[float, List[float]]   ,lowercase_			:				Optional[Union[str, ChannelDimension]] = None   ,**lowercase_			:				int   ,):
						return normalize(lowercase_   ,mean=lowercase_   ,std=lowercase_   ,data_format=lowercase_   ,**lowercase_		)







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

						lowerCAmelCase__	:						Any  				=	make_list_of_images(lowercase_		)

						if not valid_images(lowercase_		):
							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.'''		)

						# PIL RGBA images are converted to RGB
						if do_convert_rgb:
							lowerCAmelCase__	:						Tuple  				=	[convert_to_rgb(lowercase_		) for image in images]

						# All transformations expect numpy arrays.
						lowerCAmelCase__	:						Optional[int]  				=	[to_numpy_array(lowercase_		) for image in images]

						if do_resize:
							lowerCAmelCase__	:						Optional[int]  				=	[self.resize(image=lowercase_   ,size=lowercase_   ,resample=lowercase_		) for image in images]

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

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

						if do_normalize:
							lowerCAmelCase__	:						Union[str, Any]  				=	[self.normalize(image=lowercase_   ,mean=lowercase_   ,std=lowercase_		) for image in images]

						lowerCAmelCase__	:						Optional[Any]  				=	[to_channel_dimension_format(lowercase_   ,lowercase_		) for image in images]

						lowerCAmelCase__	:						List[Any]  				=	{'''pixel_values''': images}
						return BatchFeature(data=lowercase_   ,tensor_type=lowercase_		)




