tensorflow/models

View on GitHub
research/object_detection/metrics/lvis_evaluation.py

Summary

Maintainability
F
1 wk
Test Coverage

File lvis_evaluation.py has 394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2020 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 research/object_detection/metrics/lvis_evaluation.py - About 5 hrs to fix

    Function add_eval_dict has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def add_eval_dict(self, eval_dict):
        """Observes an evaluation result dict for a single example.
    
        When executing eagerly, once all observations have been observed by this
        method you can use `.evaluate()` to get the final metrics.
    Severity: Minor
    Found in research/object_detection/metrics/lvis_evaluation.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 update_op has 11 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def update_op(image_id_batched, groundtruth_boxes_batched,
    Severity: Major
    Found in research/object_detection/metrics/lvis_evaluation.py - About 1 hr to fix

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

        def add_single_ground_truth_image_info(self,
                                               image_id,
                                               groundtruth_dict):
          """Adds groundtruth for a single image to be used for evaluation.
      
      
      Severity: Minor
      Found in research/object_detection/metrics/lvis_evaluation.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

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

        def get_estimator_eval_metric_ops(self, eval_dict):
          """Returns a dictionary of eval metric ops.
      
          Note that once value_op is called, the detections and groundtruth added via
          update_op are cleared.
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 2 other locations - About 2 days to fix
      research/object_detection/metrics/coco_evaluation.py on lines 439..498
      research/object_detection/metrics/coco_evaluation.py on lines 1315..1370

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

      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 add_single_detected_image_info(self,
                                           image_id,
                                           detections_dict):
          """Adds detections for a single image to be used for evaluation.
      
      
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 1 other location - About 1 day to fix
      research/object_detection/metrics/coco_evaluation.py on lines 1066..1119

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

      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

          if not image_id.shape.as_list():
            # Apply a batch dimension to all tensors.
            image_id = tf.expand_dims(image_id, 0)
            groundtruth_boxes = tf.expand_dims(groundtruth_boxes, 0)
            groundtruth_classes = tf.expand_dims(groundtruth_classes, 0)
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 2 other locations - About 6 hrs to fix
      research/object_detection/metrics/coco_evaluation.py on lines 1278..1306
      research/object_detection/metrics/coco_evaluation.py on lines 1873..1899

      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

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

              self.add_single_detected_image_info(
                  image_id, {
                      'detection_scores': detection_scores[:num_det_box],
                      'detection_classes': detection_classes[:num_det_box],
                      'detection_masks': detection_masks[
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 1 other location - About 2 hrs to fix
      research/object_detection/metrics/coco_evaluation.py on lines 1245..1252

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

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

            if num_det_boxes_per_image is None:
              num_det_boxes_per_image = tf.shape(detection_scores)[1:2]
            else:
              num_det_boxes_per_image = tf.expand_dims(num_det_boxes_per_image, 0)
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 11 other locations - About 1 hr to fix
      research/object_detection/metrics/calibration_evaluation.py on lines 163..166
      research/object_detection/metrics/calibration_evaluation.py on lines 168..171
      research/object_detection/metrics/coco_evaluation.py on lines 406..409
      research/object_detection/metrics/coco_evaluation.py on lines 411..414
      research/object_detection/metrics/coco_evaluation.py on lines 851..854
      research/object_detection/metrics/coco_evaluation.py on lines 856..859
      research/object_detection/metrics/coco_evaluation.py on lines 1289..1292
      research/object_detection/metrics/coco_evaluation.py on lines 1294..1297
      research/object_detection/metrics/coco_evaluation.py on lines 1882..1885
      research/object_detection/metrics/coco_evaluation.py on lines 1887..1890
      research/object_detection/metrics/lvis_evaluation.py on lines 362..365

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

            if num_gt_boxes_per_image is None:
              num_gt_boxes_per_image = tf.shape(groundtruth_boxes)[1:2]
            else:
              num_gt_boxes_per_image = tf.expand_dims(num_gt_boxes_per_image, 0)
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 11 other locations - About 1 hr to fix
      research/object_detection/metrics/calibration_evaluation.py on lines 163..166
      research/object_detection/metrics/calibration_evaluation.py on lines 168..171
      research/object_detection/metrics/coco_evaluation.py on lines 406..409
      research/object_detection/metrics/coco_evaluation.py on lines 411..414
      research/object_detection/metrics/coco_evaluation.py on lines 851..854
      research/object_detection/metrics/coco_evaluation.py on lines 856..859
      research/object_detection/metrics/coco_evaluation.py on lines 1289..1292
      research/object_detection/metrics/coco_evaluation.py on lines 1294..1297
      research/object_detection/metrics/coco_evaluation.py on lines 1882..1885
      research/object_detection/metrics/coco_evaluation.py on lines 1887..1890
      research/object_detection/metrics/lvis_evaluation.py on lines 367..370

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

          self._image_id_to_verified_neg_classes[image_id] = np.flatnonzero(
              groundtruth_dict[
                  fields.InputDataFields.groundtruth_verified_neg_classes]
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 2 other locations - About 1 hr to fix
      research/object_detection/metrics/coco_evaluation.py on lines 162..163
      research/object_detection/metrics/lvis_evaluation.py on lines 140..142

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

          self._image_id_to_not_exhaustive_classes[image_id] = np.flatnonzero(
              groundtruth_dict[
                  fields.InputDataFields.groundtruth_not_exhaustive_classes]
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 2 other locations - About 1 hr to fix
      research/object_detection/metrics/coco_evaluation.py on lines 162..163
      research/object_detection/metrics/lvis_evaluation.py on lines 136..138

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

          if groundtruth_area is not None and not groundtruth_area.shape[0]:
            groundtruth_area = None
      Severity: Major
      Found in research/object_detection/metrics/lvis_evaluation.py and 7 other locations - About 30 mins to fix
      research/object_detection/metrics/coco_evaluation.py on lines 126..127
      research/object_detection/metrics/coco_evaluation.py on lines 128..129
      research/object_detection/metrics/coco_evaluation.py on lines 130..131
      research/object_detection/metrics/coco_evaluation.py on lines 132..134
      research/object_detection/metrics/coco_evaluation.py on lines 203..204
      research/object_detection/metrics/coco_evaluation.py on lines 1038..1039
      research/object_detection/metrics/coco_evaluation.py on lines 1040..1041

      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

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

          mask_metrics = {'DetectionMasks_'+ key: value
                          for key, value in iter(mask_metrics.items())}
      Severity: Minor
      Found in research/object_detection/metrics/lvis_evaluation.py and 2 other locations - About 30 mins to fix
      research/object_detection/metrics/coco_evaluation.py on lines 309..310
      research/object_detection/metrics/coco_evaluation.py on lines 741..743

      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