tensorflow/models

View on GitHub
official/vision/modeling/layers/nn_blocks.py

Summary

Maintainability
F
1 wk
Test Coverage

File nn_blocks.py has 2486 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2024 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 official/vision/modeling/layers/nn_blocks.py - About 6 days to fix

    Function call has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

      def call(self, inputs, output_range=None, training=None):
        """Transformer self-attention encoder block call."""
        if isinstance(inputs, (list, tuple)):
          if len(inputs) == 2:
            input_tensor, attention_mask = inputs
    Severity: Minor
    Found in official/vision/modeling/layers/nn_blocks.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 __init__ has 26 arguments (exceeds 4 allowed). Consider refactoring.
    Open

      def __init__(self,
    Severity: Major
    Found in official/vision/modeling/layers/nn_blocks.py - About 3 hrs to fix

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

        def __init__(
      Severity: Major
      Found in official/vision/modeling/layers/nn_blocks.py - About 3 hrs to fix

        Function call has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

          def call(
              self,
              inputs: tf.Tensor,
              training: Optional[bool] = None
          ) -> Union[tf.Tensor, Tuple[tf.Tensor, tf.Tensor]]:
        Severity: Minor
        Found in official/vision/modeling/layers/nn_blocks.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 22 arguments (exceeds 4 allowed). Consider refactoring.
        Open

          def __init__(
        Severity: Major
        Found in official/vision/modeling/layers/nn_blocks.py - About 2 hrs to fix

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

            def __init__(self,
          Severity: Major
          Found in official/vision/modeling/layers/nn_blocks.py - About 2 hrs to fix

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

              def __init__(self,
            Severity: Major
            Found in official/vision/modeling/layers/nn_blocks.py - About 2 hrs to fix

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

                def __init__(self,
              Severity: Major
              Found in official/vision/modeling/layers/nn_blocks.py - About 2 hrs to fix

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

                  def call(self, inputs):
                    """Run layer computation."""
                    if self._use_cpe:
                      x = self._cpe_dw_conv(inputs)
                      x = x + inputs
                Severity: Minor
                Found in official/vision/modeling/layers/nn_blocks.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 __init__ has 12 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                  def __init__(
                Severity: Major
                Found in official/vision/modeling/layers/nn_blocks.py - About 1 hr to fix

                  Function __init__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def __init__(
                        self,
                        in_filters: int,
                        out_filters: int,
                        expand_ratio: float,
                  Severity: Minor
                  Found in official/vision/modeling/layers/nn_blocks.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 has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def build(self, input_shape):
                      """Create layer state."""
                      self._input_norm = self._norm(
                          axis=self._bn_axis,
                          momentum=self._norm_momentum,
                  Severity: Minor
                  Found in official/vision/modeling/layers/nn_blocks.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 __init__ has 11 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def __init__(
                  Severity: Major
                  Found in official/vision/modeling/layers/nn_blocks.py - About 1 hr to fix

                    Function __init__ has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      def __init__(
                          self,
                          in_filters: int,
                          out_filters: int,
                          expand_ratio: float,
                    Severity: Minor
                    Found in official/vision/modeling/layers/nn_blocks.py - About 1 hr to fix

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

                        def __init__(
                      Severity: Major
                      Found in official/vision/modeling/layers/nn_blocks.py - About 1 hr to fix

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

                          def call(self, inputs, training=None):
                            endpoints = {}
                            shortcut = inputs
                            if self._expand_ratio > 1:
                              x = self._conv0(inputs)
                        Severity: Minor
                        Found in official/vision/modeling/layers/nn_blocks.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 __init__ has 10 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                          def __init__(
                        Severity: Major
                        Found in official/vision/modeling/layers/nn_blocks.py - About 1 hr to fix

                          Function __init__ has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def __init__(self,
                                         in_filters,
                                         out_filters,
                                         expand_ratio,
                                         strides,
                          Severity: Minor
                          Found in official/vision/modeling/layers/nn_blocks.py - About 1 hr to fix

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

                              def build(self, input_shape):
                                # Starting depthwise conv.
                                if self._start_dw_kernel_size:
                                  self._start_dw_conv = tf_keras.layers.DepthwiseConv2D(
                                      kernel_size=self._start_dw_kernel_size,
                            Severity: Minor
                            Found in official/vision/modeling/layers/nn_blocks.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 call has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def call(self, inputs, training=None):
                                """Run layer computation."""
                                endpoints = {}
                                shortcut = inputs
                                x = inputs
                            Severity: Minor
                            Found in official/vision/modeling/layers/nn_blocks.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 build has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                            Open

                              def build(self, input_shape):
                                # First 1x1 conv for channel expansion.
                                expand_filters = nn_layers.make_divisible(
                                    self._in_filters * self._expand_ratio, self._divisible_by
                                )
                            Severity: Minor
                            Found in official/vision/modeling/layers/nn_blocks.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                              def __init__(
                            Severity: Minor
                            Found in official/vision/modeling/layers/nn_blocks.py - About 45 mins to fix

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

                                def build(self, input_shape):
                                  if self._use_projection:
                                    if self._resnetd_shortcut:
                                      self._shortcut0 = tf_keras.layers.AveragePooling2D(
                                          pool_size=2, strides=self._strides, padding='same')
                              Severity: Minor
                              Found in official/vision/modeling/layers/nn_blocks.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
                              Open

                                def __init__(
                              Severity: Minor
                              Found in official/vision/modeling/layers/nn_blocks.py - About 45 mins to fix

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

                                  def _reshape_projected_query(self, t, num_heads, h_px, w_px, key_dim):
                                Severity: Minor
                                Found in official/vision/modeling/layers/nn_blocks.py - About 35 mins to fix

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

                                    def build(self, input_shape):
                                      if self._use_projection:
                                        self._shortcut = tf_keras.layers.Conv2D(
                                            filters=self._filters,
                                            kernel_size=1,
                                  Severity: Minor
                                  Found in official/vision/modeling/layers/nn_blocks.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

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

                                    def call(self, inputs):
                                      """Run layer computation."""
                                      x = inputs
                                      px = self._get_pixels(x)
                                  
                                  
                                  Severity: Minor
                                  Found in official/vision/modeling/layers/nn_blocks.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

                                  Function call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    def call(self,
                                             inputs: tf.Tensor,
                                             training: Optional[bool] = None) -> tf.Tensor:
                                  
                                      @tf.custom_gradient
                                  Severity: Minor
                                  Found in official/vision/modeling/layers/nn_blocks.py - About 25 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 call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                    def call(self, inputs, training=None):
                                      shortcut = inputs
                                      if self._use_projection:
                                        if self._resnetd_shortcut:
                                          shortcut = self._shortcut0(shortcut)
                                  Severity: Minor
                                  Found in official/vision/modeling/layers/nn_blocks.py - About 25 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

                                  There are no issues that match your filters.

                                  Category
                                  Status