tensorflow/models

View on GitHub
research/slim/nets/resnet_v2.py

Summary

Maintainability
F
1 wk
Test Coverage

File resnet_v2.py has 272 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2016 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/resnet_v2.py - About 2 hrs to fix

    Function resnet_v2 has 10 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def resnet_v2(inputs,
    Severity: Major
    Found in research/slim/nets/resnet_v2.py - About 1 hr to fix

      Function resnet_v2 has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      def resnet_v2(inputs,
                    blocks,
                    num_classes=None,
                    is_training=True,
                    global_pool=True,
      Severity: Minor
      Found in research/slim/nets/resnet_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 resnet_v2_152 has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def resnet_v2_152(inputs,
      Severity: Major
      Found in research/slim/nets/resnet_v2.py - About 1 hr to fix

        Function resnet_v2_101 has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        def resnet_v2_101(inputs,
        Severity: Major
        Found in research/slim/nets/resnet_v2.py - About 1 hr to fix

          Function resnet_v2_200 has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def resnet_v2_200(inputs,
          Severity: Major
          Found in research/slim/nets/resnet_v2.py - About 1 hr to fix

            Function resnet_v2_50 has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def resnet_v2_50(inputs,
            Severity: Major
            Found in research/slim/nets/resnet_v2.py - About 1 hr to fix

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

              def bottleneck(inputs, depth, depth_bottleneck, stride, rate=1,
              Severity: Major
              Found in research/slim/nets/resnet_v2.py - About 50 mins to fix

                Avoid deeply nested control flow statements.
                Open

                          if spatial_squeeze:
                            net = tf.squeeze(net, [1, 2], name='SpatialSqueeze')
                            end_points[sc.name + '/spatial_squeeze'] = net
                          end_points['predictions'] = slim.softmax(net, scope='predictions')
                Severity: Major
                Found in research/slim/nets/resnet_v2.py - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                            with slim.arg_scope([slim.conv2d],
                                                activation_fn=None, normalizer_fn=None):
                              net = resnet_utils.conv2d_same(net, 64, 7, stride=2, scope='conv1')
                            net = slim.max_pool2d(net, [3, 3], stride=2, scope='pool1')
                  Severity: Major
                  Found in research/slim/nets/resnet_v2.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                              if output_stride is not None:
                                if output_stride % 4 != 0:
                                  raise ValueError('The output_stride needs to be a multiple of 4.')
                                output_stride /= 4
                              # We do not include batch normalization or activation functions in
                    Severity: Major
                    Found in research/slim/nets/resnet_v2.py - About 45 mins to fix

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

                      def resnet_v2_200(inputs,
                                        num_classes=None,
                                        is_training=True,
                                        global_pool=True,
                                        output_stride=None,
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 3 other locations - About 7 hrs to fix
                      research/slim/nets/resnet_v2.py on lines 254..269
                      research/slim/nets/resnet_v2.py on lines 276..291
                      research/slim/nets/resnet_v2.py on lines 298..313

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

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

                      def resnet_v2_101(inputs,
                                        num_classes=None,
                                        is_training=True,
                                        global_pool=True,
                                        output_stride=None,
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 3 other locations - About 7 hrs to fix
                      research/slim/nets/resnet_v2.py on lines 254..269
                      research/slim/nets/resnet_v2.py on lines 298..313
                      research/slim/nets/resnet_v2.py on lines 320..335

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

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

                      def resnet_v2_152(inputs,
                                        num_classes=None,
                                        is_training=True,
                                        global_pool=True,
                                        output_stride=None,
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 3 other locations - About 7 hrs to fix
                      research/slim/nets/resnet_v2.py on lines 254..269
                      research/slim/nets/resnet_v2.py on lines 276..291
                      research/slim/nets/resnet_v2.py on lines 320..335

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

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

                      def resnet_v2_50(inputs,
                                       num_classes=None,
                                       is_training=True,
                                       global_pool=True,
                                       output_stride=None,
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 3 other locations - About 7 hrs to fix
                      research/slim/nets/resnet_v2.py on lines 276..291
                      research/slim/nets/resnet_v2.py on lines 298..313
                      research/slim/nets/resnet_v2.py on lines 320..335

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

                      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 num_classes:
                                net = slim.conv2d(net, num_classes, [1, 1], activation_fn=None,
                                                  normalizer_fn=None, scope='logits')
                                end_points[sc.name + '/logits'] = net
                                if spatial_squeeze:
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 1 other location - About 7 hrs to fix
                      research/slim/nets/resnet_v1.py on lines 248..255

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

                      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 resnet_v2_block(scope, base_depth, num_units, stride):
                        """Helper function for creating a resnet_v2 bottleneck block.
                      
                        Args:
                          scope: The scope of the block.
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 1 other location - About 3 hrs to fix
                      research/slim/nets/resnet_v1.py on lines 260..280

                      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 output_stride is not None:
                                  if output_stride % 4 != 0:
                                    raise ValueError('The output_stride needs to be a multiple of 4.')
                                  output_stride /= 4
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 1 other location - About 1 hr to fix
                      research/slim/nets/resnet_v1.py on lines 231..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 40.

                      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 global_pool:
                                # Global average pooling.
                                net = tf.reduce_mean(
                                    input_tensor=net, axis=[1, 2], name='pool5', keepdims=True)
                                end_points['global_pool'] = net
                      Severity: Major
                      Found in research/slim/nets/resnet_v2.py and 1 other location - About 1 hr to fix
                      research/slim/nets/resnet_v1.py on lines 243..247

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

                      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