tensorflow/models

View on GitHub
official/vision/tasks/maskrcnn.py

Summary

Maintainability
D
2 days
Test Coverage

File maskrcnn.py has 525 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: Major
Found in official/vision/tasks/maskrcnn.py - About 1 day to fix

    Function _reduce_instance_metrics has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
    Open

      def _reduce_instance_metrics(
          self, logs: Dict[str, Any], use_masks: bool = False
      ):
        """Updates the per class and mean instance metrics in the logs."""
        if use_masks:
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.py - About 4 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 build_metrics has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

      def build_metrics(self, training: bool = True):
        """Builds detection metrics."""
        self.instance_box_perclass_metrics = None
        self.instance_mask_perclass_metrics = None
        if training:
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.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 _build_frcnn_losses has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def _build_frcnn_losses(
          self,
          outputs: Mapping[str, Any],
          labels: Mapping[str, Any],
      ) -> Tuple[tf.Tensor, tf.Tensor]:
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.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 _build_coco_metrics has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def _build_coco_metrics(self):
        """Builds COCO metrics evaluator."""
        if (not self._task_config.model.include_mask
           ) or self._task_config.annotation_file:
          self.coco_metric = coco_evaluator.COCOEvaluator(
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.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 aggregate_logs has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

      def aggregate_logs(
          self,
          state: Optional[Any] = None,
          step_outputs: Optional[Dict[str, Any]] = None,
      ) -> Optional[Any]:
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.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 train_step has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def train_step(self,
                     inputs: Tuple[Any, Any],
                     model: tf_keras.Model,
                     optimizer: tf_keras.optimizers.Optimizer,
                     metrics: Optional[List[Any]] = None):
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.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 initialize has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def initialize(self, model: tf_keras.Model):
        """Loads pretrained checkpoint."""
    
        if not self.task_config.init_checkpoint:
          return
    Severity: Minor
    Found in official/vision/tasks/maskrcnn.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

    Avoid deeply nested control flow statements.
    Open

                for j, iou in enumerate(iou_thresholds):
                  if int(iou * 100) in {50, 75}:
                    logs[f'{prefix}{ap_key}{int(iou * 100)} ByCategory/{k}'] = (
                        per_class_ap[j][k]
                    )
    Severity: Major
    Found in official/vision/tasks/maskrcnn.py - About 45 mins to fix

      Function _update_metrics has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def _update_metrics(self, labels, outputs, logs):
          instance_predictions = {
              'detection_boxes': outputs['detection_boxes'],
              'detection_scores': outputs['detection_scores'],
              'detection_classes': outputs['detection_classes'],
      Severity: Minor
      Found in official/vision/tasks/maskrcnn.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

      Function reduce_aggregated_logs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

        def reduce_aggregated_logs(
            self,
            aggregated_logs: Dict[str, Any],
            global_step: Optional[tf.Tensor] = None,
        ) -> Dict[str, tf.Tensor]:
      Severity: Minor
      Found in official/vision/tasks/maskrcnn.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

      There are no issues that match your filters.

      Category
      Status