tensorflow/models

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

Summary

Maintainability
F
1 wk
Test Coverage

File preprocess_ops.py has 394 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/preprocess_ops.py - About 5 hrs to fix

    Function resize_to_range has a Cognitive Complexity of 12 (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/projects/centernet/ops/preprocess_ops.py - About 1 hr 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 random_square_crop_by_scale has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    def random_square_crop_by_scale(image,
                                    boxes,
                                    labels,
                                    max_border=128,
                                    scale_min=0.6,
    Severity: Minor
    Found in official/projects/centernet/ops/preprocess_ops.py - About 1 hr to fix

      Function random_square_crop_by_scale has 9 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def random_square_crop_by_scale(image,
      Severity: Major
      Found in official/projects/centernet/ops/preprocess_ops.py - About 1 hr 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/projects/centernet/ops/preprocess_ops.py - About 50 mins to fix

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

          def random_adjust_saturation(image,
          Severity: Minor
          Found in official/projects/centernet/ops/preprocess_ops.py - About 35 mins to fix

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

            def random_adjust_contrast(image,
            Severity: Minor
            Found in official/projects/centernet/ops/preprocess_ops.py - About 35 mins to fix

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

                  if image.get_shape().is_fully_defined():
                    if image.get_shape()[0] < image.get_shape()[1]:
                      new_image = _resize_landscape_image(image)
                    else:
                      new_image = _resize_portrait_image(image)
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 1 day to fix
              research/object_detection/core/preprocessor.py on lines 3050..3061

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

              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 pad_to_max_dimension:
                    channels = tf.unstack(new_image, axis=2)
                    if len(channels) != len(per_channel_pad_value):
                      raise ValueError('Number of channels must be equal to the length of '
                                       'per-channel pad value.')
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 1 day to fix
              research/object_detection/core/preprocessor.py on lines 3063..3077

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

              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 random_adjust_brightness(image,
                                           max_delta=0.2,
                                           seed=None,
                                           preprocess_vars_cache=None):
                """Randomly adjusts brightness.
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 1 day to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 419..454

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

              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 random_adjust_hue(image,
                                    max_delta=0.02,
                                    seed=None,
                                    preprocess_vars_cache=None):
                """Randomly adjusts hue.
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 1 day to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 339..374

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

              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 random_adjust_saturation(image,
                                           min_delta=0.8,
                                           max_delta=1.25,
                                           seed=None,
                                           preprocess_vars_cache=None):
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 1 day to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 377..416

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

              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 random_adjust_contrast(image,
                                         min_delta=0.8,
                                         max_delta=1.25,
                                         seed=None,
                                         preprocess_vars_cache=None):
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 1 day to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 457..496

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

              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 _get_or_create_preprocess_rand_vars(generator_func,
                                                      function_id,
                                                      preprocess_vars_cache,
                                                      key=''):
                """Returns a tensor stored in preprocess_vars_cache or using generator_func.
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 4 hrs to fix
              research/object_detection/core/preprocessor.py on lines 173..201

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

              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

                def y_function():
                  y = _random_integer(h_border,
                                      tf.cast(height, tf.int32) - h_border + 1,
                                      seed)
                  return y
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 3 other locations - About 1 hr to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 156..160
              research/object_detection/core/preprocessor.py on lines 4185..4189
              research/object_detection/core/preprocessor.py on lines 4191..4195

              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

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

                def x_function():
                  x = _random_integer(w_border,
                                      tf.cast(width, tf.int32) - w_border + 1,
                                      seed)
                  return x
              Severity: Major
              Found in official/projects/centernet/ops/preprocess_ops.py and 3 other locations - About 1 hr to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 150..154
              research/object_detection/core/preprocessor.py on lines 4185..4189
              research/object_detection/core/preprocessor.py on lines 4191..4195

              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

                image_box = [box_ymin / height, box_xmin / width,
                             box_ymax / height, box_xmax / width]
              Severity: Minor
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 40 mins to fix
              research/object_detection/core/preprocessor.py on lines 4242..4243

              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

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

                def _resize_landscape_image(image):
                  # resize a landscape image
                  return tf.image.resize(
                      image, tf.stack([min_dimension, max_dimension]), method=method,
              Severity: Minor
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 40 mins to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 279..282

              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

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

                def _resize_portrait_image(image):
                  # resize a portrait image
                  return tf.image.resize(
                      image, tf.stack([max_dimension, min_dimension]), method=method,
              Severity: Minor
              Found in official/projects/centernet/ops/preprocess_ops.py and 1 other location - About 40 mins to fix
              official/projects/centernet/ops/preprocess_ops.py on lines 273..276

              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