
import unittest

from transformers.utils.backbone_utils import (
    BackboneMixin,
    get_aligned_output_features_output_indices,
    verify_out_features_out_indices,
)
class       _lowerCAmelCase  (		unittest.TestCase							):

 """simple docstring"""

 def      __lowerCAmelCase  (						self			:			str   ):






      """simple docstring"""



      UpperCamelCase						    =					['a', 'b', 'c']

      # Defaults to last layer if both are None
      UpperCamelCase    ,		UpperCamelCase						    =					get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__					, SCREAMING_SNAKE_CASE__					, SCREAMING_SNAKE_CASE__   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, ['c']   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, [2]   )

      # Out indices set to match out features
      UpperCamelCase    ,		UpperCamelCase						    =					get_aligned_output_features_output_indices(['a', 'c']					, SCREAMING_SNAKE_CASE__					, SCREAMING_SNAKE_CASE__   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, ['a', 'c']   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, [0, 2]   )

      # Out features set to match out indices
      UpperCamelCase    ,		UpperCamelCase						    =					get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__					, [0, 2]					, SCREAMING_SNAKE_CASE__   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, ['a', 'c']   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, [0, 2]   )

      # Out features selected from negative indices
      UpperCamelCase    ,		UpperCamelCase						    =					get_aligned_output_features_output_indices(SCREAMING_SNAKE_CASE__					, [-3, -1]					, SCREAMING_SNAKE_CASE__   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, ['a', 'c']   )
      self.assertEqual(SCREAMING_SNAKE_CASE__					, [-3, -1]   )

 def      __lowerCAmelCase  (						self			:			Tuple   ):






      """simple docstring"""



      with self.assertRaises(SCREAMING_SNAKE_CASE__   ):
           verify_out_features_out_indices(['a', 'b']					, (0, 1)					, SCREAMING_SNAKE_CASE__   )

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

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

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

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

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

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

      # Out features and out indices should be in order
      with self.assertRaises(SCREAMING_SNAKE_CASE__   ):
           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      __lowerCAmelCase  (						self			:			Dict   ):






      """simple docstring"""



      UpperCamelCase						    =					BackboneMixin()

      UpperCamelCase						    =					['a', 'b', 'c']
      UpperCamelCase						    =					['a', 'c']
      UpperCamelCase						    =					[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
      UpperCamelCase						    =					['a', 'b']
      self.assertEqual(backbone.out_features					, ['a', 'b']   )
      self.assertEqual(backbone.out_indices					, [0, 1]   )

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




# Copyright 2023 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

# rely on isort to merge the imports
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


_snake_case      = {
    '''configuration_efficientnet''': [
        '''EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''EfficientNetConfig''',
        '''EfficientNetOnnxConfig''',
    ]
}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case      = ['''EfficientNetImageProcessor''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 _snake_case      = [
     '''EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''EfficientNetForImageClassification''',
     '''EfficientNetModel''',
     '''EfficientNetPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_efficientnet import (
     EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP,
     EfficientNetConfig,
     EfficientNetOnnxConfig,
 )

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .image_processing_efficientnet import EfficientNetImageProcessor

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_efficientnet import (
      EFFICIENTNET_PRETRAINED_MODEL_ARCHIVE_LIST,
      EfficientNetForImageClassification,
      EfficientNetModel,
      EfficientNetPreTrainedModel,
  )

else:
 import sys

 _snake_case      = _LazyModule(__name__, globals()['''__file__'''], _import_structure)


