The following issues were found

keras/saving/saved_model/utils.py
149 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Utility functions shared between SavedModel saving/loading implementations."""

import tensorflow.compat.v2 as tf

import itertools
import threading
import types
from keras import backend as K

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 22 Column: 1

              import itertools
import threading
import types
from keras import backend as K
from keras.engine import base_layer_utils
from keras.utils import control_flow_util
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from keras.utils.generic_utils import LazyLoader

            

Reported by Pylint.

Unable to import 'keras.engine'
Error

Line: 23 Column: 1

              import threading
import types
from keras import backend as K
from keras.engine import base_layer_utils
from keras.utils import control_flow_util
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from keras.utils.generic_utils import LazyLoader


            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 24 Column: 1

              import types
from keras import backend as K
from keras.engine import base_layer_utils
from keras.utils import control_flow_util
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from keras.utils.generic_utils import LazyLoader



            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 25 Column: 1

              from keras import backend as K
from keras.engine import base_layer_utils
from keras.utils import control_flow_util
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from keras.utils.generic_utils import LazyLoader


# pylint:disable=g-inconsistent-quotes

            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 26 Column: 1

              from keras.engine import base_layer_utils
from keras.utils import control_flow_util
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from keras.utils.generic_utils import LazyLoader


# pylint:disable=g-inconsistent-quotes
training_lib = LazyLoader(

            

Reported by Pylint.

Unable to import 'keras.utils.generic_utils'
Error

Line: 27 Column: 1

              from keras.utils import control_flow_util
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from keras.utils.generic_utils import LazyLoader


# pylint:disable=g-inconsistent-quotes
training_lib = LazyLoader(
    "training_lib", globals(),

            

Reported by Pylint.

Bad option value 'g-inconsistent-quotes'
Error

Line: 30 Column: 1

              from keras.utils.generic_utils import LazyLoader


# pylint:disable=g-inconsistent-quotes
training_lib = LazyLoader(
    "training_lib", globals(),
    "keras.engine.training")
# pylint:enable=g-inconsistent-quotes


            

Reported by Pylint.

Bad option value 'g-inconsistent-quotes'
Error

Line: 34 Column: 1

              training_lib = LazyLoader(
    "training_lib", globals(),
    "keras.engine.training")
# pylint:enable=g-inconsistent-quotes


def use_wrapped_call(layer, call_fn, default_training_value=None,
                     return_method=False):
  """Creates fn that adds the losses returned by call_fn & returns the outputs.

            

Reported by Pylint.

TODO(kathywu): This is a temporary hack. When a network of layers is
Error

Line: 71 Column: 3

                  outputs, losses = fn(*args, **kwargs)
    layer.add_loss(losses, inputs=True)

    # TODO(kathywu): This is a temporary hack. When a network of layers is
    # revived from SavedModel, only the top-level layer will have losses. This
    # causes issues in eager mode because the child layers may have graph losses
    # (thus model.losses returns a mix of Eager and graph tensors). To fix this,
    # whenever eager losses are added to one layer, add eager losses to all
    # child layers. This causes `.losses` to only return eager losses.

            

Reported by Pylint.

keras/tests/integration_test.py
149 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Integration tests for Keras."""

import tensorflow.compat.v2 as tf

import os
import random

import numpy as np

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 24 Column: 1

              
import numpy as np

import keras
from keras import keras_parameterized
from keras import testing_utils
from keras.layers.legacy_rnn import rnn_cell_impl as rnn_cell
from keras.legacy_tf_layers import base as base_layer
from keras.utils import np_utils

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 25 Column: 1

              import numpy as np

import keras
from keras import keras_parameterized
from keras import testing_utils
from keras.layers.legacy_rnn import rnn_cell_impl as rnn_cell
from keras.legacy_tf_layers import base as base_layer
from keras.utils import np_utils


            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 26 Column: 1

              
import keras
from keras import keras_parameterized
from keras import testing_utils
from keras.layers.legacy_rnn import rnn_cell_impl as rnn_cell
from keras.legacy_tf_layers import base as base_layer
from keras.utils import np_utils



            

Reported by Pylint.

Unable to import 'keras.layers.legacy_rnn'
Error

Line: 27 Column: 1

              import keras
from keras import keras_parameterized
from keras import testing_utils
from keras.layers.legacy_rnn import rnn_cell_impl as rnn_cell
from keras.legacy_tf_layers import base as base_layer
from keras.utils import np_utils


class KerasIntegrationTest(keras_parameterized.TestCase):

            

Reported by Pylint.

Unable to import 'keras.legacy_tf_layers'
Error

Line: 28 Column: 1

              from keras import keras_parameterized
from keras import testing_utils
from keras.layers.legacy_rnn import rnn_cell_impl as rnn_cell
from keras.legacy_tf_layers import base as base_layer
from keras.utils import np_utils


class KerasIntegrationTest(keras_parameterized.TestCase):


            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 29 Column: 1

              from keras import testing_utils
from keras.layers.legacy_rnn import rnn_cell_impl as rnn_cell
from keras.legacy_tf_layers import base as base_layer
from keras.utils import np_utils


class KerasIntegrationTest(keras_parameterized.TestCase):

  def _save_and_reload_model(self, model):

            

Reported by Pylint.

Attribute 'temp_dir' defined outside __init__
Error

Line: 35 Column: 5

              class KerasIntegrationTest(keras_parameterized.TestCase):

  def _save_and_reload_model(self, model):
    self.temp_dir = self.get_temp_dir()
    fpath = os.path.join(self.temp_dir,
                         'test_model_%s' % (random.randint(0, 1e7),))
    if tf.executing_eagerly():
      save_format = 'tf'
    else:

            

Reported by Pylint.

Access to a protected member _is_graph_network of a client class
Error

Line: 42 Column: 15

                    save_format = 'tf'
    else:
      if (not isinstance(model, keras.Sequential) and
          not model._is_graph_network):
        return model  # Not supported
      save_format = 'h5'
    model.save(fpath, save_format=save_format)
    model = keras.models.load_model(fpath)
    return model

            

Reported by Pylint.

standard import "import os" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

import os
import random

import numpy as np

import keras

            

Reported by Pylint.

keras/layers/core/lambda_layer.py
148 issues
Bad option value 'g-classes-have-attributes'
Error

Line: 16 Column: 1

              # limitations under the License.
# ==============================================================================
"""Contains the Lambda layer."""
# pylint: disable=g-classes-have-attributes,g-direct-tensorflow-import
import sys
import textwrap
import types as python_types
import warnings
from keras.engine.base_layer import Layer

            

Reported by Pylint.

Bad option value 'g-direct-tensorflow-import'
Error

Line: 16 Column: 1

              # limitations under the License.
# ==============================================================================
"""Contains the Lambda layer."""
# pylint: disable=g-classes-have-attributes,g-direct-tensorflow-import
import sys
import textwrap
import types as python_types
import warnings
from keras.engine.base_layer import Layer

            

Reported by Pylint.

Unable to import 'tensorflow.compat.v2'
Error

Line: 26 Column: 1

              from keras.utils import tf_inspect
from keras.utils import tf_utils
import numpy as np
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.layers.Lambda')

            

Reported by Pylint.

Unable to import 'tensorflow.python.platform'
Error

Line: 27 Column: 1

              from keras.utils import tf_utils
import numpy as np
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.layers.Lambda')
class Lambda(Layer):

            

Reported by Pylint.

Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 28 Column: 1

              import numpy as np
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.layers.Lambda')
class Lambda(Layer):
  """Wraps arbitrary expressions as a `Layer` object.

            

Reported by Pylint.

Consider explicitly re-raising using the 'from' keyword
Error

Line: 160 Column: 11

                      try:
          return super(Lambda, self).compute_output_shape(input_shape)
        except NotImplementedError:
          raise NotImplementedError(
              'We could not automatically infer the shape of the Lambda\'s '
              'output. Please specify `output_shape` for this Lambda.')

    if callable(self._output_shape):
      output_shapes = self._output_shape(input_shape)

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 179 Column: 3

                  output_shapes = tf_utils.convert_shapes(self._output_shape, to_tuples=False)
    return tf.nest.map_structure(_add_batch, output_shapes)

  def call(self, inputs, mask=None, training=None):
    # We must copy for thread safety, but it only needs to be a shallow copy.
    kwargs = {k: v for k, v in self.arguments.items()}
    if self._fn_expects_mask_arg:
      kwargs['mask'] = mask
    if self._fn_expects_training_arg:

            

Reported by Pylint.

Parameters differ from overridden 'from_config' method
Error

Line: 295 Column: 3

                  return output, output_type, module

  @classmethod
  def from_config(cls, config, custom_objects=None):
    config = config.copy()
    function = cls._parse_function_from_config(config, custom_objects,
                                               'function', 'module',
                                               'function_type')


            

Reported by Pylint.

Too many instance attributes (8/7)
Error

Line: 32 Column: 1

              

@keras_export('keras.layers.Lambda')
class Lambda(Layer):
  """Wraps arbitrary expressions as a `Layer` object.

  The `Lambda` layer exists so that arbitrary expressions can be used
  as a `Layer` when constructing `Sequential`
  and Functional API models. `Lambda` layers are best suited for simple

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 33 Column: 1

              
@keras_export('keras.layers.Lambda')
class Lambda(Layer):
  """Wraps arbitrary expressions as a `Layer` object.

  The `Lambda` layer exists so that arbitrary expressions can be used
  as a `Layer` when constructing `Sequential`
  and Functional API models. `Lambda` layers are best suited for simple
  operations or quick experimentation. For more advanced use cases, follow

            

Reported by Pylint.

keras/utils/version_utils_test.py
148 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for Keras utilities to split v1 and v2 classes."""

import tensorflow.compat.v2 as tf

import abc

import numpy as np


            

Reported by Pylint.

Method 'get_config' is abstract in class 'Model' but is not overridden
Error

Line: 58 Column: 5

                  inputs = keras.Input(10)
    outputs = keras.layers.Dense(1)(inputs)

    class MyModel(keras.Model):
      pass

    model = MyModel(inputs, outputs)
    model_class = model.__class__.__bases__[0].__bases__[0]
    self._check_model_class(model_class)

            

Reported by Pylint.

Method 'call' is abstract in class 'Model' but is not overridden
Error

Line: 58 Column: 5

                  inputs = keras.Input(10)
    outputs = keras.layers.Dense(1)(inputs)

    class MyModel(keras.Model):
      pass

    model = MyModel(inputs, outputs)
    model_class = model.__class__.__bases__[0].__bases__[0]
    self._check_model_class(model_class)

            

Reported by Pylint.

Method 'get_config' is abstract in class 'Model' but is not overridden
Error

Line: 75 Column: 5

                  inputs = keras.Input(10)
    outputs = keras.layers.Dense(1)(inputs)

    class MyModel(keras.Model):
      pass

    model = MyModel(inputs, outputs)
    model_class = model.__class__.__bases__[0].__bases__[0]
    self._check_model_class(model_class)

            

Reported by Pylint.

Method 'call' is abstract in class 'Model' but is not overridden
Error

Line: 75 Column: 5

                  inputs = keras.Input(10)
    outputs = keras.layers.Dense(1)(inputs)

    class MyModel(keras.Model):
      pass

    model = MyModel(inputs, outputs)
    model_class = model.__class__.__bases__[0].__bases__[0]
    self._check_model_class(model_class)

            

Reported by Pylint.

Method 'get_config' is abstract in class 'Model' but is not overridden
Error

Line: 91 Column: 5

              
  def test_subclass_model(self):

    class MyModel(keras.Model):

      def call(self, x):
        return 2 * x

    model = MyModel()

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 93 Column: 7

              
    class MyModel(keras.Model):

      def call(self, x):
        return 2 * x

    model = MyModel()
    model_class = model.__class__.__bases__[0]
    self._check_model_class(model_class)

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 108 Column: 7

                    Useful for testing a layer without a variable.
      """

      def call(self, inputs):
        return inputs

    layer = IdentityLayer()
    self._check_layer_class(layer)


            

Reported by Pylint.

Method 'call' is abstract in class 'Model' but is not overridden
Error

Line: 116 Column: 5

              
  def test_multiple_subclass_model(self):

    class Model1(keras.Model):
      pass

    class Model2(Model1):

      def call(self, x):

            

Reported by Pylint.

Method 'get_config' is abstract in class 'Model' but is not overridden
Error

Line: 116 Column: 5

              
  def test_multiple_subclass_model(self):

    class Model1(keras.Model):
      pass

    class Model2(Model1):

      def call(self, x):

            

Reported by Pylint.

keras/saving/saved_model_experimental.py
147 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Deprecated experimental Keras SavedModel implementation."""

import tensorflow.compat.v2 as tf

import os
import warnings
from keras import backend
from keras import optimizer_v1

            

Reported by Pylint.

Unable to import 'tensorflow.python.platform'
Error

Line: 29 Column: 1

              from keras.saving import utils_v1 as model_utils
from keras.utils import mode_keys
from keras.utils.generic_utils import LazyLoader
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export

# To avoid circular dependencies between keras/engine and keras/saving,
# code in keras/saving must delay imports.


            

Reported by Pylint.

Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 30 Column: 1

              from keras.utils import mode_keys
from keras.utils.generic_utils import LazyLoader
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export

# To avoid circular dependencies between keras/engine and keras/saving,
# code in keras/saving must delay imports.

# TODO(b/134426265): Switch back to single-quotes to match the rest of the file

            

Reported by Pylint.

Bad option value 'g-inconsistent-quotes'
Error

Line: 37 Column: 1

              
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
# pylint:disable=g-inconsistent-quotes
metrics_lib = LazyLoader("metrics_lib", globals(),
                         "keras.metrics")
models_lib = LazyLoader("models_lib", globals(),
                        "keras.models")
sequential = LazyLoader(

            

Reported by Pylint.

Bad option value 'g-inconsistent-quotes'
Error

Line: 45 Column: 1

              sequential = LazyLoader(
    "sequential", globals(),
    "keras.engine.sequential")
# pylint:enable=g-inconsistent-quotes


# File name for json format of SavedModel.
SAVED_MODEL_FILENAME_JSON = 'saved_model.json'


            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 251 Column: 3

                      f'Cannot export mode {mode}.')

  model_graph = tf.compat.v1.get_default_graph()
  with tf.Graph().as_default() as g, backend.learning_phase_scope(
      mode == mode_keys.ModeKeys.TRAIN):

    if input_signature is None:
      input_tensors = None
    else:

            

Reported by Pylint.

TODO(b/134426265): Switch back to single-quotes to match the rest of the file
Error

Line: 35 Column: 3

              # To avoid circular dependencies between keras/engine and keras/saving,
# code in keras/saving must delay imports.

# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
# pylint:disable=g-inconsistent-quotes
metrics_lib = LazyLoader("metrics_lib", globals(),
                         "keras.metrics")
models_lib = LazyLoader("models_lib", globals(),

            

Reported by Pylint.

TODO(kathywu): Build the model with input_signature to create the
Error

Line: 167 Column: 3

                                       'called on inputs or `build()` is called with an '
                         '`input_shape`, or the first layer in the model has '
                         '`input_shape` during construction.')
      # TODO(kathywu): Build the model with input_signature to create the
      # weights before _export_model_variables().
    else:
      raise NotImplementedError(
          'Subclassed models can only be exported for serving. Please set '
          'argument serving_only=True.')

            

Reported by Pylint.

TODO(b/113134168): Add fn to Builder to save with object-based saver.
Error

Line: 179 Column: 3

                # Manually save variables to export them in an object-based checkpoint. This
  # skips the `builder.add_meta_graph_and_variables()` step, which saves a
  # named-based checkpoint.
  # TODO(b/113134168): Add fn to Builder to save with object-based saver.
  # TODO(b/113178242): This should only export the model json structure. Only
  # one save is needed once the weights can be copied from the model to clone.
  checkpoint_path = _export_model_variables(model, path)

  # Export each mode. Use ModeKeys enums defined for `Estimator` to ensure that

            

Reported by Pylint.

TODO(b/113178242): This should only export the model json structure. Only
Error

Line: 180 Column: 3

                # skips the `builder.add_meta_graph_and_variables()` step, which saves a
  # named-based checkpoint.
  # TODO(b/113134168): Add fn to Builder to save with object-based saver.
  # TODO(b/113178242): This should only export the model json structure. Only
  # one save is needed once the weights can be copied from the model to clone.
  checkpoint_path = _export_model_variables(model, path)

  # Export each mode. Use ModeKeys enums defined for `Estimator` to ensure that
  # Keras models and `Estimator`s are exported with the same format.

            

Reported by Pylint.

keras/keras_parameterized.py
145 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Utilities for unit-testing Keras."""

import tensorflow.compat.v2 as tf

import collections
import functools
import itertools
import unittest

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 24 Column: 1

              import itertools
import unittest

from absl.testing import parameterized

import keras
from keras import testing_utils

try:

            

Reported by Pylint.

Bad option value 'g-import-not-at-top'
Error

Line: 30 Column: 1

              from keras import testing_utils

try:
  import h5py  # pylint:disable=g-import-not-at-top
except ImportError:
  h5py = None


class TestCase(tf.test.TestCase, parameterized.TestCase):

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 155 Column: 3

              

def _test_h5_saved_model_format(f, test_or_class, *args, **kwargs):
  with testing_utils.saved_model_format_scope('h5'):
    f(test_or_class, *args, **kwargs)


def _test_tf_saved_model_format(f, test_or_class, *args, **kwargs):
  with testing_utils.saved_model_format_scope('tf'):

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 160 Column: 3

              

def _test_tf_saved_model_format(f, test_or_class, *args, **kwargs):
  with testing_utils.saved_model_format_scope('tf'):
    f(test_or_class, *args, **kwargs)


def _test_tf_saved_model_format_no_traces(f, test_or_class, *args, **kwargs):
  with testing_utils.saved_model_format_scope('tf', save_traces=False):

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 165 Column: 3

              

def _test_tf_saved_model_format_no_traces(f, test_or_class, *args, **kwargs):
  with testing_utils.saved_model_format_scope('tf', save_traces=False):
    f(test_or_class, *args, **kwargs)


def run_with_all_weight_formats(test_or_class=None, exclude_formats=None):
  """Runs all tests with the supported formats for saving weights."""

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 295 Column: 3

              

def _test_functional_model_type(f, test_or_class, *args, **kwargs):
  with testing_utils.model_type_scope('functional'):
    f(test_or_class, *args, **kwargs)


def _test_subclass_model_type(f, test_or_class, *args, **kwargs):
  with testing_utils.model_type_scope('subclass'):

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 300 Column: 3

              

def _test_subclass_model_type(f, test_or_class, *args, **kwargs):
  with testing_utils.model_type_scope('subclass'):
    f(test_or_class, *args, **kwargs)


def _test_sequential_model_type(f, test_or_class, *args, **kwargs):
  with testing_utils.model_type_scope('sequential'):

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 305 Column: 3

              

def _test_sequential_model_type(f, test_or_class, *args, **kwargs):
  with testing_utils.model_type_scope('sequential'):
    f(test_or_class, *args, **kwargs)


def run_all_keras_modes(test_or_class=None,
                        config=None,

            

Reported by Pylint.

Context manager 'generator' doesn't implement __enter__ and __exit__.
Error

Line: 415 Column: 5

              
def _v1_session_test(f, test_or_class, config, *args, **kwargs):
  with tf.compat.v1.get_default_graph().as_default():
    with testing_utils.run_eagerly_scope(False):
      with test_or_class.test_session(config=config):
        f(test_or_class, *args, **kwargs)


def _v2_eager_test(f, test_or_class, *args, **kwargs):

            

Reported by Pylint.

keras/preprocessing/sequence_test.py
143 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for sequence data preprocessing utils."""

import tensorflow.compat.v2 as tf

from math import ceil

import numpy as np


            

Reported by Pylint.

Access to a protected member _remove_long_seq of a client class
Error

Line: 100 Column: 26

                def test_remove_long_seq(self):
    a = [[[1, 1]], [[2, 1], [2, 2]], [[3, 1], [3, 2], [3, 3]]]

    new_seq, new_label = preprocessing_sequence._remove_long_seq(
        maxlen=3, seq=a, label=['a', 'b', ['c', 'd']])
    self.assertEqual(new_seq, [[[1, 1]], [[2, 1], [2, 2]]])
    self.assertEqual(new_label, ['a', 'b'])

  def test_TimeseriesGenerator(self):

            

Reported by Pylint.

standard import "from math import ceil" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from math import ceil

import numpy as np

from keras.preprocessing import sequence as preprocessing_sequence


            

Reported by Pylint.

Missing class docstring
Error

Line: 26 Column: 1

              from keras.preprocessing import sequence as preprocessing_sequence


class TestSequence(tf.test.TestCase):

  def test_pad_sequences(self):
    a = [[1], [1, 2], [1, 2, 3]]

    # test padding

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 3

              
class TestSequence(tf.test.TestCase):

  def test_pad_sequences(self):
    a = [[1], [1, 2], [1, 2, 3]]

    # test padding
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='pre')
    self.assertAllClose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]])

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

              
class TestSequence(tf.test.TestCase):

  def test_pad_sequences(self):
    a = [[1], [1, 2], [1, 2, 3]]

    # test padding
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='pre')
    self.assertAllClose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]])

            

Reported by Pylint.

Variable name "a" doesn't conform to snake_case naming style
Error

Line: 29 Column: 5

              class TestSequence(tf.test.TestCase):

  def test_pad_sequences(self):
    a = [[1], [1, 2], [1, 2, 3]]

    # test padding
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='pre')
    self.assertAllClose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]])
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='post')

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 29 Column: 1

              class TestSequence(tf.test.TestCase):

  def test_pad_sequences(self):
    a = [[1], [1, 2], [1, 2, 3]]

    # test padding
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='pre')
    self.assertAllClose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]])
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='post')

            

Reported by Pylint.

Variable name "b" doesn't conform to snake_case naming style
Error

Line: 32 Column: 5

                  a = [[1], [1, 2], [1, 2, 3]]

    # test padding
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='pre')
    self.assertAllClose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]])
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='post')
    self.assertAllClose(b, [[1, 0, 0], [1, 2, 0], [1, 2, 3]])

    # test truncating

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 32 Column: 1

                  a = [[1], [1, 2], [1, 2, 3]]

    # test padding
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='pre')
    self.assertAllClose(b, [[0, 0, 1], [0, 1, 2], [1, 2, 3]])
    b = preprocessing_sequence.pad_sequences(a, maxlen=3, padding='post')
    self.assertAllClose(b, [[1, 0, 0], [1, 2, 0], [1, 2, 3]])

    # test truncating

            

Reported by Pylint.

keras/applications/efficientnet.py
143 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 24 Column: 1

                    https://arxiv.org/abs/1905.11946) (ICML 2019)
"""

import tensorflow.compat.v2 as tf

import copy
import math

from keras import backend

            

Reported by Pylint.

Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 35 Column: 1

              from keras.layers import VersionAwareLayers
from keras.utils import data_utils
from keras.utils import layer_utils
from tensorflow.python.util.tf_export import keras_export


BASE_WEIGHTS_PATH = 'https://storage.googleapis.com/keras-applications/'

WEIGHTS_HASHES = {

            

Reported by Pylint.

standard import "import copy" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 26 Column: 1

              
import tensorflow.compat.v2 as tf

import copy
import math

from keras import backend
from keras.applications import imagenet_utils
from keras.engine import training

            

Reported by Pylint.

standard import "import math" should be placed before "import tensorflow.compat.v2 as tf"
Error

Line: 27 Column: 1

              import tensorflow.compat.v2 as tf

import copy
import math

from keras import backend
from keras.applications import imagenet_utils
from keras.engine import training
from keras.layers import VersionAwareLayers

            

Reported by Pylint.

Too many branches (19/12)
Error

Line: 207 Column: 1

              """


def EfficientNet(
    width_coefficient,
    depth_coefficient,
    default_size,
    dropout_rate=0.2,
    drop_connect_rate=0.2,

            

Reported by Pylint.

Too many statements (67/50)
Error

Line: 207 Column: 1

              """


def EfficientNet(
    width_coefficient,
    depth_coefficient,
    default_size,
    dropout_rate=0.2,
    drop_connect_rate=0.2,

            

Reported by Pylint.

Too many arguments (16/5)
Error

Line: 207 Column: 1

              """


def EfficientNet(
    width_coefficient,
    depth_coefficient,
    default_size,
    dropout_rate=0.2,
    drop_connect_rate=0.2,

            

Reported by Pylint.

Too many local variables (32/15)
Error

Line: 207 Column: 1

              """


def EfficientNet(
    width_coefficient,
    depth_coefficient,
    default_size,
    dropout_rate=0.2,
    drop_connect_rate=0.2,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 224 Column: 1

                  pooling=None,
    classes=1000,
    classifier_activation='softmax'):
  """Instantiates the EfficientNet architecture using given scaling coefficients.

  Args:
    width_coefficient: float, scaling coefficient for network width.
    depth_coefficient: float, scaling coefficient for network depth.
    default_size: integer, default input image size.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 274 Column: 1

                  ValueError: if `classifier_activation` is not `softmax` or `None` when
      using a pretrained top layer.
  """
  if blocks_args == 'default':
    blocks_args = DEFAULT_BLOCKS_ARGS

  if not (weights in {'imagenet', None} or tf.io.gfile.exists(weights)):
    raise ValueError('The `weights` argument should be either '
                     '`None` (random initialization), `imagenet` '

            

Reported by Pylint.

keras/applications/inception_resnet_v2.py
141 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 24 Column: 1

                  (AAAI 2017)
"""

import tensorflow.compat.v2 as tf

from keras import backend
from keras.applications import imagenet_utils
from keras.engine import training
from keras.layers import VersionAwareLayers

            

Reported by Pylint.

Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 32 Column: 1

              from keras.layers import VersionAwareLayers
from keras.utils import data_utils
from keras.utils import layer_utils
from tensorflow.python.util.tf_export import keras_export


BASE_WEIGHT_URL = ('https://storage.googleapis.com/tensorflow/'
                   'keras-applications/inception_resnet_v2/')
layers = None

            

Reported by Pylint.

Using the global statement
Error

Line: 112 Column: 3

                Returns:
    A `keras.Model` instance.
  """
  global layers
  if 'layers' in kwargs:
    layers = kwargs.pop('layers')
  else:
    layers = VersionAwareLayers()
  if kwargs:

            

Reported by Pylint.

Too many arguments (7/5)
Error

Line: 42 Column: 1

              
@keras_export('keras.applications.inception_resnet_v2.InceptionResNetV2',
              'keras.applications.InceptionResNetV2')
def InceptionResNetV2(include_top=True,
                      weights='imagenet',
                      input_tensor=None,
                      input_shape=None,
                      pooling=None,
                      classes=1000,

            

Reported by Pylint.

Too many local variables (21/15)
Error

Line: 42 Column: 1

              
@keras_export('keras.applications.inception_resnet_v2.InceptionResNetV2',
              'keras.applications.InceptionResNetV2')
def InceptionResNetV2(include_top=True,
                      weights='imagenet',
                      input_tensor=None,
                      input_shape=None,
                      pooling=None,
                      classes=1000,

            

Reported by Pylint.

Too many branches (20/12)
Error

Line: 42 Column: 1

              
@keras_export('keras.applications.inception_resnet_v2.InceptionResNetV2',
              'keras.applications.InceptionResNetV2')
def InceptionResNetV2(include_top=True,
                      weights='imagenet',
                      input_tensor=None,
                      input_shape=None,
                      pooling=None,
                      classes=1000,

            

Reported by Pylint.

Too many statements (82/50)
Error

Line: 42 Column: 1

              
@keras_export('keras.applications.inception_resnet_v2.InceptionResNetV2',
              'keras.applications.InceptionResNetV2')
def InceptionResNetV2(include_top=True,
                      weights='imagenet',
                      input_tensor=None,
                      input_shape=None,
                      pooling=None,
                      classes=1000,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 50 Column: 1

                                    classes=1000,
                      classifier_activation='softmax',
                      **kwargs):
  """Instantiates the Inception-ResNet v2 architecture.

  Reference:
  - [Inception-v4, Inception-ResNet and the Impact of
     Residual Connections on Learning](https://arxiv.org/abs/1602.07261)
    (AAAI 2017)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 112 Column: 1

                Returns:
    A `keras.Model` instance.
  """
  global layers
  if 'layers' in kwargs:
    layers = kwargs.pop('layers')
  else:
    layers = VersionAwareLayers()
  if kwargs:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 113 Column: 1

                  A `keras.Model` instance.
  """
  global layers
  if 'layers' in kwargs:
    layers = kwargs.pop('layers')
  else:
    layers = VersionAwareLayers()
  if kwargs:
    raise ValueError('Unknown argument(s): %s' % (kwargs,))

            

Reported by Pylint.

keras/utils/metrics_utils_test.py
141 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for metrics_utils."""

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
from keras import combinations
from keras.utils import metrics_utils


            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
from keras import combinations
from keras.utils import metrics_utils


@combinations.generate(combinations.combine(mode=['graph', 'eager']))

            

Reported by Pylint.

Bad option value 'g-error-prone-assert-raises'
Error

Line: 210 Column: 1

                def test_failing_different_ragged_and_dense_ranks(self, x_list, y_list):
    x = tf.ragged.constant(x_list)
    y = tf.ragged.constant(y_list)
    with self.assertRaises(ValueError):  # pylint: disable=g-error-prone-assert-raises
      [x, y
      ], _ = metrics_utils.ragged_assert_compatible_and_get_flat_values([x, y])

  @parameterized.parameters([
      {

            

Reported by Pylint.

Bad option value 'g-error-prone-assert-raises'
Error

Line: 225 Column: 1

                  x = tf.ragged.constant(x_list)
    y = tf.ragged.constant(y_list)
    mask = tf.ragged.constant(mask_list)
    with self.assertRaises(ValueError):  # pylint: disable=g-error-prone-assert-raises
      [x, y
      ], _ = metrics_utils.ragged_assert_compatible_and_get_flat_values([x, y],
                                                                        mask)

  # we do not support such cases that ragged_ranks are different but overall

            

Reported by Pylint.

Bad option value 'g-error-prone-assert-raises'
Error

Line: 238 Column: 1

                  # adding a ragged dimension
    x = tf.RaggedTensor.from_row_splits(dt, row_splits=[0, 1])
    y = tf.ragged.constant([[[[1, 2]]]])
    with self.assertRaises(ValueError):  # pylint: disable=g-error-prone-assert-raises
      [x, y], _ = \
          metrics_utils.ragged_assert_compatible_and_get_flat_values([x, y])


@combinations.generate(combinations.combine(mode=['graph', 'eager']))

            

Reported by Pylint.

Access to a protected member _filter_top_k of a client class
Error

Line: 248 Column: 27

              
  def test_one_dimensional(self):
    x = tf.constant([.3, .1, .2, -.5, 42.])
    top_1 = self.evaluate(metrics_utils._filter_top_k(x=x, k=1))
    top_2 = self.evaluate(metrics_utils._filter_top_k(x=x, k=2))
    top_3 = self.evaluate(metrics_utils._filter_top_k(x=x, k=3))

    self.assertAllClose(top_1, [
        metrics_utils.NEG_INF, metrics_utils.NEG_INF, metrics_utils.NEG_INF,

            

Reported by Pylint.

Access to a protected member _filter_top_k of a client class
Error

Line: 249 Column: 27

                def test_one_dimensional(self):
    x = tf.constant([.3, .1, .2, -.5, 42.])
    top_1 = self.evaluate(metrics_utils._filter_top_k(x=x, k=1))
    top_2 = self.evaluate(metrics_utils._filter_top_k(x=x, k=2))
    top_3 = self.evaluate(metrics_utils._filter_top_k(x=x, k=3))

    self.assertAllClose(top_1, [
        metrics_utils.NEG_INF, metrics_utils.NEG_INF, metrics_utils.NEG_INF,
        metrics_utils.NEG_INF, 42.

            

Reported by Pylint.

Access to a protected member _filter_top_k of a client class
Error

Line: 250 Column: 27

                  x = tf.constant([.3, .1, .2, -.5, 42.])
    top_1 = self.evaluate(metrics_utils._filter_top_k(x=x, k=1))
    top_2 = self.evaluate(metrics_utils._filter_top_k(x=x, k=2))
    top_3 = self.evaluate(metrics_utils._filter_top_k(x=x, k=3))

    self.assertAllClose(top_1, [
        metrics_utils.NEG_INF, metrics_utils.NEG_INF, metrics_utils.NEG_INF,
        metrics_utils.NEG_INF, 42.
    ])

            

Reported by Pylint.

Access to a protected member _filter_top_k of a client class
Error

Line: 266 Column: 27

                def test_three_dimensional(self):
    x = tf.constant([[[.3, .1, .2], [-.3, -.2, -.1]],
                              [[5., .2, 42.], [-.3, -.6, -.99]]])
    top_2 = self.evaluate(metrics_utils._filter_top_k(x=x, k=2))

    self.assertAllClose(
        top_2,
        [[[.3, metrics_utils.NEG_INF, .2], [metrics_utils.NEG_INF, -.2, -.1]],
         [[5., metrics_utils.NEG_INF, 42.], [-.3, -.6, metrics_utils.NEG_INF]]])

            

Reported by Pylint.

Access to a protected member _filter_top_k of a client class
Error

Line: 283 Column: 14

                    # This loses the static shape.
      x = tf.numpy_function(_identity, (x,), tf.float32)

      return metrics_utils._filter_top_k(x=x, k=2)

    x = tf.constant([.3, .1, .2, -.5, 42.])
    top_2 = self.evaluate(_filter_top_k(x))
    self.assertAllClose(top_2, [
        .3, metrics_utils.NEG_INF, metrics_utils.NEG_INF, metrics_utils.NEG_INF,

            

Reported by Pylint.