tensorflow/models

View on GitHub
research/object_detection/model_lib_v2.py

Summary

Maintainability
F
1 wk
Test Coverage

File model_lib_v2.py has 950 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2019 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/model_lib_v2.py - About 2 days to fix

    Function eager_eval_loop has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
    Open

    def eager_eval_loop(
        detection_model,
        configs,
        eval_dataset,
        use_tpu=False,
    Severity: Minor
    Found in research/object_detection/model_lib_v2.py - About 6 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 train_loop has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
    Open

    def train_loop(
        pipeline_config_path,
        model_dir,
        config_override=None,
        train_steps=None,
    Severity: Minor
    Found in research/object_detection/model_lib_v2.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 eval_continuously has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def eval_continuously(
        pipeline_config_path,
        config_override=None,
        train_steps=None,
        sample_1_of_n_eval_examples=1,
    Severity: Minor
    Found in research/object_detection/model_lib_v2.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 eval_continuously has 15 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def eval_continuously(
    Severity: Major
    Found in research/object_detection/model_lib_v2.py - About 1 hr to fix

      Function train_loop has 12 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def train_loop(
      Severity: Major
      Found in research/object_detection/model_lib_v2.py - About 1 hr to fix

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

        def validate_tf_v2_checkpoint_restore_map(checkpoint_restore_map):
          """Ensure that given dict is a valid TF v2 style restore map.
        
          Args:
            checkpoint_restore_map: A nested dict mapping strings to
        Severity: Minor
        Found in research/object_detection/model_lib_v2.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 eager_eval_loop has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        def eager_eval_loop(
            detection_model,
            configs,
            eval_dataset,
            use_tpu=False,
        Severity: Minor
        Found in research/object_detection/model_lib_v2.py - About 1 hr to fix

          Function eager_train_step has 9 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def eager_train_step(detection_model,
          Severity: Major
          Found in research/object_detection/model_lib_v2.py - About 1 hr to fix

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

            def train_loop(
                pipeline_config_path,
                model_dir,
                config_override=None,
                train_steps=None,
            Severity: Minor
            Found in research/object_detection/model_lib_v2.py - About 1 hr to fix

              Function load_fine_tune_checkpoint has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

              def load_fine_tune_checkpoint(model, checkpoint_path, checkpoint_type,
              Severity: Major
              Found in research/object_detection/model_lib_v2.py - About 50 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          for key, val in logged_dict.items():
                            tf.compat.v2.summary.scalar(key, val, step=global_step)
                
                
                Severity: Major
                Found in research/object_detection/model_lib_v2.py - About 45 mins to fix

                  Function eager_eval_loop has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                  def eager_eval_loop(
                  Severity: Minor
                  Found in research/object_detection/model_lib_v2.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                for _ in tf.range(num_steps_per_iteration - 1):
                                  # Following suggestion on yaqs/5402607292645376
                                  with tf.name_scope(''):
                                    _sample_and_train(strategy, train_step_fn, data_iterator)
                    
                    
                    Severity: Major
                    Found in research/object_detection/model_lib_v2.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                if ((int(global_step.value()) - checkpointed_step) >=
                                    checkpoint_every_n):
                                  manager.save()
                                  checkpointed_step = int(global_step.value())
                      
                      
                      Severity: Major
                      Found in research/object_detection/model_lib_v2.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                  if global_step.value() - logged_step >= LOG_EVERY:
                                    logged_dict_np = {name: value.numpy() for name, value in
                                                      logged_dict.items()}
                                    tf.logging.info(
                                        'Step {} per-step time {:.3f}s'.format(
                        Severity: Major
                        Found in research/object_detection/model_lib_v2.py - About 45 mins to fix

                          Function _compute_losses_and_predictions_dicts has 5 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                          def _compute_losses_and_predictions_dicts(
                          Severity: Minor
                          Found in research/object_detection/model_lib_v2.py - About 35 mins to fix

                            Function prepare_eval_dict has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                            Open

                            def prepare_eval_dict(detections, groundtruth, features):
                              """Prepares eval dictionary containing detections and groundtruth.
                            
                              Takes in `detections` from the model, `groundtruth` and `features` returned
                              from the eval tf.data.dataset and creates a dictionary of tensors suitable
                            Severity: Minor
                            Found in research/object_detection/model_lib_v2.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

                                    for j, dp_image in enumerate(dp_image_list):
                                      tf.compat.v2.summary.image(
                                          name='densepose_detections_{}_{}'.format(i, j),
                                          step=global_step,
                                          data=dp_image,
                            Severity: Major
                            Found in research/object_detection/model_lib_v2.py and 1 other location - About 1 hr to fix
                            research/object_detection/model_lib_v2.py on lines 977..982

                            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

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

                                  for j, sbys_image in enumerate(sbys_image_list):
                                    tf.compat.v2.summary.image(
                                        name='eval_side_by_side_{}_{}'.format(i, j),
                                        step=global_step,
                                        data=sbys_image,
                            Severity: Major
                            Found in research/object_detection/model_lib_v2.py and 1 other location - About 1 hr to fix
                            research/object_detection/model_lib_v2.py on lines 986..991

                            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

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

                              if fields.InputDataFields.groundtruth_not_exhaustive_classes in groundtruth:
                                groundtruth[
                                    fields.InputDataFields.groundtruth_not_exhaustive_classes] = tf.pad(
                                        groundtruth[
                                            fields.InputDataFields.groundtruth_not_exhaustive_classes],
                            Severity: Major
                            Found in research/object_detection/model_lib_v2.py and 2 other locations - About 1 hr to fix
                            research/object_detection/model_lib_v2.py on lines 785..790
                            research/object_detection/model_lib_v2.py on lines 797..800

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

                            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 fields.InputDataFields.groundtruth_verified_neg_classes in groundtruth:
                                groundtruth[
                                    fields.InputDataFields.groundtruth_verified_neg_classes] = tf.pad(
                                        groundtruth[
                                            fields.InputDataFields.groundtruth_verified_neg_classes],
                            Severity: Major
                            Found in research/object_detection/model_lib_v2.py and 2 other locations - About 1 hr to fix
                            research/object_detection/model_lib_v2.py on lines 791..796
                            research/object_detection/model_lib_v2.py on lines 797..800

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

                            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 fields.InputDataFields.groundtruth_labeled_classes in groundtruth:
                                groundtruth[fields.InputDataFields.groundtruth_labeled_classes] = tf.pad(
                                    groundtruth[fields.InputDataFields.groundtruth_labeled_classes],
                                    label_id_offset_paddings)
                            Severity: Major
                            Found in research/object_detection/model_lib_v2.py and 2 other locations - About 1 hr to fix
                            research/object_detection/model_lib_v2.py on lines 785..790
                            research/object_detection/model_lib_v2.py on lines 791..796

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

                            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 loss_key, loss_tensor in iter(losses_dict.items()):
                                  if loss_key not in loss_metrics:
                                    loss_metrics[loss_key] = []
                                  loss_metrics[loss_key].append(loss_tensor)
                            Severity: Minor
                            Found in research/object_detection/model_lib_v2.py and 1 other location - About 55 mins to fix
                            research/delf/delf/python/training/build_image_dataset.py on lines 355..358

                            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

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

                              eval_dict = eval_util.result_dict_for_batched_example(
                                  eval_images,
                                  features[inputs.HASH_KEY],
                                  detections,
                                  groundtruth,
                            Severity: Minor
                            Found in research/object_detection/model_lib_v2.py and 1 other location - About 45 mins to fix
                            research/object_detection/model_lib.py on lines 661..665

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

                              for key, values in tensor_dict.items():
                                new_tensor_dict[key] = tf.concat(values, axis=0)
                            Severity: Major
                            Found in research/object_detection/model_lib_v2.py and 2 other locations - About 40 mins to fix
                            research/object_detection/predictors/convolutional_box_predictor_tf1_test.py on lines 902..903
                            research/object_detection/predictors/convolutional_keras_box_predictor_tf2_test.py on lines 926..927

                            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 model_dir and save_final_config:
                                tf.logging.info('Saving pipeline config file to directory %s', model_dir)
                                pipeline_config_final = create_pipeline_proto_from_configs(configs)
                                config_util.save_pipeline_config(pipeline_config_final, model_dir)
                            Severity: Minor
                            Found in research/object_detection/model_lib_v2.py and 1 other location - About 30 mins to fix
                            research/object_detection/model_lib_v2.py on lines 539..542

                            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 save_final_config:
                                tf.logging.info('Saving pipeline config file to directory %s', model_dir)
                                pipeline_config_final = create_pipeline_proto_from_configs(configs)
                                config_util.save_pipeline_config(pipeline_config_final, model_dir)
                            Severity: Minor
                            Found in research/object_detection/model_lib_v2.py and 1 other location - About 30 mins to fix
                            research/object_detection/model_lib_v2.py on lines 1093..1096

                            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