tensorflow/models

View on GitHub
official/legacy/detection/ops/roi_ops.py

Summary

Maintainability
F
6 days
Test Coverage

File roi_ops.py has 407 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/detection/ops/roi_ops.py - About 5 hrs to fix

    Function oln_multilevel_propose_rois has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

      def oln_multilevel_propose_rois(self,
                                      rpn_boxes,
                                      rpn_scores,
                                      anchor_boxes,
                                      image_shape,
    Severity: Minor
    Found in official/legacy/detection/ops/roi_ops.py - About 3 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

    Function multilevel_propose_rois has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

    def multilevel_propose_rois(rpn_boxes,
                                rpn_scores,
                                anchor_boxes,
                                image_shape,
                                rpn_pre_nms_top_k=2000,
    Severity: Minor
    Found in official/legacy/detection/ops/roi_ops.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

    Function oln_multilevel_propose_rois has 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def oln_multilevel_propose_rois(self,
    Severity: Major
    Found in official/legacy/detection/ops/roi_ops.py - About 1 hr to fix

      Function multilevel_propose_rois has 13 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def multilevel_propose_rois(rpn_boxes,
      Severity: Major
      Found in official/legacy/detection/ops/roi_ops.py - About 1 hr to fix

        Function __call__ has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def __call__(self, boxes, scores, anchor_boxes, image_shape, is_training,
        Severity: Major
        Found in official/legacy/detection/ops/roi_ops.py - About 50 mins to fix

          Avoid deeply nested control flow statements.
          Open

                      if is_box_lrtb:  # Box in left-right-top-bottom format.
                        this_level_boxes = box_utils.decode_boxes_lrtb(
                            this_level_boxes, this_level_anchors)
                      else:  # Box in standard x-y-h-w format.
                        this_level_boxes = box_utils.decode_boxes(
          Severity: Major
          Found in official/legacy/detection/ops/roi_ops.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      if use_batched_nms:
                        this_level_rois, this_level_roi_scores, _, _ = (
                            tf.image.combined_non_max_suppression(
                                tf.expand_dims(this_level_boxes, axis=2),
                                tf.expand_dims(this_level_scores, axis=-1),
            Severity: Major
            Found in official/legacy/detection/ops/roi_ops.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                          if use_batched_nms:
                            this_level_rois, this_level_roi_scores, _, _ = (
                                tf.image.combined_non_max_suppression(
                                    tf.expand_dims(this_level_boxes, axis=2),
                                    tf.expand_dims(this_level_scores, axis=-1),
              Severity: Major
              Found in official/legacy/detection/ops/roi_ops.py - About 45 mins to fix

                Function call has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def call(self, boxes, scores, anchor_boxes, image_shape, is_training):
                Severity: Minor
                Found in official/legacy/detection/ops/roi_ops.py - About 35 mins to fix

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

                            if rpn_nms_threshold > 0.0:
                              if use_batched_nms:
                                this_level_rois, this_level_roi_scores, _, _ = (
                                    tf.image.combined_non_max_suppression(
                                        tf.expand_dims(this_level_boxes, axis=2),
                  Severity: Major
                  Found in official/legacy/detection/ops/roi_ops.py and 1 other location - About 1 day to fix
                  official/legacy/detection/ops/roi_ops.py on lines 127..155

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

                  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 rpn_nms_threshold > 0.0:
                            if use_batched_nms:
                              this_level_rois, this_level_roi_scores, _, _ = (
                                  tf.image.combined_non_max_suppression(
                                      tf.expand_dims(this_level_boxes, axis=2),
                  Severity: Major
                  Found in official/legacy/detection/ops/roi_ops.py and 1 other location - About 1 day to fix
                  official/legacy/detection/ops/roi_ops.py on lines 424..453

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

                  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

                      with tf.name_scope('top_k_rois'):
                        _, num_valid_rois = all_roi_scores.get_shape().as_list()
                        overall_top_k = min(num_valid_rois, rpn_post_nms_top_k)
                  
                        selected_rois, selected_roi_scores = box_utils.top_k_boxes(
                  Severity: Major
                  Found in official/legacy/detection/ops/roi_ops.py and 1 other location - About 2 hrs to fix
                  official/legacy/detection/ops/roi_ops.py on lines 461..466

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

                  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

                        with tf.name_scope('top_k_rois'):
                          _, num_valid_rois = all_roi_scores.get_shape().as_list()
                          overall_top_k = min(num_valid_rois, rpn_post_nms_top_k)
                  
                          selected_rois, selected_roi_scores = box_utils.top_k_boxes(
                  Severity: Major
                  Found in official/legacy/detection/ops/roi_ops.py and 1 other location - About 2 hrs to fix
                  official/legacy/detection/ops/roi_ops.py on lines 163..168

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

                  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

                          this_level_anchors = tf.cast(
                              tf.reshape(anchor_boxes[level], [-1, num_boxes, 4]),
                              dtype=this_level_scores.dtype)
                  Severity: Minor
                  Found in official/legacy/detection/ops/roi_ops.py and 1 other location - About 40 mins to fix
                  official/legacy/detection/ops/roi_ops.py on lines 390..392

                  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

                            this_level_anchors = tf.cast(
                                tf.reshape(anchor_boxes[level], [-1, num_boxes, 4]),
                                dtype=this_level_scores.dtype)
                  Severity: Minor
                  Found in official/legacy/detection/ops/roi_ops.py and 1 other location - About 40 mins to fix
                  official/legacy/detection/ops/roi_ops.py on lines 107..109

                  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