tensorflow/models

View on GitHub
official/vision/modeling/retinanet_model_test.py

Summary

Maintainability
F
4 days
Test Coverage

Function test_forward has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def test_forward(self, strategy, image_size, training, has_att_heads,
                   output_intermediate_features, soft_nms_sigma):
    """Test for creation of a R50-FPN RetinaNet."""
    tf_keras.backend.set_image_data_format('channels_last')
    num_classes = 3
Severity: Minor
Found in official/vision/modeling/retinanet_model_test.py - About 2 hrs 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

File retinanet_model_test.py has 282 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/vision/modeling/retinanet_model_test.py - About 2 hrs to fix

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

      def test_forward(self, strategy, image_size, training, has_att_heads,
    Severity: Minor
    Found in official/vision/modeling/retinanet_model_test.py - About 45 mins to fix

      Function test_build_model has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def test_build_model(self, use_separable_conv, build_anchor_boxes,
                             is_training, has_att_heads):
          num_classes = 3
          min_level = 3
          max_level = 7
      Severity: Minor
      Found in official/vision/modeling/retinanet_model_test.py - About 25 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 2 locations. Consider refactoring.
      Open

            for l in range(2, 6):
              self.assertIn('backbone_{}'.format(l), model_outputs)
              self.assertAllEqual([
                  2, image_size[0] // 2**l, image_size[1] // 2**l,
                  backbone.output_specs[str(l)].as_list()[-1]
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 1 other location - About 6 hrs to fix
      official/vision/modeling/retinanet_model_test.py on lines 272..277

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

      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

            for l in range(min_level, max_level + 1):
              self.assertIn('decoder_{}'.format(l), model_outputs)
              self.assertAllEqual([
                  2, image_size[0] // 2**l, image_size[1] // 2**l,
                  decoder.output_specs[str(l)].as_list()[-1]
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 1 other location - About 6 hrs to fix
      official/vision/modeling/retinanet_model_test.py on lines 266..271

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

      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

                for att in att_outputs.values():
                  self.assertAllEqual([
                      2, image_size[0] // 2**level, image_size[1] // 2**level,
                      1 * num_anchors_per_location
                  ], att[str(level)].numpy().shape)
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 1 other location - About 3 hrs to fix
      official/vision/modeling/retinanet_model_test.py on lines 234..239

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

      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

              self.assertAllEqual([
                  2,
                  image_size[0] // 2**level,
                  image_size[1] // 2**level,
                  4 * num_anchors_per_location
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 1 other location - About 3 hrs to fix
      official/vision/modeling/retinanet_model_test.py on lines 242..246

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

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

            for l in anchor_boxes:
              anchor_boxes[l] = tf.tile(
                  tf.expand_dims(anchor_boxes[l], axis=0), [2, 1, 1, 1])
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 2 other locations - About 1 hr to fix
      official/vision/modeling/maskrcnn_model_test.py on lines 69..71
      official/vision/modeling/retinanet_model_test.py on lines 178..180

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

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

            for l in anchor_boxes:
              anchor_boxes[l] = tf.tile(
                  tf.expand_dims(anchor_boxes[l], axis=0), [2, 1, 1, 1])
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 2 other locations - About 1 hr to fix
      official/vision/modeling/maskrcnn_model_test.py on lines 69..71
      official/vision/modeling/retinanet_model_test.py on lines 96..98

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

      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

          model = retinanet_model.RetinaNetModel(
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 3 other locations - About 55 mins to fix
      official/projects/pointpillars/modeling/models_test.py on lines 112..112
      research/object_detection/dataset_tools/seq_example_util_test.py on lines 133..133
      research/object_detection/models/keras_models/inception_resnet_v2_tf2_test.py on lines 119..119

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

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

          head = dense_prediction_heads.RetinaNetHead(
      Severity: Major
      Found in official/vision/modeling/retinanet_model_test.py and 5 other locations - About 40 mins to fix
      official/projects/assemblenet/modeling/assemblenet_plus_test.py on lines 66..66
      research/object_detection/builders/box_predictor_builder.py on lines 507..507
      research/object_detection/models/keras_models/inception_resnet_v2_tf2_test.py on lines 146..146
      research/object_detection/models/keras_models/mobilenet_v1_tf2_test.py on lines 103..103
      research/object_detection/models/keras_models/mobilenet_v2_tf2_test.py on lines 94..94

      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

            if has_att_heads:
              attribute_heads = [
                  dict(
                      name='depth',
                      type='regression',
      Severity: Minor
      Found in official/vision/modeling/retinanet_model_test.py and 1 other location - About 30 mins to fix
      official/vision/modeling/retinanet_model_test.py on lines 102..108

      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

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

          if has_att_heads:
            attribute_heads = [
                dict(
                    name='depth', type='regression', size=1, prediction_tower_name='')
            ]
      Severity: Minor
      Found in official/vision/modeling/retinanet_model_test.py and 1 other location - About 30 mins to fix
      official/vision/modeling/retinanet_model_test.py on lines 188..197

      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