tensorflow/models

View on GitHub
research/object_detection/utils/bifpn_utils.py

Summary

Maintainability
D
2 days
Test Coverage

File bifpn_utils.py has 298 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2020 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 research/object_detection/utils/bifpn_utils.py - About 3 hrs to fix

    Function create_conv_block has 12 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def create_conv_block(name, num_filters, kernel_size, strides, padding,
    Severity: Major
    Found in research/object_detection/utils/bifpn_utils.py - About 1 hr to fix

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

      def create_resample_feature_map_ops(input_scale_factor, output_scale_factor,
      Severity: Major
      Found in research/object_detection/utils/bifpn_utils.py - About 1 hr to fix

        Function build has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def build(self, input_shape):
            if not isinstance(input_shape, list):
              raise ValueError('A BiFPN combine layer should be called '
                               'on a list of inputs.')
            if len(input_shape) < 2:
        Severity: Minor
        Found in research/object_detection/utils/bifpn_utils.py - About 45 mins to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

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

        def create_downsample_feature_map_ops(scale, downsample_method,
        Severity: Minor
        Found in research/object_detection/utils/bifpn_utils.py - About 45 mins to fix

          Function create_conv_block has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def create_conv_block(name, num_filters, kernel_size, strides, padding,
                                use_separable, apply_batchnorm, apply_activation,
                                conv_hyperparams, is_training, freeze_batchnorm,
                                conv_bn_act_pattern=True):
            """Create Keras layers for regular or separable convolutions.
          Severity: Minor
          Found in research/object_detection/utils/bifpn_utils.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function create_resample_feature_map_ops has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def create_resample_feature_map_ops(input_scale_factor, output_scale_factor,
                                              downsample_method, use_native_resize_op,
                                              conv_hyperparams, is_training,
                                              freeze_batchnorm, name):
            """Creates Keras layers for downsampling or upsampling feature maps.
          Severity: Minor
          Found in research/object_detection/utils/bifpn_utils.py - About 35 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

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

              layers.append(
                  tf.keras.layers.DepthwiseConv2D(
                      kernel_size=kernel_size,
                      strides=stride,
                      padding=padding,
          Severity: Major
          Found in research/object_detection/utils/bifpn_utils.py and 2 other locations - About 1 hr to fix
          research/object_detection/utils/bifpn_utils.py on lines 138..144
          research/object_detection/utils/bifpn_utils.py on lines 145..151

          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 3 locations. Consider refactoring.
          Open

            elif downsample_method == 'avg_pooling':
              layers.append(
                  tf.keras.layers.AveragePooling2D(
                      pool_size=kernel_size,
                      strides=stride,
          Severity: Major
          Found in research/object_detection/utils/bifpn_utils.py and 2 other locations - About 1 hr to fix
          research/object_detection/utils/bifpn_utils.py on lines 138..144
          research/object_detection/utils/bifpn_utils.py on lines 153..158

          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 3 locations. Consider refactoring.
          Open

            if downsample_method == 'max_pooling':
              layers.append(
                  tf.keras.layers.MaxPooling2D(
                      pool_size=kernel_size,
                      strides=stride,
          Severity: Major
          Found in research/object_detection/utils/bifpn_utils.py and 2 other locations - About 1 hr to fix
          research/object_detection/utils/bifpn_utils.py on lines 145..151
          research/object_detection/utils/bifpn_utils.py on lines 153..158

          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

            if apply_batchnorm:
              layers.append(
                  conv_hyperparams.build_batch_norm(
                      training=(is_training and not freeze_batchnorm),
                      name=name + 'batchnorm'))
          Severity: Major
          Found in research/object_detection/utils/bifpn_utils.py and 6 other locations - About 45 mins to fix
          research/object_detection/models/feature_map_generators.py on lines 109..112
          research/object_detection/models/feature_map_generators.py on lines 235..238
          research/object_detection/models/feature_map_generators.py on lines 266..269
          research/object_detection/models/feature_map_generators.py on lines 279..282
          research/object_detection/models/feature_map_generators.py on lines 295..298
          research/object_detection/utils/bifpn_utils.py on lines 159..162

          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 35.

          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

              layers.append(
                  conv_hyperparams.build_batch_norm(
                      training=(is_training and not freeze_batchnorm),
                      name=name + 'downsample_batchnorm'))
          Severity: Major
          Found in research/object_detection/utils/bifpn_utils.py and 6 other locations - About 45 mins to fix
          research/object_detection/models/feature_map_generators.py on lines 109..112
          research/object_detection/models/feature_map_generators.py on lines 235..238
          research/object_detection/models/feature_map_generators.py on lines 266..269
          research/object_detection/models/feature_map_generators.py on lines 279..282
          research/object_detection/models/feature_map_generators.py on lines 295..298
          research/object_detection/utils/bifpn_utils.py on lines 92..96

          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 35.

          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 2 locations. Consider refactoring.
          Open

              layers.append(
                  tf.keras.layers.Lambda(
                      resize_nearest_neighbor,
                      name=name + 'nearest_neighbor_upsampling_x{}'.format(scale)))
          Severity: Minor
          Found in research/object_detection/utils/bifpn_utils.py and 1 other location - About 45 mins to fix
          research/object_detection/utils/bifpn_utils.py on lines 204..207

          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 35.

          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 2 locations. Consider refactoring.
          Open

              layers.append(
                  tf.keras.layers.Lambda(
                      nearest_neighbor_upsampling,
                      name=name + 'nearest_neighbor_upsampling_x{}'.format(scale)))
          Severity: Minor
          Found in research/object_detection/utils/bifpn_utils.py and 1 other location - About 45 mins to fix
          research/object_detection/utils/bifpn_utils.py on lines 195..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 35.

          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

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

              return tf.squeeze(
                  tf.linalg.matmul(tf.stack(inputs, axis=-1), normalized_weights),
                  axis=[-1])
          Severity: Minor
          Found in research/object_detection/utils/bifpn_utils.py and 1 other location - About 40 mins to fix
          research/object_detection/utils/bifpn_utils.py on lines 298..300

          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 34.

          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

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

              return tf.squeeze(
                  tf.linalg.matmul(tf.stack(inputs, axis=-1), normalized_weights),
                  axis=[-1])
          Severity: Minor
          Found in research/object_detection/utils/bifpn_utils.py and 1 other location - About 40 mins to fix
          research/object_detection/utils/bifpn_utils.py on lines 306..308

          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 34.

          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