'''simple docstring'''

import enum
import inspect
from typing import Iterable, List, Optional, Tuple, Union




class 		SCREAMING_SNAKE_CASE_					(enum.Enum      ):



			"""simple docstring"""






			__magic_name__ :				Optional[Any]   							=       """timm"""
			__magic_name__ :				Dict   							=       """transformers"""







def        UpperCAmelCase__   (				_lowerCAmelCase    :			Optional[Iterable[str]],      _lowerCAmelCase    :			Optional[Iterable[int]],      _lowerCAmelCase    :			Optional[Iterable[str]])    ->		Tuple:



						"""simple docstring"""

						if stage_names is None:
												raise ValueError("Stage_names must be set for transformers backbones")

						if out_features is not None:
												if not isinstance(_lowerCAmelCase,      (list,)):
																		raise ValueError(f"""out_features must be a list {type(_lowerCAmelCase)}""")
												if any(feat not in stage_names for feat in out_features):
																		raise ValueError(f"""out_features must be a subset of stage_names: {stage_names} got {out_features}""")

						if out_indices is not None:
												if not isinstance(_lowerCAmelCase,      (list, tuple)):
																		raise ValueError(f"""out_indices must be a list or tuple, got {type(_lowerCAmelCase)}""")
												if any(idx >= len(_lowerCAmelCase) for idx in out_indices):
																		raise ValueError("out_indices must be valid indices for stage_names {stage_names}, got {out_indices}")

						if out_features is not None and out_indices is not None:
												if len(_lowerCAmelCase) != len(_lowerCAmelCase):
																		raise ValueError("out_features and out_indices should have the same length if both are set")
												if out_features != [stage_names[idx] for idx in out_indices]:
																		raise ValueError("out_features and out_indices should correspond to the same stages if both are set")


def        UpperCAmelCase__   (				_lowerCAmelCase    :			Optional[List[str]],      _lowerCAmelCase    :			Optional[Union[List[int], Tuple[int]]],      _lowerCAmelCase    :			List[str],      )    ->		List[str]:



						"""simple docstring"""

						if out_indices is None and out_features is None:
												snake_case :       Dict				=    [len(_lowerCAmelCase) - 1]
												snake_case :       Optional[int]				=    [stage_names[-1]]
						elif out_indices is None and out_features is not None:
												snake_case :       List[str]				=    [stage_names.index(_lowerCAmelCase) for layer in out_features]
						elif out_features is None and out_indices is not None:
												snake_case :       Optional[Any]				=    [stage_names[idx] for idx in out_indices]
						return out_features, out_indices


def        UpperCAmelCase__   (				_lowerCAmelCase    :			Optional[List[str]],      _lowerCAmelCase    :			Optional[Union[List[int], Tuple[int]]],      _lowerCAmelCase    :			List[str],      )    ->		Tuple[List[str], List[int]]:



						"""simple docstring"""

						verify_out_features_out_indices(out_features=_lowerCAmelCase,      out_indices=_lowerCAmelCase,      stage_names=_lowerCAmelCase)
						snake_case				,					snake_case :       str				=    _align_output_features_output_indices(
						    out_features=_lowerCAmelCase,      out_indices=_lowerCAmelCase,      stage_names=_lowerCAmelCase)
						# Verify that the aligned out_features and out_indices are valid
						verify_out_features_out_indices(out_features=_lowerCAmelCase,      out_indices=_lowerCAmelCase,      stage_names=_lowerCAmelCase)
						return output_features, output_indices




class 		SCREAMING_SNAKE_CASE_					:



			"""simple docstring"""






			__magic_name__ :				Optional[BackboneType]   							=       None



			def   lowerCamelCase (							self				,			snake_case_					):
									if getattr(self				,			"_backbone"				,			snake_case_					) is None:
															raise ValueError("self._backbone must be set before calling _init_timm_backbone"					)

									# These will diagree with the defaults for the transformers models e.g. for resnet50
									# the transformer model has out_features = ['stem', 'stage1', 'stage2', 'stage3', 'stage4']
									# the timm model has out_features = ['act', 'layer1', 'layer2', 'layer3', 'layer4']
									snake_case :       Optional[int]				=    [stage["module"] for stage in self._backbone.feature_info.info]
									snake_case :       Dict				=    [stage["num_chs"] for stage in self._backbone.feature_info.info]
									snake_case :       str				=    self._backbone.feature_info.out_indices
									snake_case :       List[Any]				=    self._backbone.feature_info.module_name()

									# We verify the out indices and out features are valid
									verify_out_features_out_indices(
									    out_features=snake_case_				,			out_indices=snake_case_				,			stage_names=self.stage_names					)
									snake_case				,					snake_case :       Any				=    out_features, out_indices



			def   lowerCamelCase (							self				,			snake_case_					):
									snake_case :       Any				=    getattr(snake_case_				,			"stage_names"					)
									snake_case :       Any				=    getattr(snake_case_				,			"out_features"				,			snake_case_					)
									snake_case :       Tuple				=    getattr(snake_case_				,			"out_indices"				,			snake_case_					)

									snake_case :       Dict				=    stage_names
									snake_case				,					snake_case :       Tuple				=    get_aligned_output_features_output_indices(
									    out_features=snake_case_				,			out_indices=snake_case_				,			stage_names=snake_case_					)
									# Number of channels for each stage. This is set in the transformer backbone model init
									snake_case :       int				=    None



			def   lowerCamelCase (							self				,			snake_case_					):
									snake_case :       Any				=    config

									snake_case :       str				=    getattr(snake_case_				,			"use_timm_backbone"				,			snake_case_					)
									snake_case :       Tuple				=    BackboneType.TIMM if self.use_timm_backbone else BackboneType.TRANSFORMERS

									if self.backbone_type == BackboneType.TIMM:
															self._init_timm_backbone(snake_case_					)
									elif self.backbone_type == BackboneType.TRANSFORMERS:
															self._init_transformers_backbone(snake_case_					)
									else:
															raise ValueError(F"""backbone_type {self.backbone_type} not supported."""					)



			@property
			def   lowerCamelCase (							self					):
									return self._out_features



			@out_features.setter
			def   lowerCamelCase (							self				,			snake_case_					):
									snake_case				,					snake_case :       Optional[int]				=    get_aligned_output_features_output_indices(
									    out_features=snake_case_				,			out_indices=snake_case_				,			stage_names=self.stage_names					)



			@property
			def   lowerCamelCase (							self					):
									return self._out_indices



			@out_indices.setter
			def   lowerCamelCase (							self				,			snake_case_					):
									snake_case				,					snake_case :       int				=    get_aligned_output_features_output_indices(
									    out_features=snake_case_				,			out_indices=snake_case_				,			stage_names=self.stage_names					)



			@property
			def   lowerCamelCase (							self					):
									# the current backbones will output the number of channels for each stage
									# even if that stage is not in the out_features list.
									return {stage: self.num_features[i] for i, stage in enumerate(self.stage_names					)}



			@property
			def   lowerCamelCase (							self					):
									return [self.out_feature_channels[name] for name in self.out_features]



			def   lowerCamelCase (							self				,			*snake_case_				,			**snake_case_					):
									snake_case :       List[str]				=    dict(inspect.signature(self.forward					).parameters					)
									snake_case :       Any				=    {k: v for k, v in kwargs.items() if k in signature}
									return self(*snake_case_				,			**snake_case_					)



			def   lowerCamelCase (							self				,			snake_case_				,			snake_case_ = None				,			snake_case_ = None				,			snake_case_ = None				,			):
									raise NotImplementedError("This method should be implemented by the derived class."					)






			def   lowerCamelCase (							self					):
									snake_case :       Optional[Any]				=    super().to_dict()
									snake_case :       List[str]				=    output.pop("_out_features"					)
									snake_case :       Any				=    output.pop("_out_indices"					)
									return output







class 		SCREAMING_SNAKE_CASE_					:



			"""simple docstring"""






			@property
			def   lowerCamelCase (							self					):
									return self._out_features



			@out_features.setter
			def   lowerCamelCase (							self				,			snake_case_					):
									snake_case				,					snake_case :       List[Any]				=    get_aligned_output_features_output_indices(
									    out_features=snake_case_				,			out_indices=snake_case_				,			stage_names=self.stage_names					)



			@property
			def   lowerCamelCase (							self					):
									return self._out_indices



			@out_indices.setter
			def   lowerCamelCase (							self				,			snake_case_					):
									snake_case				,					snake_case :       str				=    get_aligned_output_features_output_indices(
									    out_features=snake_case_				,			out_indices=snake_case_				,			stage_names=self.stage_names					)






			def   lowerCamelCase (							self					):
									snake_case :       int				=    super().to_dict()
									snake_case :       Union[str, Any]				=    output.pop("_out_features"					)
									snake_case :       Union[str, Any]				=    output.pop("_out_indices"					)
									return output






'''simple docstring'''

import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding




class 		SCREAMING_SNAKE_CASE_					(_UpperCAmelCase      ):



			"""simple docstring"""






			__magic_name__ :				Dict   							=       ["""image_processor""", """tokenizer"""]
			__magic_name__ :				Union[str, Any]   							=       """VideoMAEImageProcessor"""
			__magic_name__ :				List[str]   							=       ("""CLIPTokenizer""", """CLIPTokenizerFast""")



			def __init__(							self				,			snake_case_=None				,			snake_case_=None				,			**snake_case_					):
									snake_case :       int				=    None
									if "feature_extractor" in kwargs:
															warnings.warn(
															    "The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"
															    " instead."				,			snake_case_				,			)
															snake_case :       Optional[int]				=    kwargs.pop("feature_extractor"					)

									snake_case :       Union[str, Any]				=    image_processor if image_processor is not None else feature_extractor
									if image_processor is None:
															raise ValueError("You need to specify an `image_processor`."					)
									if tokenizer is None:
															raise ValueError("You need to specify a `tokenizer`."					)

									super().__init__(snake_case_				,			snake_case_					)
									snake_case :       List[Any]				=    self.image_processor



			def __call__(							self				,			snake_case_=None				,			snake_case_=None				,			snake_case_=None				,			**snake_case_					):

									if text is None and videos is None:
															raise ValueError("You have to specify either text or videos. Both cannot be none."					)

									if text is not None:
															snake_case :       List[Any]				=    self.tokenizer(snake_case_				,			return_tensors=snake_case_				,			**snake_case_					)

									if videos is not None:
															snake_case :       List[Any]				=    self.image_processor(snake_case_				,			return_tensors=snake_case_				,			**snake_case_					)

									if text is not None and videos is not None:
															snake_case :       Tuple				=    image_features.pixel_values
															return encoding
									elif text is not None:
															return encoding
									else:
															return BatchEncoding(data=dict(**snake_case_					)				,			tensor_type=snake_case_					)



			def   lowerCamelCase (							self				,			*snake_case_				,			**snake_case_					):
									return self.tokenizer.batch_decode(*snake_case_				,			**snake_case_					)



			def   lowerCamelCase (							self				,			*snake_case_				,			**snake_case_					):
									return self.tokenizer.decode(*snake_case_				,			**snake_case_					)



			@property
			def   lowerCamelCase (							self					):
									return ["input_ids", "attention_mask", "position_ids", "pixel_values"]



			@property
			def   lowerCamelCase (							self					):
									warnings.warn(
									    "`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."				,			snake_case_				,			)
									return self.image_processor_class






			@property
			def   lowerCamelCase (							self					):
									warnings.warn(
									    "`feature_extractor` is deprecated and will be removed in v5. Use `image_processor` instead."				,			snake_case_				,			)
									return self.image_processor





