tensorflow/models

View on GitHub
official/legacy/detection/dataloader/maskrcnn_parser.py

Summary

Maintainability
F
5 days
Test Coverage

File maskrcnn_parser.py has 296 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/dataloader/maskrcnn_parser.py - About 3 hrs to fix

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

      def __init__(self,
    Severity: Major
    Found in official/legacy/detection/dataloader/maskrcnn_parser.py - About 2 hrs to fix

      Function _parse_train_data has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def _parse_train_data(self, data):
          """Parses data for training.
      
          Args:
            data: the decoded tensor dictionary from TfExampleDecoder.
      Severity: Minor
      Found in official/legacy/detection/dataloader/maskrcnn_parser.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 _parse_train_data has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def _parse_train_data(self, data):
          """Parses data for training.
      
          Args:
            data: the decoded tensor dictionary from TfExampleDecoder.
      Severity: Minor
      Found in official/legacy/detection/dataloader/maskrcnn_parser.py - About 1 hr to fix

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

            if self._include_mask:
              masks = tf.gather(masks, indices)
              # Transfer boxes to the original image space and do normalization.
              cropped_boxes = boxes + tf.tile(tf.expand_dims(offset, axis=0), [1, 2])
              cropped_boxes /= tf.tile(tf.expand_dims(image_scale, axis=0), [1, 2])
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 1 other location - About 1 day to fix
        official/legacy/detection/dataloader/olnmask_parser.py on lines 231..244

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

        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 self._skip_crowd_during_training and self._is_training:
              num_groundtruths = tf.shape(classes)[0]
              with tf.control_dependencies([num_groundtruths, is_crowds]):
                indices = tf.cond(
                    tf.greater(tf.size(is_crowds), 0),
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 1 other location - About 1 day to fix
        official/legacy/detection/dataloader/olnmask_parser.py on lines 178..188

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

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

            if mode == ModeKeys.TRAIN:
              self._parse_fn = self._parse_train_data
            elif mode == ModeKeys.EVAL:
              self._parse_fn = self._parse_eval_data
            elif mode == ModeKeys.PREDICT or mode == ModeKeys.PREDICT_WITH_GT:
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 2 other locations - About 5 hrs to fix
        official/legacy/detection/dataloader/retinanet_parser.py on lines 146..153
        official/legacy/detection/dataloader/shapemask_parser.py on lines 184..191

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

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

            image, image_info = input_utils.resize_and_crop_image(
                image,
                self._output_size,
                padded_size=input_utils.compute_padded_size(
                    self._output_size, 2 ** self._max_level),
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 2 other locations - About 1 hr to fix
        official/legacy/detection/dataloader/olnmask_parser.py on lines 211..217
        official/legacy/detection/dataloader/retinanet_parser.py on lines 232..238

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

        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 self._aug_rand_hflip:
              if self._include_mask:
                image, boxes, masks = input_utils.random_horizontal_flip(
                    image, boxes, masks)
              else:
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 1 other location - About 1 hr to fix
        official/legacy/detection/dataloader/olnmask_parser.py on lines 198..204

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

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

            image, image_info = input_utils.resize_and_crop_image(
                image,
                self._output_size,
                padded_size=input_utils.compute_padded_size(
                    self._output_size, 2 ** self._max_level),
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 2 other locations - About 1 hr to fix
        official/legacy/detection/dataloader/retinanet_parser.py on lines 291..295
        official/legacy/detection/dataloader/retinanet_parser.py on lines 365..369

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

        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 __call__(self, value):
            """Parses data to an image and associated training labels.
        
            Args:
              value: a string tensor holding a serialized tf.Example proto.
        Severity: Major
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 2 other locations - About 1 hr to fix
        official/legacy/detection/dataloader/retinanet_parser.py on lines 155..198
        official/legacy/detection/dataloader/shapemask_parser.py on lines 193..248

        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

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

            rpn_score_targets, rpn_box_targets = anchor_labeler.label_anchors(
                boxes, tf.cast(tf.expand_dims(classes, axis=-1), dtype=tf.float32))
        Severity: Minor
        Found in official/legacy/detection/dataloader/maskrcnn_parser.py and 1 other location - About 55 mins to fix
        official/legacy/detection/dataloader/olnmask_parser.py on lines 290..291

        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