tensorflow/models

View on GitHub
research/object_detection/exporter.py

Summary

Maintainability
F
3 days
Test Coverage

File exporter.py has 561 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/exporter.py - About 1 day to fix

    Function rewrite_nn_resize_op has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def rewrite_nn_resize_op(is_quantized=False):
      """Replaces a custom nearest-neighbor resize op with the Tensorflow version.
    
      Some graphs use this custom version for TPU-compatibility.
    
    
    Severity: Minor
    Found in research/object_detection/exporter.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 _export_inference_graph has 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _export_inference_graph(input_type,
    Severity: Major
    Found in research/object_detection/exporter.py - About 1 hr to fix

      Function _export_inference_graph has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      def _export_inference_graph(input_type,
                                  detection_model,
                                  use_moving_averages,
                                  trained_checkpoint_prefix,
                                  output_directory,
      Severity: Minor
      Found in research/object_detection/exporter.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 export_inference_graph has 12 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def export_inference_graph(input_type,
      Severity: Major
      Found in research/object_detection/exporter.py - About 1 hr to fix

        Function parse_side_inputs has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        def parse_side_inputs(side_input_shapes_string, side_input_names_string,
                              side_input_types_string):
          """Parses side input flags.
        
          Args:
        Severity: Minor
        Found in research/object_detection/exporter.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_detection_graph has 9 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def build_detection_graph(input_type, detection_model, input_shape,
        Severity: Major
        Found in research/object_detection/exporter.py - About 1 hr to fix

          Function add_output_tensor_nodes has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          def add_output_tensor_nodes(postprocessed_tensors,
                                      output_collection_name='inference_op'):
            """Adds output nodes for detection boxes and scores.
          
            Adds the following nodes for output tensors -
          Severity: Minor
          Found in research/object_detection/exporter.py - About 1 hr to fix

            Function build_detection_graph has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            def build_detection_graph(input_type, detection_model, input_shape,
                                      output_collection_name, graph_hook_fn,
                                      use_side_inputs=False, side_input_shapes=None,
                                      side_input_names=None, side_input_types=None):
              """Build the detection graph."""
            Severity: Minor
            Found in research/object_detection/exporter.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 add_output_tensor_nodes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def add_output_tensor_nodes(postprocessed_tensors,
                                        output_collection_name='inference_op'):
              """Adds output nodes for detection boxes and scores.
            
              Adds the following nodes for output tensors -
            Severity: Minor
            Found in research/object_detection/exporter.py - About 35 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

              frozen_graph_def = freeze_graph.freeze_graph_with_def_protos(
                  input_graph_def=tf.get_default_graph().as_graph_def(),
            Severity: Major
            Found in research/object_detection/exporter.py and 1 other location - About 1 hr to fix
            research/object_detection/exporter_tf1_test.py on lines 747..748

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

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

              if raw_boxes is not None:
                outputs[detection_fields.raw_detection_boxes] = tf.identity(
                    raw_boxes, name=detection_fields.raw_detection_boxes)
            Severity: Major
            Found in research/object_detection/exporter.py and 5 other locations - About 45 mins to fix
            research/object_detection/exporter.py on lines 334..336
            research/object_detection/exporter.py on lines 337..340
            research/object_detection/exporter.py on lines 348..350
            research/object_detection/exporter.py on lines 351..353
            research/object_detection/exporter.py on lines 354..356

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

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

              if raw_scores is not None:
                outputs[detection_fields.raw_detection_scores] = tf.identity(
                    raw_scores, name=detection_fields.raw_detection_scores)
            Severity: Major
            Found in research/object_detection/exporter.py and 5 other locations - About 45 mins to fix
            research/object_detection/exporter.py on lines 334..336
            research/object_detection/exporter.py on lines 337..340
            research/object_detection/exporter.py on lines 345..347
            research/object_detection/exporter.py on lines 351..353
            research/object_detection/exporter.py on lines 354..356

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

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

              if keypoints is not None:
                outputs[detection_fields.detection_keypoints] = tf.identity(
                    keypoints, name=detection_fields.detection_keypoints)
            Severity: Major
            Found in research/object_detection/exporter.py and 5 other locations - About 45 mins to fix
            research/object_detection/exporter.py on lines 334..336
            research/object_detection/exporter.py on lines 337..340
            research/object_detection/exporter.py on lines 345..347
            research/object_detection/exporter.py on lines 348..350
            research/object_detection/exporter.py on lines 354..356

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

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

              if multiclass_scores is not None:
                outputs[detection_fields.detection_multiclass_scores] = tf.identity(
                    multiclass_scores, name=detection_fields.detection_multiclass_scores)
            Severity: Major
            Found in research/object_detection/exporter.py and 5 other locations - About 45 mins to fix
            research/object_detection/exporter.py on lines 337..340
            research/object_detection/exporter.py on lines 345..347
            research/object_detection/exporter.py on lines 348..350
            research/object_detection/exporter.py on lines 351..353
            research/object_detection/exporter.py on lines 354..356

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

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

              if box_classifier_features is not None:
                outputs[detection_fields.detection_features] = tf.identity(
                    box_classifier_features,
                    name=detection_fields.detection_features)
            Severity: Major
            Found in research/object_detection/exporter.py and 5 other locations - About 45 mins to fix
            research/object_detection/exporter.py on lines 334..336
            research/object_detection/exporter.py on lines 345..347
            research/object_detection/exporter.py on lines 348..350
            research/object_detection/exporter.py on lines 351..353
            research/object_detection/exporter.py on lines 354..356

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

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

              if masks is not None:
                outputs[detection_fields.detection_masks] = tf.identity(
                    masks, name=detection_fields.detection_masks)
            Severity: Major
            Found in research/object_detection/exporter.py and 5 other locations - About 45 mins to fix
            research/object_detection/exporter.py on lines 334..336
            research/object_detection/exporter.py on lines 337..340
            research/object_detection/exporter.py on lines 345..347
            research/object_detection/exporter.py on lines 348..350
            research/object_detection/exporter.py on lines 351..353

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

            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(inputs, dict):
                    for k, v in inputs.items():
                      tensor_info_inputs[k] = tf.saved_model.utils.build_tensor_info(v)
            Severity: Minor
            Found in research/object_detection/exporter.py and 1 other location - About 40 mins to fix
            research/object_detection/exporter.py on lines 396..397

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

            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

                  for k, v in outputs.items():
                    tensor_info_outputs[k] = tf.saved_model.utils.build_tensor_info(v)
            Severity: Minor
            Found in research/object_detection/exporter.py and 1 other location - About 40 mins to fix
            research/object_detection/exporter.py on lines 389..391

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

            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 input_shape is not None:
                  image_tensor = tf.image.resize(image_tensor, input_shape[1:3])
            Severity: Minor
            Found in research/object_detection/exporter.py and 1 other location - About 30 mins to fix
            research/object_detection/exporter.py on lines 250..251

            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

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

                if input_shape is not None:
                  image_tensor = tf.image.resize(image_tensor, input_shape[1:3])
            Severity: Minor
            Found in research/object_detection/exporter.py and 1 other location - About 30 mins to fix
            research/object_detection/exporter.py on lines 221..222

            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