tensorflow/models

View on GitHub
official/legacy/detection/modeling/maskrcnn_model.py

Summary

Maintainability
F
6 days
Test Coverage

File maskrcnn_model.py has 270 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/legacy/detection/modeling/maskrcnn_model.py - About 2 hrs to fix

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

      def build_input_layers(self, params, mode):
        is_training = mode == mode_keys.TRAIN
        input_shape = (
            params.maskrcnn_parser.output_size +
            [params.maskrcnn_parser.num_channels])
    Severity: Minor
    Found in official/legacy/detection/modeling/maskrcnn_model.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 build_outputs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_outputs(self, inputs, mode):
        is_training = mode == mode_keys.TRAIN
        model_outputs = {}
    
        image = inputs['image']
    Severity: Minor
    Found in official/legacy/detection/modeling/maskrcnn_model.py - About 25 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 2 locations. Consider refactoring.
    Open

      def build_input_layers(self, params, mode):
        is_training = mode == mode_keys.TRAIN
        input_shape = (
            params.maskrcnn_parser.output_size +
            [params.maskrcnn_parser.num_channels])
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 1 other location - About 2 days to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 362..419

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

    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 build_model(self, params, mode):
        if self._keras_model is None:
          input_layers = self.build_input_layers(self._params, mode)
          outputs = self.model_outputs(input_layers, mode)
    
    
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 2 other locations - About 6 hrs to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 421..432
    official/legacy/detection/modeling/shapemask_model.py on lines 255..266

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

    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 is_training:
          rpn_rois, classes, mask_targets = self._sample_masks_fn(
              rpn_rois, matched_gt_boxes, matched_gt_classes, matched_gt_indices,
              inputs['gt_masks'])
          mask_targets = tf.stop_gradient(mask_targets)
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 1 other location - About 5 hrs to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 259..273

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

    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

        model_outputs.update({
            'class_outputs':
                tf.nest.map_structure(lambda x: tf.cast(x, tf.float32),
                                      class_outputs),
            'box_outputs':
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 3 other locations - About 3 hrs to fix
    official/legacy/detection/modeling/maskrcnn_model.py on lines 87..93
    official/legacy/detection/modeling/olnmask_model.py on lines 122..128
    official/legacy/detection/modeling/olnmask_model.py on lines 209..215

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

    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 is_training:
          model_outputs.update({
              'mask_outputs':
                  tf.nest.map_structure(lambda x: tf.cast(x, tf.float32),
                                        mask_outputs),
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 1 other location - About 3 hrs to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 280..287

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

    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

        model_outputs.update({
            'rpn_score_outputs':
                tf.nest.map_structure(lambda x: tf.cast(x, tf.float32),
                                      rpn_score_outputs),
            'rpn_box_outputs':
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 3 other locations - About 3 hrs to fix
    official/legacy/detection/modeling/maskrcnn_model.py on lines 131..137
    official/legacy/detection/modeling/olnmask_model.py on lines 122..128
    official/legacy/detection/modeling/olnmask_model.py on lines 209..215

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

    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

        input_anchor = anchor.Anchor(self._params.architecture.min_level,
                                     self._params.architecture.max_level,
                                     self._params.anchor.num_scales,
                                     self._params.anchor.aspect_ratios,
                                     self._params.anchor.anchor_size,
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 1 other location - About 1 hr to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 130..135

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

    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

          box_targets = tf.where(
              tf.tile(
                  tf.expand_dims(tf.equal(matched_gt_classes, 0), axis=-1),
                  [1, 1, 4]), tf.zeros_like(box_targets), box_targets)
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 1 other location - About 1 hr to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 181..184

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

    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 self._include_mask:
            mask_loss = self._mask_loss_fn(outputs['mask_outputs'],
                                           outputs['mask_targets'],
                                           outputs['sampled_class_targets'])
          else:
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 2 other locations - About 1 hr to fix
    official/legacy/detection/modeling/olnmask_model.py on lines 320..325
    official/legacy/detection/modeling/olnmask_model.py on lines 332..337

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

    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

        for field in required_output_fields:
          if field not in outputs:
            raise ValueError('"%s" is missing in outputs, requried %s found %s' %
                             (field, required_output_fields, outputs.keys()))
    Severity: Major
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 2 other locations - About 55 mins to fix
    official/legacy/detection/modeling/retinanet_model.py on lines 132..135
    official/legacy/detection/modeling/retinanet_model.py on lines 137..140

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 37.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

        boxes, scores, classes, valid_detections = self._generate_detections_fn(
            box_outputs, class_outputs, rpn_rois, inputs['image_info'][:, 1:2, :])
    Severity: Minor
    Found in official/legacy/detection/modeling/maskrcnn_model.py and 1 other location - About 55 mins to fix
    official/legacy/detection/modeling/shapemask_model.py on lines 93..95

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 37.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    There are no issues that match your filters.

    Category
    Status