tensorflow/models

View on GitHub
research/object_detection/utils/ops.py

Summary

Maintainability
F
1 wk
Test Coverage

File ops.py has 977 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2017 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: Major
Found in research/object_detection/utils/ops.py - About 2 days to fix

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

    def position_sensitive_crop_regions(image,
                                        boxes,
                                        crop_size,
                                        num_spatial_bins,
                                        global_pool):
    Severity: Minor
    Found in research/object_detection/utils/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 retain_groundtruth has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def retain_groundtruth(tensor_dict, valid_indices):
      """Retains groundtruth by valid indices.
    
      Args:
        tensor_dict: a dictionary of following groundtruth tensors -
    Severity: Minor
    Found in research/object_detection/utils/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 normalize_to_target has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def normalize_to_target(inputs,
                            target_norm_value,
                            dim,
                            epsilon=1e-7,
                            trainable=True,
    Severity: Minor
    Found in research/object_detection/utils/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 bfloat16_to_float32_nested has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def bfloat16_to_float32_nested(input_nested):
      """Convert float32 tensors in a nested structure to bfloat16.
    
      Args:
        input_nested: A Python dict, values being Tensor or Python list/tuple of
    Severity: Minor
    Found in research/object_detection/utils/ops.py - About 55 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 pad_to_multiple has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def pad_to_multiple(tensor, multiple):
      """Returns the tensor zero padded to the specified multiple.
    
      Appends 0s to the end of the first and second dimension (height and width) of
      the tensor until both dimensions are a multiple of the input argument
    Severity: Minor
    Found in research/object_detection/utils/ops.py - About 55 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 normalize_to_target has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def normalize_to_target(inputs,
    Severity: Major
    Found in research/object_detection/utils/ops.py - About 50 mins to fix

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

      def batch_position_sensitive_crop_regions(images,
      Severity: Minor
      Found in research/object_detection/utils/ops.py - About 45 mins to fix

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

        def merge_boxes_with_multiple_labels(boxes,
        Severity: Minor
        Found in research/object_detection/utils/ops.py - About 35 mins to fix

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

          def position_sensitive_crop_regions(image,
          Severity: Minor
          Found in research/object_detection/utils/ops.py - About 35 mins to fix

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

            def reframe_box_masks_to_image_masks(box_masks, boxes, image_height,
            Severity: Minor
            Found in research/object_detection/utils/ops.py - About 35 mins to fix

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

              def nearest_neighbor_upsampling(input_tensor, scale=None, height_scale=None,
              Severity: Minor
              Found in research/object_detection/utils/ops.py - About 35 mins to fix

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

                def indices_to_dense_vector(indices,
                Severity: Minor
                Found in research/object_detection/utils/ops.py - About 35 mins to fix

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

                    if tensor_height is None:
                      tensor_height = tf.shape(tensor)[1]
                      padded_tensor_height = tf.cast(
                          tf.ceil(
                              tf.cast(tensor_height, dtype=tf.float32) /
                  Severity: Major
                  Found in research/object_detection/utils/ops.py and 1 other location - About 7 hrs to fix
                  research/object_detection/utils/ops.py on lines 200..209

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

                  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 tensor_width is None:
                      tensor_width = tf.shape(tensor)[2]
                      padded_tensor_width = tf.cast(
                          tf.ceil(
                              tf.cast(tensor_width, dtype=tf.float32) /
                  Severity: Major
                  Found in research/object_detection/utils/ops.py and 1 other location - About 7 hrs to fix
                  research/object_detection/utils/ops.py on lines 189..198

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

                  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

                  def indices_to_dense_vector(indices,
                                              size,
                                              indices_value=1.,
                                              default_value=0,
                                              dtype=tf.float32):
                  Severity: Major
                  Found in research/object_detection/utils/ops.py and 2 other locations - About 7 hrs to fix
                  official/vision/ops/sampling_ops.py on lines 61..90
                  official/vision/utils/object_detection/ops.py on lines 25..54

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

                  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

                  def fixed_padding(inputs, kernel_size, rate=1):
                    """Pads the input along the spatial dimensions independently of input size.
                  
                    Args:
                      inputs: A tensor of size [batch, height_in, width_in, channels].
                  Severity: Major
                  Found in research/object_detection/utils/ops.py and 2 other locations - About 6 hrs to fix
                  research/deeplab/core/xception.py on lines 81..100
                  research/object_detection/models/keras_models/resnet_v1.py on lines 33..55

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

                  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(scope, 'MatMulGather'):
                      params_shape = shape_utils.combined_static_and_dynamic_shape(params)
                      indices_shape = shape_utils.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 research/object_detection/utils/ops.py and 2 other locations - About 6 hrs to fix
                  official/projects/centernet/ops/box_list_ops.py on lines 120..127
                  official/vision/utils/object_detection/ops.py on lines 74..81

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

                      hashcodes = (
                          ymin +
                          xmin * quantization_bins +
                          ymax * quantization_bins * quantization_bins +
                          xmax * quantization_bins * quantization_bins * quantization_bins)
                  Severity: Major
                  Found in research/object_detection/utils/ops.py and 1 other location - About 2 hrs to fix
                  official/vision/utils/object_detection/ops.py on lines 110..114

                  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

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

                    ymin, xmin, ymax, xmax = (boxes[:, 0], boxes[:, 1], boxes[:, 2], boxes[:, 3])
                  Severity: Major
                  Found in research/object_detection/utils/ops.py and 12 other locations - About 2 hrs to fix
                  research/object_detection/core/preprocessor_test.py on lines 1314..1314
                  research/object_detection/core/preprocessor_test.py on lines 1315..1317
                  research/object_detection/core/preprocessor_test.py on lines 1337..1337
                  research/object_detection/core/preprocessor_test.py on lines 1338..1340
                  research/object_detection/core/preprocessor_test.py on lines 1363..1363
                  research/object_detection/core/preprocessor_test.py on lines 1364..1366
                  research/object_detection/core/preprocessor_test.py on lines 1396..1396
                  research/object_detection/core/preprocessor_test.py on lines 1397..1399
                  research/object_detection/core/preprocessor_test.py on lines 1419..1419
                  research/object_detection/core/preprocessor_test.py on lines 1420..1422
                  research/object_detection/core/preprocessor_test.py on lines 1445..1445
                  research/object_detection/core/preprocessor_test.py on lines 1446..1448

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

                  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 isinstance(input_nested, tf.Tensor):
                      if input_nested.dtype == tf.bfloat16:
                        return tf.cast(input_nested, dtype=tf.float32)
                      else:
                        return input_nested
                  Severity: Minor
                  Found in research/object_detection/utils/ops.py and 1 other location - About 35 mins to fix
                  research/object_detection/tpu_exporters/utils.py on lines 25..28

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

                  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 left_pad < 0 or not isinstance(left_pad, six.integer_types):
                      raise ValueError('`left_pad` must be a non-negative integer.')
                  Severity: Minor
                  Found in research/object_detection/utils/ops.py and 1 other location - About 35 mins to fix
                  research/object_detection/utils/ops.py on lines 255..256

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

                  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 depth < 0 or not isinstance(depth, six.integer_types):
                      raise ValueError('`depth` must be a non-negative integer.')
                  Severity: Minor
                  Found in research/object_detection/utils/ops.py and 1 other location - About 35 mins to fix
                  research/object_detection/utils/ops.py on lines 257..258

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

                  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