"""simple docstring"""







from typing import Tuple, Union

from ...modeling_outputs import BackboneOutput
from ...modeling_utils import PreTrainedModel
from ...utils import is_timm_available, is_torch_available, requires_backends
from ...utils.backbone_utils import BackboneMixin
from .configuration_timm_backbone import TimmBackboneConfig


if is_timm_available():
						import timm


if is_torch_available():
						from torch import Tensor



class  _lowerCamelCase			(__lowerCamelCase						,							__lowerCamelCase     ):
				_snake_case     =  "pixel_values"
				_snake_case     =  False
				_snake_case     =  TimmBackboneConfig







				def __init__( self    :       Union[str, Any]			,					lowerCamelCase_    :       Tuple			,					**lowerCamelCase_    :       Optional[int]						):

					"""simple docstring"""






					requires_backends(self			,					'timm'						)
					super().__init__(lowerCamelCase_						)
					_lowercase :    Union[str, Any]							=							config

					if config.backbone is None:
						raise ValueError('backbone is not set in the config. Please set it to a timm model name.'						)

					if config.backbone not in timm.list_models():
						raise ValueError(F'''backbone {config.backbone} is not supported by timm.'''						)

					if hasattr(lowerCamelCase_			,					'out_features'						) and config.out_features is not None:
						raise ValueError('out_features is not supported by TimmBackbone. Please use out_indices instead.'						)

					_lowercase :    Any							=							getattr(lowerCamelCase_			,					'use_pretrained_backbone'			,					lowerCamelCase_						)
					if pretrained is None:
						raise ValueError('use_pretrained_backbone is not set in the config. Please set it to True or False.'						)

					# We just take the final layer by default. This matches the default for the transformers models.
					_lowercase :    str							=							config.out_indices if getattr(lowerCamelCase_			,					'out_indices'			,					lowerCamelCase_						) is not None else (-1,)

					_lowercase :    List[Any]							=							timm.create_model(
					    config.backbone			,					pretrained=lowerCamelCase_			,					features_only=config.features_only			,					in_chans=config.num_channels			,					out_indices=lowerCamelCase_			,					**lowerCamelCase_			,					)
					# These are used to control the output of the model when called. If output_hidden_states is True, then
					# return_layers is modified to include all layers.
					_lowercase :    str							=							self._backbone.return_layers
					_lowercase :    int							=							{layer['module']: str(lowerCamelCase_						) for i, layer in enumerate(self._backbone.feature_info.info						)}
					super()._init_backbone(lowerCamelCase_						)







				@classmethod
				def 							__UpperCAmelCase					( cls    :       List[Any]			,					lowerCamelCase_    :       Any			,					*lowerCamelCase_    :       Dict			,					**lowerCamelCase_    :       Union[str, Any]						):

					"""simple docstring"""






					requires_backends(cls			,					['vision', 'timm']						)
					from ...models.timm_backbone import TimmBackboneConfig

					_lowercase :    List[str]							=							kwargs.pop('config'			,					TimmBackboneConfig()						)

					_lowercase :    Union[str, Any]							=							kwargs.pop('use_timm_backbone'			,					lowerCamelCase_						)
					if not use_timm:
						raise ValueError('use_timm_backbone must be True for timm backbones'						)

					_lowercase :    Dict							=							kwargs.pop('num_channels'			,					config.num_channels						)
					_lowercase :    Tuple							=							kwargs.pop('features_only'			,					config.features_only						)
					_lowercase :    Optional[Any]							=							kwargs.pop('use_pretrained_backbone'			,					config.use_pretrained_backbone						)
					_lowercase :    Dict							=							kwargs.pop('out_indices'			,					config.out_indices						)
					_lowercase :    Union[str, Any]							=							TimmBackboneConfig(
					    backbone=lowerCamelCase_			,					num_channels=lowerCamelCase_			,					features_only=lowerCamelCase_			,					use_pretrained_backbone=lowerCamelCase_			,					out_indices=lowerCamelCase_			,					)
					return super()._from_config(lowerCamelCase_			,					**lowerCamelCase_						)







				def 							__UpperCAmelCase					( self    :       Tuple			,					lowerCamelCase_    :       List[str]						):

					"""simple docstring"""






					pass







				def 							__UpperCAmelCase					( self    :       str			,					lowerCamelCase_    :       Tuple			,					lowerCamelCase_    :       Tuple=None			,					lowerCamelCase_    :       List[str]=None			,					lowerCamelCase_    :       Optional[Any]=None			,					**lowerCamelCase_    :       Tuple						):

					"""simple docstring"""






					_lowercase :    List[Any]							=							return_dict if return_dict is not None else self.config.use_return_dict
					_lowercase :    Optional[int]							=							(
					    output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
					)
					_lowercase :    Optional[int]							=							output_attentions if output_attentions is not None else self.config.output_attentions

					if output_attentions:
						raise ValueError('Cannot output attentions for timm backbones at the moment'						)

					if output_hidden_states:
						# We modify the return layers to include all the stages of the backbone
						_lowercase :    Optional[int]							=							self._all_layers
						_lowercase :    Optional[Any]							=							self._backbone(lowerCamelCase_			,					**lowerCamelCase_						)
						_lowercase :    List[Any]							=							self._return_layers
						_lowercase :    Optional[int]							=							tuple(hidden_states[i] for i in self.out_indices						)
					else:
						_lowercase :    List[str]							=							self._backbone(lowerCamelCase_			,					**lowerCamelCase_						)
						_lowercase :    Tuple							=							None

					_lowercase :    Tuple							=							tuple(lowerCamelCase_						)
					_lowercase :    List[str]							=							tuple(lowerCamelCase_						) if hidden_states is not None else None

					if not return_dict:
						_lowercase :    Optional[int]							=							(feature_maps,)
						if output_hidden_states:
							_lowercase :    List[Any]							=							output + (hidden_states,)
						return output

					return BackboneOutput(feature_maps=lowerCamelCase_			,					hidden_states=lowerCamelCase_			,					attentions=lowerCamelCase_						)




"""simple docstring"""







from typing import Any


def      __lowerCAmelCase(		__UpperCAmelCase			):






	"""simple docstring"""





	if not input_list:
		return []
	_lowercase :    List[str]							=							[input_list.count(__UpperCAmelCase			) for value in input_list]
	_lowercase :    Optional[int]							=							max(__UpperCAmelCase			)  # Gets the maximum count in the input list.
	# Gets values of modes
	return sorted({input_list[i] for i, value in enumerate(__UpperCAmelCase			) if value == y}			)


if __name__ == "__main__":
						import doctest

						doctest.testmod()



