tensorflow/models

View on GitHub
research/deeplab/core/nas_network.py

Summary

Maintainability
F
3 days
Test Coverage

Function _build_nas_base has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
Open

def _build_nas_base(images,
                    cell,
                    backbone,
                    num_classes,
                    hparams,
Severity: Minor
Found in research/deeplab/core/nas_network.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

File nas_network.py has 312 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Lint as: python2, python3
# Copyright 2018 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.
Severity: Minor
Found in research/deeplab/core/nas_network.py - About 3 hrs to fix

    Function _build_nas_base has 13 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def _build_nas_base(images,
    Severity: Major
    Found in research/deeplab/core/nas_network.py - About 1 hr to fix

      Function pnasnet has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def pnasnet(images,
      Severity: Major
      Found in research/deeplab/core/nas_network.py - About 1 hr to fix

        Function hnasnet has 11 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def hnasnet(images,
        Severity: Major
        Found in research/deeplab/core/nas_network.py - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                    if backbone[cell_num] == 3 and nas_remove_os32_stride:
                      stride = 1
                    filter_scaling *= hparams.filter_scaling_rate
          Severity: Major
          Found in research/deeplab/core/nas_network.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                      if backbone[cell_num - 1] == 3 and nas_remove_os32_stride:
                        # No need to rescale features.
                        pass
                      else:
                        # Scale features by a factor of 2.
            Severity: Major
            Found in research/deeplab/core/nas_network.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                        if output_stride != 1:
                          stride = 2
                          output_stride //= 2
                        else:
                          stride = 1
              Severity: Major
              Found in research/deeplab/core/nas_network.py - About 45 mins to fix

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

                def pnasnet(images,
                            num_classes,
                            is_training=True,
                            global_pool=False,
                            output_stride=16,
                Severity: Minor
                Found in research/deeplab/core/nas_network.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

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

                  with arg_scope([slim.dropout, batch_norm], is_training=is_training):
                    return _build_nas_base(
                        images,
                        cell=cell,
                        backbone=backbone,
                Severity: Major
                Found in research/deeplab/core/nas_network.py and 1 other location - About 3 hrs to fix
                research/deeplab/core/nas_network.py on lines 289..304

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

                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

                  with arg_scope([slim.dropout, batch_norm], is_training=is_training):
                    return _build_nas_base(
                        images,
                        cell=cell,
                        backbone=backbone,
                Severity: Major
                Found in research/deeplab/core/nas_network.py and 1 other location - About 3 hrs to fix
                research/deeplab/core/nas_network.py on lines 352..367

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

                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 nas_training_hyper_parameters:
                    hparams.set_hparam('drop_path_keep_prob',
                                       nas_training_hyper_parameters['drop_path_keep_prob'])
                    hparams.set_hparam('total_training_steps',
                                       nas_training_hyper_parameters['total_training_steps'])
                Severity: Minor
                Found in research/deeplab/core/nas_network.py and 1 other location - About 50 mins to fix
                research/deeplab/core/nas_network.py on lines 266..270

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

                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 nas_training_hyper_parameters:
                    hparams.set_hparam('drop_path_keep_prob',
                                       nas_training_hyper_parameters['drop_path_keep_prob'])
                    hparams.set_hparam('total_training_steps',
                                       nas_training_hyper_parameters['total_training_steps'])
                Severity: Minor
                Found in research/deeplab/core/nas_network.py and 1 other location - About 50 mins to fix
                research/deeplab/core/nas_network.py on lines 326..330

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

                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

                    def add_and_check_endpoint(endpoint_name, net):
                      end_points[endpoint_name] = net
                      return final_endpoint and (endpoint_name == final_endpoint)
                Severity: Minor
                Found in research/deeplab/core/nas_network.py and 2 other locations - About 30 mins to fix
                research/slim/nets/nasnet/nasnet.py on lines 465..467
                research/slim/nets/nasnet/pnasnet.py on lines 96..98

                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