tensorflow/models

View on GitHub
research/slim/nets/nasnet/nasnet_utils.py

Summary

Maintainability
F
3 days
Test Coverage

File nasnet_utils.py has 422 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: Minor
Found in research/slim/nets/nasnet/nasnet_utils.py - About 6 hrs to fix

    Function _apply_conv_operation has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      def _apply_conv_operation(self, net, operation,
                                stride, is_from_original_input, current_step):
        """Applies the predicted conv operation to net."""
        # Dont stride if this is not one of the original hiddenstates
        if stride > 1 and not is_from_original_input:
    Severity: Minor
    Found in research/slim/nets/nasnet/nasnet_utils.py - About 3 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 _apply_drop_path has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

      def _apply_drop_path(self, net, current_step=None,
                           use_summaries=False, drop_connect_version='v3'):
        """Apply drop_path regularization.
    
        Args:
    Severity: Minor
    Found in research/slim/nets/nasnet/nasnet_utils.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 __init__ has 8 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self, num_conv_filters, operations, used_hiddenstates,
    Severity: Major
    Found in research/slim/nets/nasnet/nasnet_utils.py - About 1 hr to fix

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

        def __call__(self, net, scope=None, filter_scaling=1, stride=1,
      Severity: Major
      Found in research/slim/nets/nasnet/nasnet_utils.py - About 50 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if self._use_bounded_activation:
                      h = tf.nn.relu6(h)
        
                  # Add hiddenstate to the list of hiddenstates we can choose from
                  net.append(h)
        Severity: Major
        Found in research/slim/nets/nasnet/nasnet_utils.py - About 45 mins to fix

          Function _combine_unused_states has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def _combine_unused_states(self, net):
              """Concatenate the unused hidden states of the cell."""
              used_hiddenstates = self._used_hiddenstates
          
              final_height = int(net[-1].shape[2])
          Severity: Minor
          Found in research/slim/nets/nasnet/nasnet_utils.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 _stacked_separable_conv has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def _stacked_separable_conv(net, stride, operation, filter_size,
          Severity: Minor
          Found in research/slim/nets/nasnet/nasnet_utils.py - About 35 mins to fix

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

              def __init__(self, num_conv_filters, drop_path_keep_prob, total_num_cells,
            Severity: Minor
            Found in research/slim/nets/nasnet/nasnet_utils.py - About 35 mins to fix

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

                def __init__(self, num_conv_filters, drop_path_keep_prob, total_num_cells,
              Severity: Minor
              Found in research/slim/nets/nasnet/nasnet_utils.py - About 35 mins to fix

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

                  def _apply_conv_operation(self, net, operation,
                Severity: Minor
                Found in research/slim/nets/nasnet/nasnet_utils.py - About 35 mins to fix

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

                  class NasNetAReductionCell(NasNetABaseCell):
                    """NASNetA Reduction Cell."""
                  
                    def __init__(self, num_conv_filters, drop_path_keep_prob, total_num_cells,
                                 total_training_steps, use_bounded_activation=False):
                  Severity: Major
                  Found in research/slim/nets/nasnet/nasnet_utils.py and 1 other location - About 5 hrs to fix
                  research/slim/nets/nasnet/nasnet_utils.py on lines 481..504

                  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

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

                  class NasNetANormalCell(NasNetABaseCell):
                    """NASNetA Normal Cell."""
                  
                    def __init__(self, num_conv_filters, drop_path_keep_prob, total_num_cells,
                                 total_training_steps, use_bounded_activation=False):
                  Severity: Major
                  Found in research/slim/nets/nasnet/nasnet_utils.py and 1 other location - About 5 hrs to fix
                  research/slim/nets/nasnet/nasnet_utils.py on lines 507..530

                  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

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

                        if input_filters != filter_size:
                          net = slim.conv2d(net, filter_size, 1, stride=1, scope='1x1')
                          net = slim.batch_norm(net, scope='bn_1')
                  Severity: Major
                  Found in research/slim/nets/nasnet/nasnet_utils.py and 1 other location - About 1 hr to fix
                  research/deeplab/core/nas_cell.py on lines 183..185

                  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

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

                  def _operation_to_pooling_info(operation):
                    """Parses the pooling operation string to return its type and shape."""
                    pooling_type = _operation_to_pooling_type(operation)
                    pooling_shape = _operation_to_pooling_shape(operation)
                    return pooling_type, pooling_shape
                  Severity: Minor
                  Found in research/slim/nets/nasnet/nasnet_utils.py and 1 other location - About 35 mins to fix
                  research/slim/nets/nasnet/nasnet_utils.py on lines 168..181

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

                  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

                  def _operation_to_info(operation):
                    """Takes in operation name and returns meta information.
                  
                    An example would be 'separable_3x3_4' -> (3, 4).
                  
                  
                  Severity: Minor
                  Found in research/slim/nets/nasnet/nasnet_utils.py and 1 other location - About 35 mins to fix
                  research/slim/nets/nasnet/nasnet_utils.py on lines 230..234

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

                  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