tensorflow/tensorflow

View on GitHub
tensorflow/python/keras/engine/base_layer.py

Summary

Maintainability
F
2 wks
Test Coverage

File base_layer.py has 2394 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2015 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 tensorflow/python/keras/engine/base_layer.py - About 6 days to fix

    Layer has 124 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Layer(module.Module, version_utils.LayerVersionSelector):
      """This is the class from which all layers inherit.
    
      A layer is a callable object that takes as input one or more tensors and
      that outputs one or more tensors. It involves *computation*, defined
    Severity: Major
    Found in tensorflow/python/keras/engine/base_layer.py - About 2 days to fix

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

        def add_weight(self,
                       name=None,
                       shape=None,
                       dtype=None,
                       initializer=None,
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 __setattr__ has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
      Open

        def __setattr__(self, name, value):
          if (name == '_self_setattr_tracking' or
              not getattr(self, '_self_setattr_tracking', True) or
              # Exclude @property.setters from tracking
              hasattr(self.__class__, name)):
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 _flatten_modules has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def _flatten_modules(self, recursive=True, include_self=True):
          """Flattens `tf.Module` instances (excluding `Metrics`).
      
          Args:
            recursive: Whether to recursively flatten through submodules.
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 add_loss has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_loss(self, losses, **kwargs):
          """Add loss tensor(s), potentially dependent on layer inputs.
      
          Some losses (for instance, activity regularization losses) may be dependent
          on the inputs passed when calling a layer. Hence, when reusing the same
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 _functional_construction_call has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        def _functional_construction_call(self, inputs, args, kwargs, input_list):
          call_context = base_layer_utils.call_context()
      
          # Accept NumPy and scalar inputs by converting to Tensors.
          if any(isinstance(x, (
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 add_metric has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_metric(self, value, name=None, **kwargs):
          """Adds metric tensor to the layer.
      
          This method can be used inside the `call()` method of a subclassed layer
          or model.
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 _set_training_mode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def _set_training_mode(self, args, kwargs, call_context):
          training_mode = None
          if self._expects_training_arg:
            # (1) `training` was passed to this `Layer.call`.
            if self._call_arg_was_passed('training', args, kwargs):
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 set_weights has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        def set_weights(self, weights):
          """Sets the weights of the layer, from NumPy arrays.
      
          The weights of a layer represent the state of the layer. This function
          sets the weight values from numpy arrays. The weight values should be
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 _maybe_build has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

        def _maybe_build(self, inputs):
          # Check input assumptions set before layer building, e.g. input rank.
          if not self.built:
            input_spec.assert_input_compatibility(
                self.input_spec, inputs, self.name)
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 losses has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def losses(self):
          """List of losses added using the `add_loss()` API.
      
          Variable regularization tensors are created when this property is accessed,
          so it is eager safe: accessing `losses` under a `tf.GradientTape` will
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 12 (exceeds 5 allowed). Consider refactoring.
      Open

        def __call__(self, *args, **kwargs):
          """Wraps `call`, applying pre- and post-processing steps.
      
          Args:
            *args: Positional arguments to be passed to `self.call`.
      Severity: Minor
      Found in tensorflow/python/keras/engine/base_layer.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 add_weight has 11 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def add_weight(self,
      Severity: Major
      Found in tensorflow/python/keras/engine/base_layer.py - About 1 hr to fix

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

          def __init__(self,
                       trainable=True,
                       name=None,
                       dtype=None,
                       dynamic=False,
        Severity: Minor
        Found in tensorflow/python/keras/engine/base_layer.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 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def __init__(self,
                       trainable=True,
                       name=None,
                       dtype=None,
                       dynamic=False,
        Severity: Minor
        Found in tensorflow/python/keras/engine/base_layer.py - About 1 hr to fix

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

            def _set_mask_metadata(self, inputs, outputs, previous_mask, build_graph):
              # Many `Layer`s don't need to call `compute_mask`.
              # This method is optimized to do as little work as needed for the common
              # case.
              if not self._supports_masking:
          Severity: Minor
          Found in tensorflow/python/keras/engine/base_layer.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 _set_dtype_policy has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def _set_dtype_policy(self, dtype):
              """Sets self._dtype_policy."""
              if isinstance(dtype, policy.Policy):
                self._dtype_policy = dtype
              elif isinstance(dtype, dict):
          Severity: Minor
          Found in tensorflow/python/keras/engine/base_layer.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 add_update has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

            def add_update(self, updates, inputs=None):
              """Add update op(s), potentially dependent on layer inputs.
          
              Weight updates (for instance, the updates of the moving mean and variance
              in a BatchNormalization layer) may be dependent on the inputs passed
          Severity: Minor
          Found in tensorflow/python/keras/engine/base_layer.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

          Avoid deeply nested control flow statements.
          Open

                      if subtrackables:
                        deque.extendleft(reversed(subtrackables))
                  elif isinstance(trackable_obj, data_structures.TrackableDataStructure):
          Severity: Major
          Found in tensorflow/python/keras/engine/base_layer.py - About 45 mins to fix

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

              def _set_call_arg_value(
            Severity: Minor
            Found in tensorflow/python/keras/engine/base_layer.py - About 45 mins to fix

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

                def __init__(self,
              Severity: Minor
              Found in tensorflow/python/keras/engine/base_layer.py - About 35 mins to fix

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

                def _in_functional_construction_mode(layer, inputs, args, kwargs, input_list):  # pylint: disable=unused-argument
                Severity: Minor
                Found in tensorflow/python/keras/engine/base_layer.py - About 35 mins to fix

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

                    def __init__(self,
                  Severity: Minor
                  Found in tensorflow/python/keras/engine/base_layer.py - About 35 mins to fix

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

                      def get_config(self):
                        """Returns the config of the layer.
                    
                        A layer config is a Python dictionary (serializable)
                        containing the configuration of a layer.
                    Severity: Minor
                    Found in tensorflow/python/keras/engine/base_layer.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 _get_input_masks has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def _get_input_masks(self, inputs, input_list, args, kwargs):
                        if not self._supports_masking and not self._expects_mask_arg:
                          # Input masks only need to be retrieved if they are needed for `call`
                          # or `compute_mask`.
                          input_masks = None
                    Severity: Minor
                    Found in tensorflow/python/keras/engine/base_layer.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 _set_call_arg_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def _set_call_arg_value(
                          self, arg_name, new_value, args,
                          kwargs, inputs_in_args=False, pop_kwarg_if_none=False):
                        arg_pos = self._call_fn_arg_positions.get(arg_name, None)
                        if arg_pos is not None:
                    Severity: Minor
                    Found in tensorflow/python/keras/engine/base_layer.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 __delattr__ has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def __delattr__(self, name):
                        # For any super.__delattr__() call, we will directly use the implementation
                        # in Trackable and skip the behavior in AutoTrackable. The Layer was
                        # originally use Trackable as base class, the change of using Module as base
                        # class forced us to have AutoTrackable in the class hierarchy.
                    Severity: Minor
                    Found in tensorflow/python/keras/engine/base_layer.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