tensorflow/models

View on GitHub
official/projects/yolo/ops/mosaic.py

Summary

Maintainability
F
3 days
Test Coverage

File mosaic.py has 437 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/yolo/ops/mosaic.py - About 6 hrs to fix

    Function __init__ has 19 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(
    Severity: Major
    Found in official/projects/yolo/ops/mosaic.py - About 2 hrs to fix

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

        def _augment_image(
      Severity: Major
      Found in official/projects/yolo/ops/mosaic.py - About 1 hr to fix

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

          def _update_patched_sample(
        Severity: Major
        Found in official/projects/yolo/ops/mosaic.py - About 50 mins to fix

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

            def _mosaic(self, *patch_samples):
              """Builds a 2x2 or 3x3 mosaic."""
              if self._mosaic_frequency >= 1.0:
                mosaic_prob = 1.0
              else:
          Severity: Minor
          Found in official/projects/yolo/ops/mosaic.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 _mosaic_crop_image has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

            def _mosaic_crop_image(
          Severity: Minor
          Found in official/projects/yolo/ops/mosaic.py - About 45 mins to fix

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

              def _patch(self, patches, ishape, num_rows, num_cols, mosaic_center):
            Severity: Minor
            Found in official/projects/yolo/ops/mosaic.py - About 35 mins to fix

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

                def scale_boxes(self, patch, ishape, boxes, x_offset, y_offset):
              Severity: Minor
              Found in official/projects/yolo/ops/mosaic.py - About 35 mins to fix

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

                  def _process_image(self, sample, shiftx, shifty, cut, letter_box):
                Severity: Minor
                Found in official/projects/yolo/ops/mosaic.py - About 35 mins to fix

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

                        cut_y = preprocessing_ops.random_uniform_strong(
                            self._output_size[0] * min_offset,
                            self._output_size[0] * (1 - min_offset),
                            seed=self._seed)
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 1 other location - About 2 hrs to fix
                  official/projects/yolo/ops/mosaic.py on lines 122..125

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

                  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

                        cut_x = preprocessing_ops.random_uniform_strong(
                            self._output_size[1] * min_offset,
                            self._output_size[1] * (1 - min_offset),
                            seed=self._seed)
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 1 other location - About 2 hrs to fix
                  official/projects/yolo/ops/mosaic.py on lines 126..129

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

                  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

                        ch = tf.math.round(
                            preprocessing_ops.random_uniform_strong(
                                -center[0], center[0], seed=self._seed))
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 1 other location - About 1 hr to fix
                  official/projects/yolo/ops/mosaic.py on lines 218..220

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

                  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

                        cw = tf.math.round(
                            preprocessing_ops.random_uniform_strong(
                                -center[1], center[1], seed=self._seed))
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 1 other location - About 1 hr to fix
                  official/projects/yolo/ops/mosaic.py on lines 215..217

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

                  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

                        sample['groundtruth_is_crowd'] = tf.concat(
                            [one['groundtruth_is_crowd'], two['groundtruth_is_crowd']], axis=0)
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 3 other locations - About 50 mins to fix
                  official/projects/yolo/ops/mosaic.py on lines 450..451
                  official/projects/yolo/ops/mosaic.py on lines 452..453
                  official/projects/yolo/ops/mosaic.py on lines 456..457

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

                  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

                        sample['groundtruth_area'] = tf.concat(
                            [one['groundtruth_area'], two['groundtruth_area']], axis=0)
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 3 other locations - About 50 mins to fix
                  official/projects/yolo/ops/mosaic.py on lines 450..451
                  official/projects/yolo/ops/mosaic.py on lines 452..453
                  official/projects/yolo/ops/mosaic.py on lines 454..455

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

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

                      image, _, affine = preprocessing_ops.affine_warp_image(
                          image, [self._output_size[0], self._output_size[1]],
                          scale_min=self._aug_scale_min,
                          scale_max=self._aug_scale_max,
                          translate=self._aug_rand_translate,
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 4 other locations - About 50 mins to fix
                  official/nlp/modeling/layers/relative_attention.py on lines 135..142
                  official/projects/yolo/modeling/layers/nn_blocks.py on lines 1911..1921
                  research/audioset/vggish/vggish_input.py on lines 61..69
                  research/pcl_rl/trainer.py on lines 309..316

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

                  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

                        sample['groundtruth_boxes'] = tf.concat(
                            [one['groundtruth_boxes'], two['groundtruth_boxes']], axis=0)
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 3 other locations - About 50 mins to fix
                  official/projects/yolo/ops/mosaic.py on lines 452..453
                  official/projects/yolo/ops/mosaic.py on lines 454..455
                  official/projects/yolo/ops/mosaic.py on lines 456..457

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

                  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

                        sample['groundtruth_classes'] = tf.concat(
                            [one['groundtruth_classes'], two['groundtruth_classes']], axis=0)
                  Severity: Major
                  Found in official/projects/yolo/ops/mosaic.py and 3 other locations - About 50 mins to fix
                  official/projects/yolo/ops/mosaic.py on lines 450..451
                  official/projects/yolo/ops/mosaic.py on lines 454..455
                  official/projects/yolo/ops/mosaic.py on lines 456..457

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

                  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

                      self._seed = seed if seed is not None else random.randint(0, 2**30)
                  Severity: Minor
                  Found in official/projects/yolo/ops/mosaic.py and 1 other location - About 30 mins to fix
                  official/projects/maskconver/modeling/layers/copypaste.py on lines 105..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 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