





'''simple docstring'''







import unittest
from unittest.util import safe_repr

from transformers import AutoTokenizer, RwkvConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch

					from transformers import (
					    RWKV_PRETRAINED_MODEL_ARCHIVE_LIST,
					    RwkvForCausalLM,
					    RwkvModel,
					)
					from transformers.pytorch_utils import is_torch_greater_or_equal_than_2_0
else:
					snake_case_  :							Union[str, Any]            =	False


class        __a   :

							def __init__(				self				:  Optional[Any]							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Dict=14							,  __magic_name__				:  Dict=7							,  __magic_name__				:  Union[str, Any]=True							,  __magic_name__				:  Tuple=False							,  __magic_name__				:  Optional[int]=True							,  __magic_name__				:  List[Any]=True							,  __magic_name__				:  int=True							,  __magic_name__				:  str=99							,  __magic_name__				:  Optional[int]=32							,  __magic_name__				:  Optional[int]=5							,  __magic_name__				:  Optional[Any]=37							,  __magic_name__				:  Union[str, Any]="gelu"							,  __magic_name__				:  Dict=0.1							,  __magic_name__				:  Dict=0.1							,  __magic_name__				:  Optional[int]=5_12							,  __magic_name__				:  Optional[Any]=16							,  __magic_name__				:  Tuple=2							,  __magic_name__				:  List[Any]=3							,  __magic_name__				:  Dict=4							,  __magic_name__				:  Dict=None							,  )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   str      =	parent
													UpperCAmelCase_      :   List[Any]      =	batch_size
													UpperCAmelCase_      :   List[Any]      =	seq_length
													UpperCAmelCase_      :   Tuple      =	is_training
													UpperCAmelCase_      :   Optional[int]      =	use_token_type_ids
													UpperCAmelCase_      :   Union[str, Any]      =	use_input_mask
													UpperCAmelCase_      :   List[str]      =	use_labels
													UpperCAmelCase_      :   str      =	use_mc_token_ids
													UpperCAmelCase_      :   Dict      =	vocab_size
													UpperCAmelCase_      :   Optional[int]      =	hidden_size
													UpperCAmelCase_      :   int      =	num_hidden_layers
													UpperCAmelCase_      :   Optional[Any]      =	intermediate_size
													UpperCAmelCase_      :   List[Any]      =	hidden_act
													UpperCAmelCase_      :   List[Any]      =	hidden_dropout_prob
													UpperCAmelCase_      :   Union[str, Any]      =	attention_probs_dropout_prob
													UpperCAmelCase_      :   str      =	max_position_embeddings
													UpperCAmelCase_      :   List[Any]      =	type_vocab_size
													UpperCAmelCase_      :   Optional[Any]      =	type_sequence_label_size
													UpperCAmelCase_      :   Optional[int]      =	num_labels
													UpperCAmelCase_      :   Optional[Any]      =	num_choices
													UpperCAmelCase_      :   Tuple      =	scope
													UpperCAmelCase_      :   List[str]      =	vocab_size - 1
													UpperCAmelCase_      :   List[Any]      =	vocab_size - 1
													UpperCAmelCase_      :   Any      =	vocab_size - 1

							def      UpperCAmelCase__						(				self				:  int )       ->							str:







													"""simple docstring"""
													return RwkvConfig.from_pretrained('''sgugger/rwkv-4-pile-7b''' )

							def      UpperCAmelCase__						(				self				:  List[Any]							,  __magic_name__				:  Optional[Any]=False							,  __magic_name__				:  str=False							,  __magic_name__				:  Dict=False )       ->							Tuple:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  self.vocab_size )

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

													UpperCAmelCase_      :   List[Any]      =	None
													if self.use_token_type_ids:
																			UpperCAmelCase_      :   int      =	ids_tensor([self.batch_size, self.seq_length]							,  self.type_vocab_size )

													UpperCAmelCase_      :   Optional[Any]      =	None
													if self.use_mc_token_ids:
																			UpperCAmelCase_      :   List[Any]      =	ids_tensor([self.batch_size, self.num_choices]							,  self.seq_length )

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

													UpperCAmelCase_      :   Union[str, Any]      =	self.get_config(
													    gradient_checkpointing=__magic_name__							,  scale_attn_by_inverse_layer_idx=__magic_name__							,  reorder_and_upcast_attn=__magic_name__							,  )

													return (
													    config,
													    input_ids,
													    input_mask,
													    None,
													    token_type_ids,
													    mc_token_ids,
													    sequence_labels,
													    token_labels,
													    choice_labels,
													)

							def      UpperCAmelCase__						(				self				:  Optional[int]							,  __magic_name__				:  Union[str, Any]=False							,  __magic_name__				:  Optional[Any]=False							,  __magic_name__				:  Union[str, Any]=False )       ->							Union[str, Any]:







													"""simple docstring"""
													return RwkvConfig(
													    vocab_size=self.vocab_size							,  hidden_size=self.hidden_size							,  num_hidden_layers=self.num_hidden_layers							,  intermediate_size=self.intermediate_size							,  activation_function=self.hidden_act							,  resid_pdrop=self.hidden_dropout_prob							,  attn_pdrop=self.attention_probs_dropout_prob							,  n_positions=self.max_position_embeddings							,  type_vocab_size=self.type_vocab_size							,  use_cache=__magic_name__							,  bos_token_id=self.bos_token_id							,  eos_token_id=self.eos_token_id							,  pad_token_id=self.pad_token_id							,  gradient_checkpointing=__magic_name__							,  scale_attn_by_inverse_layer_idx=__magic_name__							,  reorder_and_upcast_attn=__magic_name__							,  )

							def      UpperCAmelCase__						(				self				:  str )       ->							Dict:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	self.get_config()
													UpperCAmelCase_      :   int      =	3_00
													return config

							def      UpperCAmelCase__						(				self				:  Optional[int] )       ->							Union[str, Any]:







													"""simple docstring"""
													(
													    (
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							
													)      :   List[str]      =	self.prepare_config_and_inputs()

													UpperCAmelCase_      :   str      =	floats_tensor([self.batch_size, self.seq_length, self.hidden_size] )
													UpperCAmelCase_      :   Optional[Any]      =	ids_tensor([self.batch_size, self.seq_length]							,  vocab_size=2 )

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

							def      UpperCAmelCase__						(				self				:  int							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[Any]							,  __magic_name__				:  str							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  Optional[Any]							,  *__magic_name__				:  Union[str, Any] )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   Tuple      =	True
													UpperCAmelCase_      :   Any      =	RwkvModel(config=__magic_name__ )
													model.to(__magic_name__ )
													model.eval()

													UpperCAmelCase_      :   Optional[int]      =	model(__magic_name__ )

													self.parent.assertEqual(result.last_hidden_state.shape							,  (self.batch_size, self.seq_length, self.hidden_size) )
													self.parent.assertEqual(len(result.hidden_states )							,  config.num_hidden_layers + 1 )

							def      UpperCAmelCase__						(				self				:  Union[str, Any]							,  __magic_name__				:  List[str]							,  __magic_name__				:  List[str]							,  __magic_name__				:  List[str]							,  __magic_name__				:  int							,  __magic_name__				:  Tuple							,  *__magic_name__				:  Optional[int] )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	RwkvForCausalLM(__magic_name__ )
													model.to(__magic_name__ )
													model.eval()

													UpperCAmelCase_      :   List[str]      =	model(__magic_name__							,  labels=__magic_name__ )
													self.parent.assertEqual(result.loss.shape							,  () )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size) )

							def      UpperCAmelCase__						(				self				:  Tuple							,  __magic_name__				:  int							,  __magic_name__				:  str							,  __magic_name__				:  str							,  __magic_name__				:  Any							,  __magic_name__				:  Any							,  *__magic_name__				:  Union[str, Any] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	RwkvModel(config=__magic_name__ )
													model.to(__magic_name__ )
													model.eval()

													UpperCAmelCase_      :   Optional[int]      =	model(__magic_name__ )
													UpperCAmelCase_      :   Dict      =	outputs.last_hidden_state

													UpperCAmelCase_      :   Any      =	model(input_ids[:, :2] )
													UpperCAmelCase_      :   int      =	outputs.last_hidden_state

													# Using the state computed on the first inputs, we will get the same output
													UpperCAmelCase_      :   Optional[Any]      =	model(input_ids[:, 2:]							,  state=outputs.state )
													UpperCAmelCase_      :   int      =	outputs.last_hidden_state

													self.parent.assertTrue(torch.allclose(torch.cat([output_one, output_two]							,  dim=1 )							,  __magic_name__							,  atol=1E-5 ) )

							def      UpperCAmelCase__						(				self				:  int							,  __magic_name__				:  Optional[Any]							,  __magic_name__				:  List[str]							,  __magic_name__				:  Any							,  __magic_name__				:  Union[str, Any]							,  __magic_name__				:  List[Any]							,  *__magic_name__				:  List[Any]							,  __magic_name__				:  List[str]=False )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	RwkvForCausalLM(__magic_name__ )
													model.to(__magic_name__ )
													if gradient_checkpointing:
																			model.gradient_checkpointing_enable()

													UpperCAmelCase_      :   Any      =	model(__magic_name__							,  labels=__magic_name__ )
													self.parent.assertEqual(result.loss.shape							,  () )
													self.parent.assertEqual(result.logits.shape							,  (self.batch_size, self.seq_length, self.vocab_size) )
													result.loss.backward()



							def      UpperCAmelCase__						(				self				:  str )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   List[str]      =	self.prepare_config_and_inputs()

													(
													    (
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							(
													    UpperCAmelCase_
													)    ,							
													)      :   str      =	config_and_inputs

													UpperCAmelCase_      :   Any      =	{'''input_ids''': input_ids}

													return config, inputs_dict





@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0							,		reason="See https://github.com/huggingface/transformers/pull/24204"  )
@require_torch
class        __a   (lowerCamelCase							,		lowerCamelCase							,		lowerCamelCase							,		unittest.TestCase  ):
							__a       : List[Any]          =							(RwkvModel, RwkvForCausalLM) if is_torch_available() else ()
							__a       : List[str]          =							(
							    {"feature-extraction": RwkvModel, "text-generation": RwkvForCausalLM} if is_torch_available() else {}
							)
							# all_generative_model_classes = (RwkvForCausalLM,) if is_torch_available() else ()
							__a       : List[Any]          =							False
							__a       : Union[str, Any]          =							False
							__a       : List[str]          =							False
							__a       : List[Any]          =							False
							__a       : List[Any]          =							False  # Rwkv does not support head masking

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Dict      =	RwkvModelTester(self )
													UpperCAmelCase_      :   Union[str, Any]      =	ConfigTester(
													    self							,  config_class=__magic_name__							,  n_embd=37							,  common_properties=['''hidden_size''', '''num_hidden_layers'''] )

							def      UpperCAmelCase__						(				self				:  Optional[int]							,  __magic_name__				:  int							,  __magic_name__				:  Optional[int]							,  __magic_name__				:  Dict=None )       ->							List[str]:







													"""simple docstring"""
													if isinstance(__magic_name__							,  torch.Tensor ):
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   int      =	member.max().item(), member.min().item()
													elif isinstance(__magic_name__							,  __magic_name__ ) or isinstance(__magic_name__							,  __magic_name__ ):
																			UpperCAmelCase_    ,							UpperCAmelCase_      :   int      =	max(__magic_name__ ), min(__magic_name__ )

													if not isinstance(__magic_name__							,  __magic_name__ ):
																			raise TypeError('''container should be a list or tuple''' )
													elif len(__magic_name__ ) != 2:
																			raise ValueError('''container should have 2 elements''' )

													UpperCAmelCase_    ,							UpperCAmelCase_      :   Tuple      =	container

													UpperCAmelCase_      :   int      =	(min_value >= expected_min) and (max_value <= expected_max)

													if not is_inside_interval:
																			UpperCAmelCase_      :   Optional[Any]      =	'''%s not found in %s''' % (safe_repr(__magic_name__ ), safe_repr(__magic_name__ ))
																			self.fail(self._formatMessage(__magic_name__							,  __magic_name__ ) )

							def      UpperCAmelCase__						(				self				:  Any )       ->							List[Any]:







													"""simple docstring"""
													self.config_tester.run_common_tests()

							def      UpperCAmelCase__						(				self				:  List[str] )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_rwkv_model(*__magic_name__ )

							def      UpperCAmelCase__						(				self				:  Tuple )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[int]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_causl_lm(*__magic_name__ )

							def      UpperCAmelCase__						(				self				:  str )       ->							List[Any]:







													"""simple docstring"""
													UpperCAmelCase_      :   Union[str, Any]      =	self.model_tester.prepare_config_and_inputs()
													self.model_tester.create_and_check_state_equivalency(*__magic_name__ )

							def      UpperCAmelCase__						(				self				:  List[str] )       ->							Optional[Any]:







													"""simple docstring"""
													UpperCAmelCase_    ,							UpperCAmelCase_      :   List[str]      =	self.model_tester.prepare_config_and_inputs_for_common()

													for model_class in self.all_model_classes:
																			UpperCAmelCase_      :   int      =	model_class(config=__magic_name__ )
																			for name, param in model.named_parameters():
																									if "time_decay" in name:
																															if param.requires_grad:
																																					self.assertTrue(param.data.max().item() == 3.0 )
																																					self.assertTrue(param.data.min().item() == -5.0 )
																									elif "time_first" in name:
																															if param.requires_grad:
																																					# check if it's a ones like
																																					self.assertTrue(torch.allclose(param.data							,  torch.ones_like(param.data )							,  atol=1E-5							,  rtol=1E-5 ) )
																									elif any(x in name for x in ['''time_mix_key''', '''time_mix_receptance'''] ):
																															if param.requires_grad:
																																					self.assertInterval(
																																					    param.data							,  [0.0, 1.0]							,  msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""							,  )
																									elif "time_mix_value" in name:
																															if param.requires_grad:
																																					self.assertInterval(
																																					    param.data							,  [0.0, 1.3]							,  msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""							,  )

							def      UpperCAmelCase__						(				self				:  Dict )       ->							Union[str, Any]:







													"""simple docstring"""
													UpperCAmelCase_    ,							UpperCAmelCase_      :   Union[str, Any]      =	self.model_tester.prepare_config_and_inputs_for_common()
													UpperCAmelCase_      :   str      =	True

													UpperCAmelCase_      :   Optional[int]      =	getattr(self.model_tester							,  '''seq_length'''							,  __magic_name__ )

													for model_class in self.all_model_classes:
																			UpperCAmelCase_      :   Union[str, Any]      =	True
																			UpperCAmelCase_      :   Dict      =	False
																			UpperCAmelCase_      :   List[str]      =	True
																			UpperCAmelCase_      :   Tuple      =	model_class(__magic_name__ )
																			model.to(__magic_name__ )
																			model.eval()

																			UpperCAmelCase_      :   Tuple      =	self._prepare_for_class(__magic_name__							,  __magic_name__ )
																			UpperCAmelCase_      :   Optional[Any]      =	inputs['''input_ids'''].shape[0]
																			with torch.no_grad():
																									UpperCAmelCase_      :   Optional[Any]      =	model(**__magic_name__ )
																			UpperCAmelCase_      :   List[Any]      =	outputs.attentions
																			self.assertEqual(len(__magic_name__ )							,  self.model_tester.num_hidden_layers )

																			# check that output_attentions also work using config
																			del inputs_dict["output_attentions"]
																			UpperCAmelCase_      :   Union[str, Any]      =	True
																			UpperCAmelCase_      :   Tuple      =	model_class(__magic_name__ )
																			model.to(__magic_name__ )
																			model.eval()

																			UpperCAmelCase_      :   List[Any]      =	self._prepare_for_class(__magic_name__							,  __magic_name__ )
																			UpperCAmelCase_      :   Dict      =	inputs['''input_ids'''].shape[0]
																			with torch.no_grad():
																									UpperCAmelCase_      :   Tuple      =	model(**__magic_name__ )
																			UpperCAmelCase_      :   Any      =	outputs.attentions
																			self.assertEqual(len(__magic_name__ )							,  self.model_tester.num_hidden_layers )

																			self.assertListEqual(
																			    list(attentions[0].shape[-3:] )							,  [batch_size, seq_len, config.hidden_size]							,  )
																			UpperCAmelCase_      :   Dict      =	len(__magic_name__ )

																			# Check attention is always last and order is fine
																			UpperCAmelCase_      :   Union[str, Any]      =	True
																			UpperCAmelCase_      :   List[str]      =	True
																			UpperCAmelCase_      :   Any      =	model_class(__magic_name__ )
																			model.to(__magic_name__ )
																			model.eval()

																			UpperCAmelCase_      :   Optional[Any]      =	self._prepare_for_class(__magic_name__							,  __magic_name__ )
																			UpperCAmelCase_      :   Tuple      =	inputs['''input_ids'''].shape[0]
																			with torch.no_grad():
																									UpperCAmelCase_      :   str      =	model(**__magic_name__ )

																			UpperCAmelCase_      :   int      =	1
																			self.assertEqual(out_len + added_hidden_states							,  len(__magic_name__ ) )

																			UpperCAmelCase_      :   Optional[int]      =	outputs.attentions

																			self.assertEqual(len(__magic_name__ )							,  self.model_tester.num_hidden_layers )
																			self.assertListEqual(
																			    list(self_attentions[0].shape[-3:] )							,  [batch_size, seq_len, config.hidden_size]							,  )



							@slow
							def      UpperCAmelCase__						(				self				:  Tuple )       ->							str:







													"""simple docstring"""
													for model_name in RWKV_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																			UpperCAmelCase_      :   Optional[Any]      =	RwkvModel.from_pretrained(__magic_name__ )
																			self.assertIsNotNone(__magic_name__ )





@unittest.skipIf(
    not is_torch_greater_or_equal_than_2_0							,		reason="See https://github.com/huggingface/transformers/pull/24204"  )
@slow
class        __a   (unittest.TestCase  ):

							def      UpperCAmelCase__						(				self				:  Any )       ->							Optional[int]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	'''RWKV/rwkv-4-169m-pile'''
													UpperCAmelCase_      :   int      =	AutoTokenizer.from_pretrained(self.model_id )

							def      UpperCAmelCase__						(				self				:  Dict )       ->							str:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	'''Hello my name is Jasmine and I am a newbie to the'''
													UpperCAmelCase_      :   Optional[Any]      =	RwkvForCausalLM.from_pretrained(self.model_id ).to(__magic_name__ )

													UpperCAmelCase_      :   List[Any]      =	self.tokenizer('''Hello my name is'''							,  return_tensors='''pt''' ).input_ids.to(__magic_name__ )
													UpperCAmelCase_      :   Optional[int]      =	model.generate(__magic_name__							,  max_new_tokens=10 )
													UpperCAmelCase_      :   Dict      =	self.tokenizer.decode(output[0].tolist() )

													self.assertEqual(__magic_name__							,  __magic_name__ )



							def      UpperCAmelCase__						(				self				:  List[str] )       ->							List[str]:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	'''Hello my name is Jasmine and I am a newbie to the'''

													UpperCAmelCase_      :   List[str]      =	self.tokenizer('''Hello my name is'''							,  return_tensors='''pt''' ).input_ids.to(__magic_name__ )
													UpperCAmelCase_      :   int      =	RwkvForCausalLM.from_pretrained(self.model_id							,  torch_dtype=torch.bfloataa ).to(__magic_name__ )

													UpperCAmelCase_      :   List[str]      =	model.generate(__magic_name__							,  max_new_tokens=10 )
													UpperCAmelCase_      :   List[str]      =	self.tokenizer.decode(output[0].tolist() )

													self.assertEqual(__magic_name__							,  __magic_name__ )












'''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


snake_case_  :							Any            =	logging.get_logger(__name__)


if is_vision_available():
					import PIL


class        __a   (lowerCamelCase  ):
							__a       : Any          =							["pixel_values"]

							def __init__(				self				:  Optional[int]							,  __magic_name__				:  bool = True							,  __magic_name__				:  Dict[str, int] = None							,  __magic_name__				:  PILImageResampling = PILImageResampling.BICUBIC							,  __magic_name__				:  bool = True							,  __magic_name__				:  Dict[str, int] = None							,  __magic_name__				:  bool = True							,  __magic_name__				:  Union[int, float] = 1 / 2_55							,  __magic_name__				:  bool = True							,  __magic_name__				:  Optional[Union[float, List[float]]] = None							,  __magic_name__				:  Optional[Union[float, List[float]]] = None							,  __magic_name__				:  bool = True							,  **__magic_name__				:  Union[str, Any]							,  )       ->							None:







													"""simple docstring"""
													super().__init__(**__magic_name__ )
													UpperCAmelCase_      :   List[Any]      =	size if size is not None else {'''shortest_edge''': 2_24}
													UpperCAmelCase_      :   List[str]      =	get_size_dict(__magic_name__							,  default_to_square=__magic_name__ )
													UpperCAmelCase_      :   int      =	crop_size if crop_size is not None else {'''height''': 2_24, '''width''': 2_24}
													UpperCAmelCase_      :   Union[str, Any]      =	get_size_dict(__magic_name__ )

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

							def      UpperCAmelCase__						(				self				:  int							,  __magic_name__				:  np.ndarray							,  __magic_name__				:  Dict[str, int]							,  __magic_name__				:  PILImageResampling = PILImageResampling.BICUBIC							,  __magic_name__				:  Optional[Union[str, ChannelDimension]] = None							,  **__magic_name__				:  Optional[int]							,  )       ->							np.ndarray:







													"""simple docstring"""
													UpperCAmelCase_      :   Optional[Any]      =	get_size_dict(__magic_name__							,  default_to_square=__magic_name__ )
													UpperCAmelCase_      :   Any      =	get_resize_output_image_size(
													    __magic_name__							,  size=(size['''height'''], size['''width'''])							,  default_to_square=__magic_name__ )
													return resize(__magic_name__							,  size=__magic_name__							,  resample=__magic_name__							,  data_format=__magic_name__							,  **__magic_name__ )

							def      UpperCAmelCase__						(				self				:  List[Any]							,  __magic_name__				:  np.ndarray							,  __magic_name__				:  Dict[str, int]							,  __magic_name__				:  Optional[Union[str, ChannelDimension]] = None							,  **__magic_name__				:  Any							,  )       ->							np.ndarray:







													"""simple docstring"""
													UpperCAmelCase_      :   List[Any]      =	get_size_dict(__magic_name__ )
													return center_crop(__magic_name__							,  size=(size['''height'''], size['''width'''])							,  data_format=__magic_name__							,  **__magic_name__ )

							def      UpperCAmelCase__						(				self				:  str							,  __magic_name__				:  np.ndarray							,  __magic_name__				:  Union[int, float]							,  __magic_name__				:  Optional[Union[str, ChannelDimension]] = None							,  **__magic_name__				:  Any							,  )       ->							Union[str, Any]:







													"""simple docstring"""
													return rescale(__magic_name__							,  scale=__magic_name__							,  data_format=__magic_name__							,  **__magic_name__ )

							def      UpperCAmelCase__						(				self				:  str							,  __magic_name__				:  np.ndarray							,  __magic_name__				:  Union[float, List[float]]							,  __magic_name__				:  Union[float, List[float]]							,  __magic_name__				:  Optional[Union[str, ChannelDimension]] = None							,  **__magic_name__				:  Optional[int]							,  )       ->							np.ndarray:







													"""simple docstring"""
													return normalize(__magic_name__							,  mean=__magic_name__							,  std=__magic_name__							,  data_format=__magic_name__							,  **__magic_name__ )



							def      UpperCAmelCase__						(				self				:  Dict							,  __magic_name__				:  ImageInput							,  __magic_name__				:  bool = None							,  __magic_name__				:  Dict[str, int] = None							,  __magic_name__				:  PILImageResampling = None							,  __magic_name__				:  bool = None							,  __magic_name__				:  int = None							,  __magic_name__				:  bool = None							,  __magic_name__				:  float = None							,  __magic_name__				:  bool = None							,  __magic_name__				:  Optional[Union[float, List[float]]] = None							,  __magic_name__				:  Optional[Union[float, List[float]]] = None							,  __magic_name__				:  bool = None							,  __magic_name__				:  Optional[Union[str, TensorType]] = None							,  __magic_name__				:  Optional[ChannelDimension] = ChannelDimension.FIRST							,  **__magic_name__				:  Union[str, Any]							,  )       ->							PIL.Image.Image:







													"""simple docstring"""
													UpperCAmelCase_      :   int      =	do_resize if do_resize is not None else self.do_resize
													UpperCAmelCase_      :   Dict      =	size if size is not None else self.size
													UpperCAmelCase_      :   Union[str, Any]      =	get_size_dict(__magic_name__							,  default_to_square=__magic_name__ )
													UpperCAmelCase_      :   str      =	resample if resample is not None else self.resample
													UpperCAmelCase_      :   Tuple      =	do_center_crop if do_center_crop is not None else self.do_center_crop
													UpperCAmelCase_      :   List[str]      =	crop_size if crop_size is not None else self.crop_size
													UpperCAmelCase_      :   Optional[Any]      =	get_size_dict(__magic_name__ )
													UpperCAmelCase_      :   str      =	do_rescale if do_rescale is not None else self.do_rescale
													UpperCAmelCase_      :   Tuple      =	rescale_factor if rescale_factor is not None else self.rescale_factor
													UpperCAmelCase_      :   List[Any]      =	do_normalize if do_normalize is not None else self.do_normalize
													UpperCAmelCase_      :   Tuple      =	image_mean if image_mean is not None else self.image_mean
													UpperCAmelCase_      :   int      =	image_std if image_std is not None else self.image_std
													UpperCAmelCase_      :   Optional[Any]      =	do_convert_rgb if do_convert_rgb is not None else self.do_convert_rgb

													UpperCAmelCase_      :   Any      =	make_list_of_images(__magic_name__ )

													if not valid_images(__magic_name__ ):
																			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:
																			UpperCAmelCase_      :   Optional[int]      =	[convert_to_rgb(__magic_name__ ) for image in images]

													# All transformations expect numpy arrays.
													UpperCAmelCase_      :   Optional[Any]      =	[to_numpy_array(__magic_name__ ) for image in images]

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

													if do_center_crop:
																			UpperCAmelCase_      :   Union[str, Any]      =	[self.center_crop(image=__magic_name__							,  size=__magic_name__ ) for image in images]

													if do_rescale:
																			UpperCAmelCase_      :   Dict      =	[self.rescale(image=__magic_name__							,  scale=__magic_name__ ) for image in images]

													if do_normalize:
																			UpperCAmelCase_      :   Optional[int]      =	[self.normalize(image=__magic_name__							,  mean=__magic_name__							,  std=__magic_name__ ) for image in images]

													UpperCAmelCase_      :   Optional[Any]      =	[to_channel_dimension_format(__magic_name__							,  __magic_name__ ) for image in images]

													UpperCAmelCase_      :   int      =	{'''pixel_values''': images}
													return BatchFeature(data=__magic_name__							,  tensor_type=__magic_name__ )





