tensorflow/models

View on GitHub
official/projects/centernet/ops/box_list_ops.py

Summary

Maintainability
F
1 wk
Test Coverage

File box_list_ops.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/projects/centernet/ops/box_list_ops.py - About 2 hrs to fix

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

    def gather(boxlist, indices, fields=None, use_static_shapes=False):
      """Gather boxes from BoxList according to indices and return new BoxList.
    
      By default, `gather` returns boxes corresponding to the input index list, as
      well as all additional fields stored in the boxlist (indexing into the
    Severity: Minor
    Found in official/projects/centernet/ops/box_list_ops.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 to_absolute_coordinates has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def to_absolute_coordinates(boxlist,
    Severity: Minor
    Found in official/projects/centernet/ops/box_list_ops.py - About 35 mins to fix

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

        with tf.name_scope('ClipToWindow'):
          y_min, x_min, y_max, x_max = tf.split(
              value=boxlist.get(), num_or_size_splits=4, axis=1)
          win_y_min = window[0]
          win_x_min = window[1]
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 1 other location - About 2 days to fix
      research/object_detection/core/box_list_ops.py on lines 151..171

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

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

        with tf.name_scope('Scale'):
          y_scale = tf.cast(y_scale, tf.float32)
          x_scale = tf.cast(x_scale, tf.float32)
          y_min, x_min, y_max, x_max = tf.split(
              value=boxlist.get(), num_or_size_splits=4, axis=1)
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 3 other locations - About 1 day to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 92..103
      official/vision/utils/object_detection/preprocessor.py on lines 457..468
      research/object_detection/core/box_list_ops.py on lines 94..105

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

      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

        with tf.name_scope('ChangeCoordinateFrame'):
          win_height = window[2] - window[0]
          win_width = window[3] - window[1]
          boxlist_new = scale(box_list.BoxList(
              boxlist.get() - [window[0], window[1], window[0], window[1]]),
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 2 other locations - About 1 day to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 394..402
      research/object_detection/core/box_list_ops.py on lines 462..469

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

      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

        with tf.name_scope('ToAbsoluteCoordinates'):
          height = tf.cast(height, tf.float32)
          width = tf.cast(width, tf.float32)
      
          # Ensure range of input boxes is correct.
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 2 other locations - About 6 hrs to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 845..860
      research/object_detection/core/box_list_ops.py on lines 906..920

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

        with tf.name_scope('MatMulGather'):
          params_shape = sampling_ops.combined_static_and_dynamic_shape(params)
          indices_shape = sampling_ops.combined_static_and_dynamic_shape(indices)
          params2d = tf.reshape(params, [params_shape[0], -1])
          indicator_matrix = tf.one_hot(indices, params_shape[0])
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 2 other locations - About 6 hrs to fix
      official/vision/utils/object_detection/ops.py on lines 74..81
      research/object_detection/utils/ops.py on lines 1026..1033

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

      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

        with tf.name_scope('HeightWidth'):
          y_min, x_min, y_max, x_max = tf.split(
              value=boxlist.get(), num_or_size_splits=4, axis=1)
          return tf.squeeze(y_max - y_min, [1]), tf.squeeze(x_max - x_min, [1])
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 2 other locations - About 3 hrs to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 74..77
      research/object_detection/core/box_list_ops.py on lines 76..79

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

      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

        with tf.name_scope('PruneSmallBoxes'):
          height, width = height_width(boxlist)
          is_valid = tf.logical_and(tf.greater_equal(width, min_side),
                                    tf.greater_equal(height, min_side))
          return gather(boxlist, tf.reshape(tf.where(is_valid), [-1]))
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 2 other locations - About 3 hrs to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 367..371
      research/object_detection/core/box_list_ops.py on lines 435..439

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

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

        with tf.name_scope('Area'):
          y_min, x_min, y_max, x_max = tf.split(
              value=boxlist.get(), num_or_size_splits=4, axis=1)
          return tf.squeeze((y_max - y_min) * (x_max - x_min), [1])
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 3 other locations - About 2 hrs to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 57..60
      official/vision/utils/object_detection/region_similarity_calculator.py on lines 38..41
      research/object_detection/core/box_list_ops.py on lines 59..62

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

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

      def _copy_extra_fields(boxlist_to_copy_to, boxlist_to_copy_from):
        """Copies the extra fields of boxlist_to_copy_from to boxlist_to_copy_to.
      
        Args:
          boxlist_to_copy_to: BoxList to which extra fields are copied.
      Severity: Major
      Found in official/projects/centernet/ops/box_list_ops.py and 4 other locations - About 1 hr to fix
      official/vision/utils/object_detection/box_list_ops.py on lines 764..776
      official/vision/utils/object_detection/preprocessor.py on lines 428..440
      research/object_detection/core/box_list_ops.py on lines 829..841
      research/object_detection/utils/np_box_list_ops.py on lines 545..557

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

      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