tensorflow/models

View on GitHub
official/legacy/image_classification/resnet/resnet_model.py

Summary

Maintainability
D
2 days
Test Coverage

File resnet_model.py has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2024 The TensorFlow Authors. 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
Severity: Minor
Found in official/legacy/image_classification/resnet/resnet_model.py - About 2 hrs to fix

    Function resnet50 has 30 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def resnet50(num_classes,
                 batch_size=None,
                 use_l2_regularizer=True,
                 rescale_inputs=False,
                 batch_norm_decay=0.9,
    Severity: Minor
    Found in official/legacy/image_classification/resnet/resnet_model.py - About 1 hr to fix

      Function conv_block has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def conv_block(input_tensor,
      Severity: Major
      Found in official/legacy/image_classification/resnet/resnet_model.py - About 1 hr to fix

        Function identity_block has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def identity_block(input_tensor,
        Severity: Major
        Found in official/legacy/image_classification/resnet/resnet_model.py - About 1 hr to fix

          Function resnet50 has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def resnet50(num_classes,
          Severity: Minor
          Found in official/legacy/image_classification/resnet/resnet_model.py - About 45 mins to fix

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

              if tf_keras.backend.image_data_format() == 'channels_first':
                x = layers.Permute((3, 1, 2))(x)
                bn_axis = 1
              else:  # channels_last
                bn_axis = 3
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 1 other location - About 1 hr to fix
            official/legacy/image_classification/vgg/vgg_model.py on lines 56..60

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 46.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 4 locations. Consider refactoring.
            Open

              x = layers.Conv2D(
                  filters3, (1, 1),
                  use_bias=False,
                  kernel_initializer='he_normal',
                  kernel_regularizer=_gen_l2_regularizer(use_l2_regularizer),
            official/legacy/image_classification/resnet/resnet_model.py on lines 72..77
            official/legacy/image_classification/resnet/resnet_model.py on lines 104..109
            official/legacy/image_classification/resnet/resnet_model.py on lines 160..165

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 42.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 4 locations. Consider refactoring.
            Open

              x = layers.Conv2D(
                  filters3, (1, 1),
                  use_bias=False,
                  kernel_initializer='he_normal',
                  kernel_regularizer=_gen_l2_regularizer(use_l2_regularizer),
            official/legacy/image_classification/resnet/resnet_model.py on lines 72..77
            official/legacy/image_classification/resnet/resnet_model.py on lines 160..165
            official/legacy/image_classification/resnet/resnet_model.py on lines 193..198

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 42.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 4 locations. Consider refactoring.
            Open

              x = layers.Conv2D(
                  filters1, (1, 1),
                  use_bias=False,
                  kernel_initializer='he_normal',
                  kernel_regularizer=_gen_l2_regularizer(use_l2_regularizer),
            official/legacy/image_classification/resnet/resnet_model.py on lines 72..77
            official/legacy/image_classification/resnet/resnet_model.py on lines 104..109
            official/legacy/image_classification/resnet/resnet_model.py on lines 193..198

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 42.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 4 locations. Consider refactoring.
            Open

              x = layers.Conv2D(
                  filters1, (1, 1),
                  use_bias=False,
                  kernel_initializer='he_normal',
                  kernel_regularizer=_gen_l2_regularizer(use_l2_regularizer),
            official/legacy/image_classification/resnet/resnet_model.py on lines 104..109
            official/legacy/image_classification/resnet/resnet_model.py on lines 160..165
            official/legacy/image_classification/resnet/resnet_model.py on lines 193..198

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 42.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              shortcut = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '1')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 79..83
            official/legacy/image_classification/resnet/resnet_model.py on lines 96..100
            official/legacy/image_classification/resnet/resnet_model.py on lines 111..115
            official/legacy/image_classification/resnet/resnet_model.py on lines 167..171
            official/legacy/image_classification/resnet/resnet_model.py on lines 185..189
            official/legacy/image_classification/resnet/resnet_model.py on lines 200..204

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              x = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '2a')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 96..100
            official/legacy/image_classification/resnet/resnet_model.py on lines 111..115
            official/legacy/image_classification/resnet/resnet_model.py on lines 167..171
            official/legacy/image_classification/resnet/resnet_model.py on lines 185..189
            official/legacy/image_classification/resnet/resnet_model.py on lines 200..204
            official/legacy/image_classification/resnet/resnet_model.py on lines 215..219

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              x = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '2a')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 79..83
            official/legacy/image_classification/resnet/resnet_model.py on lines 96..100
            official/legacy/image_classification/resnet/resnet_model.py on lines 111..115
            official/legacy/image_classification/resnet/resnet_model.py on lines 185..189
            official/legacy/image_classification/resnet/resnet_model.py on lines 200..204
            official/legacy/image_classification/resnet/resnet_model.py on lines 215..219

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              x = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '2b')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 79..83
            official/legacy/image_classification/resnet/resnet_model.py on lines 96..100
            official/legacy/image_classification/resnet/resnet_model.py on lines 111..115
            official/legacy/image_classification/resnet/resnet_model.py on lines 167..171
            official/legacy/image_classification/resnet/resnet_model.py on lines 200..204
            official/legacy/image_classification/resnet/resnet_model.py on lines 215..219

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              x = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '2b')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 79..83
            official/legacy/image_classification/resnet/resnet_model.py on lines 111..115
            official/legacy/image_classification/resnet/resnet_model.py on lines 167..171
            official/legacy/image_classification/resnet/resnet_model.py on lines 185..189
            official/legacy/image_classification/resnet/resnet_model.py on lines 200..204
            official/legacy/image_classification/resnet/resnet_model.py on lines 215..219

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              x = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '2c')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 79..83
            official/legacy/image_classification/resnet/resnet_model.py on lines 96..100
            official/legacy/image_classification/resnet/resnet_model.py on lines 167..171
            official/legacy/image_classification/resnet/resnet_model.py on lines 185..189
            official/legacy/image_classification/resnet/resnet_model.py on lines 200..204
            official/legacy/image_classification/resnet/resnet_model.py on lines 215..219

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              x = layers.BatchNormalization(
                  axis=bn_axis,
                  momentum=batch_norm_decay,
                  epsilon=batch_norm_epsilon,
                  name=bn_name_base + '2c')(
            Severity: Major
            Found in official/legacy/image_classification/resnet/resnet_model.py and 6 other locations - About 30 mins to fix
            official/legacy/image_classification/resnet/resnet_model.py on lines 79..83
            official/legacy/image_classification/resnet/resnet_model.py on lines 96..100
            official/legacy/image_classification/resnet/resnet_model.py on lines 111..115
            official/legacy/image_classification/resnet/resnet_model.py on lines 167..171
            official/legacy/image_classification/resnet/resnet_model.py on lines 185..189
            official/legacy/image_classification/resnet/resnet_model.py on lines 215..219

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 32.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status