tensorflow/models

View on GitHub
official/vision/utils/object_detection/preprocessor.py

Summary

Maintainability
F
5 days
Test Coverage

File preprocessor.py has 399 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/utils/object_detection/preprocessor.py - About 5 hrs to fix

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

    def resize_to_range(image,
    Severity: Major
    Found in official/vision/utils/object_detection/preprocessor.py - About 50 mins to fix

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

      def random_horizontal_flip(image,
      Severity: Minor
      Found in official/vision/utils/object_detection/preprocessor.py - About 45 mins to fix

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

        def resize_to_range(image,
                            masks=None,
                            min_dimension=None,
                            max_dimension=None,
                            method=tf.image.ResizeMethod.BILINEAR,
        Severity: Minor
        Found in official/vision/utils/object_detection/preprocessor.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

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

          with tf.name_scope(scope):
            y, x = tf.split(value=keypoints, num_or_size_splits=2, axis=2)
            win_y_min, win_x_min, win_y_max, win_x_max = tf.unstack(window)
        
            valid_indices = tf.logical_and(
        Severity: Major
        Found in official/vision/utils/object_detection/preprocessor.py and 1 other location - About 1 day to fix
        research/object_detection/core/keypoint_ops.py on lines 88..100

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

        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(scope):
            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/vision/utils/object_detection/preprocessor.py and 3 other locations - About 1 day to fix
        official/projects/centernet/ops/box_list_ops.py on lines 49..60
        official/vision/utils/object_detection/box_list_ops.py on lines 92..103
        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

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

        def _flip_boxes_left_right(boxes):
          """Left-right flip the boxes.
        
          Args:
            boxes: rank 2 float32 tensor containing the bounding boxes -> [N, 4]. Boxes
        Severity: Major
        Found in official/vision/utils/object_detection/preprocessor.py and 1 other location - About 4 hrs to fix
        research/object_detection/core/preprocessor.py on lines 484..500

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

        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(scope):
            y_scale = tf.cast(y_scale, tf.float32)
            x_scale = tf.cast(x_scale, tf.float32)
            new_keypoints = keypoints * [[[y_scale, x_scale]]]
            return new_keypoints
        Severity: Major
        Found in official/vision/utils/object_detection/preprocessor.py and 1 other location - About 2 hrs to fix
        research/object_detection/core/keypoint_ops.py on lines 40..44

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

        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

            if boxes is not None:
              boxes = tf.cond(
                  pred=do_a_flip_random,
                  true_fn=lambda: _flip_boxes_left_right(boxes),
                  false_fn=lambda: boxes)
        Severity: Major
        Found in official/vision/utils/object_detection/preprocessor.py and 1 other location - About 2 hrs to fix
        official/vision/utils/object_detection/preprocessor.py on lines 252..257

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

        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

            if masks is not None:
              masks = tf.cond(
                  pred=do_a_flip_random,
                  true_fn=lambda: _flip_masks_left_right(masks),
                  false_fn=lambda: masks)
        Severity: Major
        Found in official/vision/utils/object_detection/preprocessor.py and 1 other location - About 2 hrs to fix
        official/vision/utils/object_detection/preprocessor.py on lines 244..249

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

        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/vision/utils/object_detection/preprocessor.py and 4 other locations - About 1 hr to fix
        official/projects/centernet/ops/box_list_ops.py on lines 23..35
        official/vision/utils/object_detection/box_list_ops.py on lines 764..776
        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

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

            new_keypoints = box_list_ops.scale(keypoints - [window[0], window[1]],
                                               1.0 / win_height, 1.0 / win_width)
        Severity: Minor
        Found in official/vision/utils/object_detection/preprocessor.py and 1 other location - About 55 mins to fix
        research/object_detection/core/keypoint_ops.py on lines 127..128

        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

        There are no issues that match your filters.

        Category
        Status