




"""simple docstring"""
import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)

class __lowercase(   unittest.TestCase					):




					'''simple docstring'''


					def      snake_case_					(     self  ):
								__lowerCamelCase       :						Optional[int]													=					['a', 'b', 'c']

								# Defaults to last layer if both are None
								__lowerCamelCase       :						List[str]													=					get_aligned_output_features_output_indices(__a    ,						__a    ,						__a  )
								self.assertEqual(__a    ,						['c']  )
								self.assertEqual(__a    ,						[2]  )

								# Out indices set to match out features
								__lowerCamelCase       :						List[str]													=					get_aligned_output_features_output_indices(['a', 'c']    ,						__a    ,						__a  )
								self.assertEqual(__a    ,						['a', 'c']  )
								self.assertEqual(__a    ,						[0, 2]  )

								# Out features set to match out indices
								__lowerCamelCase       :						Dict													=					get_aligned_output_features_output_indices(__a    ,						[0, 2]    ,						__a  )
								self.assertEqual(__a    ,						['a', 'c']  )
								self.assertEqual(__a    ,						[0, 2]  )

								# Out features selected from negative indices
								__lowerCamelCase       :						Dict													=					get_aligned_output_features_output_indices(__a    ,						[-3, -1]    ,						__a  )
								self.assertEqual(__a    ,						['a', 'c']  )
								self.assertEqual(__a    ,						[-3, -1]  )
					def      snake_case_					(     self  ):
								# Stage names must be set
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(['a', 'b']    ,						(0, 1)    ,						__a  )

								# Out features must be a list
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(('a', 'b')    ,						(0, 1)    ,						['a', 'b']  )

								# Out features must be a subset of stage names
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(['a', 'b']    ,						(0, 1)    ,						['a']  )

								# Out indices must be a list or tuple
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(__a    ,						0    ,						['a', 'b']  )

								# Out indices must be a subset of stage names
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(__a    ,						(0, 1)    ,						['a']  )

								# Out features and out indices must be the same length
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(['a', 'b']    ,						(0,)    ,						['a', 'b', 'c']  )

								# Out features should match out indices
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(['a', 'b']    ,						(0, 2)    ,						['a', 'b', 'c']  )

								# Out features and out indices should be in order
								with self.assertRaises(__a  ):
											verify_out_features_out_indices(['b', 'a']    ,						(0, 1)    ,						['a', 'b']  )

								# Check passes with valid inputs
								verify_out_features_out_indices(['a', 'b', 'd']    ,						(0, 1, -1)    ,						['a', 'b', 'c', 'd']  )





					def      snake_case_					(     self  ):
								__lowerCamelCase       :						Optional[int]													=					BackboneMixin()

								__lowerCamelCase       :						Any													=					['a', 'b', 'c']
								__lowerCamelCase       :						Union[str, Any]													=					['a', 'c']
								__lowerCamelCase       :						List[str]													=					[0, 2]

								# Check that the output features and indices are set correctly
								self.assertEqual(backbone.out_features    ,						['a', 'c']  )
								self.assertEqual(backbone.out_indices    ,						[0, 2]  )

								# Check out features and indices are updated correctly
								__lowerCamelCase       :						str													=					['a', 'b']
								self.assertEqual(backbone.out_features    ,						['a', 'b']  )
								self.assertEqual(backbone.out_indices    ,						[0, 1]  )

								__lowerCamelCase       :						Any													=					[-3, -1]
								self.assertEqual(backbone.out_features    ,						['a', 'c']  )
								self.assertEqual(backbone.out_indices    ,						[-3, -1]  )








'''simple docstring'''





import copy

from ...configuration_utils import PretrainedConfig
from ...utils import logging
from ..auto.configuration_auto import CONFIG_MAPPING


A__    :   Union[str, Any]           =					logging.get_logger(__name__)



class  snake_case__						(    SCREAMING_SNAKE_CASE_				):
 A__				= '''upernet'''
 def __init__(   self						:							Optional[int]      ,     __a						:							Dict=None      ,     __a						:							List[str]=512      ,     __a						:							int=0.0_2      ,     __a						:							Optional[Any]=[1, 2, 3, 6]      ,     __a						:							Union[str, Any]=True      ,     __a						:							Any=0.4      ,     __a						:							int=384      ,     __a						:							int=256      ,     __a						:							str=1      ,     __a						:							List[Any]=False      ,     __a						:							Dict=255      ,     **__a						:							Dict      ,     )      ->   Optional[int]:







       '''simple docstring'''
       super().__init__(**__a  )

       if backbone_config is None:
             logger.info('`backbone_config` is `None`. Initializing the config with the default `ResNet` backbone.'  )
             __snake_case :   Optional[int]													=    CONFIG_MAPPING['resnet'](out_features=['stage1', 'stage2', 'stage3', 'stage4']  )
       elif isinstance(__a      ,     __a  ):
             __snake_case :   List[Any]													=    backbone_config.get('model_type'  )
             __snake_case :   List[str]													=    CONFIG_MAPPING[backbone_model_type]
             __snake_case :   int													=    config_class.from_dict(__a  )

       __snake_case :   Any													=    backbone_config
       __snake_case :   Tuple													=    hidden_size
       __snake_case :   str													=    initializer_range
       __snake_case :   Dict													=    pool_scales
       __snake_case :   Optional[Any]													=    use_auxiliary_head
       __snake_case :   Optional[Any]													=    auxiliary_loss_weight
       __snake_case :   Optional[int]													=    auxiliary_in_channels
       __snake_case :   Dict													=    auxiliary_channels
       __snake_case :   Any													=    auxiliary_num_convs
       __snake_case :   Optional[Any]													=    auxiliary_concat_input
       __snake_case :   List[str]													=    loss_ignore_index





 def A_   (   self						:							List[Any]  )      ->   Union[str, Any]:







       '''simple docstring'''
       __snake_case :   Union[str, Any]													=    copy.deepcopy(self.__dict__  )
       __snake_case :   str													=    self.backbone_config.to_dict()
       __snake_case :   Optional[int]													=    self.__class__.model_type
       return output



