The following issues were found

keras/distribute/checkpointing_test.py
77 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 18 Column: 1

              
import os

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
from keras.optimizer_v2 import adam



            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 20 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
from keras.optimizer_v2 import adam


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


            

Reported by Pylint.

Access to a protected member _distribute_strategy of a client class
Error

Line: 75 Column: 46

                      checkpoint.restore(save_path)
    step()
    slot = opt.get_slot(v, "m")
    self.assertEqual(v._distribute_strategy, slot._distribute_strategy)

    v, opt, step = state()
    checkpoint = tf.train.Checkpoint(v=v, opt=opt)
    # Restore from the checkpoint outside a distribution.scope().
    with self.test_session():

            

Reported by Pylint.

Access to a protected member _distribute_strategy of a client class
Error

Line: 75 Column: 22

                      checkpoint.restore(save_path)
    step()
    slot = opt.get_slot(v, "m")
    self.assertEqual(v._distribute_strategy, slot._distribute_strategy)

    v, opt, step = state()
    checkpoint = tf.train.Checkpoint(v=v, opt=opt)
    # Restore from the checkpoint outside a distribution.scope().
    with self.test_session():

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Copyright 2018 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
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software

            

Reported by Pylint.

Missing class docstring
Error

Line: 24 Column: 1

              from keras.optimizer_v2 import adam


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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=[
              tf.__internal__.distribute.combinations.mirrored_strategy_with_one_cpu,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 26 Column: 1

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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=[
              tf.__internal__.distribute.combinations.mirrored_strategy_with_one_cpu,
              tf.__internal__.distribute.combinations.mirrored_strategy_with_gpu_and_cpu,
              tf.__internal__.distribute.combinations.tpu_strategy,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 36 Column: 1

                            tf.__internal__.distribute.combinations.central_storage_strategy_with_two_gpus,
          ],
          mode=["eager"]))
  def testCheckpointRestoreOptimizerSlots(self, distribution):
    def state():
      with distribution.scope():
        v = tf.Variable(tf.random.normal([]))
      opt = adam.Adam(0.001)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 3

                            tf.__internal__.distribute.combinations.central_storage_strategy_with_two_gpus,
          ],
          mode=["eager"]))
  def testCheckpointRestoreOptimizerSlots(self, distribution):
    def state():
      with distribution.scope():
        v = tf.Variable(tf.random.normal([]))
      opt = adam.Adam(0.001)


            

Reported by Pylint.

Method name "testCheckpointRestoreOptimizerSlots" doesn't conform to snake_case naming style
Error

Line: 36 Column: 3

                            tf.__internal__.distribute.combinations.central_storage_strategy_with_two_gpus,
          ],
          mode=["eager"]))
  def testCheckpointRestoreOptimizerSlots(self, distribution):
    def state():
      with distribution.scope():
        v = tf.Variable(tf.random.normal([]))
      opt = adam.Adam(0.001)


            

Reported by Pylint.

keras/distribute/mirrored_strategy_test.py
77 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for MirroredStrategy."""

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np

import keras

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np

import keras
from tensorflow.python.eager import backprop
from keras.engine import training as keras_training

            

Reported by Pylint.

Unable to import 'tensorflow.python.eager'
Error

Line: 23 Column: 1

              import numpy as np

import keras
from tensorflow.python.eager import backprop
from keras.engine import training as keras_training
from keras.layers import core as keras_core
from keras.optimizer_v2 import rmsprop
from keras.utils import kpl_test_utils
from tensorflow.python.training import optimizer as optimizer_lib

            

Reported by Pylint.

Unable to import 'tensorflow.python.training'
Error

Line: 28 Column: 1

              from keras.layers import core as keras_core
from keras.optimizer_v2 import rmsprop
from keras.utils import kpl_test_utils
from tensorflow.python.training import optimizer as optimizer_lib


class MiniModel(keras_training.Model):
  """Minimal model for mnist.


            

Reported by Pylint.

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

Line: 31 Column: 1

              from tensorflow.python.training import optimizer as optimizer_lib


class MiniModel(keras_training.Model):
  """Minimal model for mnist.

  Useful for testing and debugging on slow TPU simulators.
  """


            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 42 Column: 3

                  self.fc = keras_core.Dense(1, name="fc", kernel_initializer="ones",
                               bias_initializer="ones")

  def call(self, inputs, training=True):
    inputs = tf.ones([1, 10])
    return self.fc(inputs)


@tf.__internal__.distribute.combinations.generate(

            

Reported by Pylint.

Imports from package tensorflow are not grouped
Error

Line: 28 Column: 1

              from keras.layers import core as keras_core
from keras.optimizer_v2 import rmsprop
from keras.utils import kpl_test_utils
from tensorflow.python.training import optimizer as optimizer_lib


class MiniModel(keras_training.Model):
  """Minimal model for mnist.


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

              

class MiniModel(keras_training.Model):
  """Minimal model for mnist.

  Useful for testing and debugging on slow TPU simulators.
  """

  def __init__(self):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 37 Column: 1

                Useful for testing and debugging on slow TPU simulators.
  """

  def __init__(self):
    super(MiniModel, self).__init__(name="")
    self.fc = keras_core.Dense(1, name="fc", kernel_initializer="ones",
                               bias_initializer="ones")

  def call(self, inputs, training=True):

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 38 Column: 5

                """

  def __init__(self):
    super(MiniModel, self).__init__(name="")
    self.fc = keras_core.Dense(1, name="fc", kernel_initializer="ones",
                               bias_initializer="ones")

  def call(self, inputs, training=True):
    inputs = tf.ones([1, 10])

            

Reported by Pylint.

keras/distribute/keras_embedding_model_correctness_test.py
77 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Correctness test for tf.keras Embedding models using DistributionStrategy."""

import tensorflow.compat.v2 as tf

import numpy as np

import keras
from keras.distribute import keras_correctness_test_base

            

Reported by Pylint.

Module 'keras.initializers' has no 'RandomUniform' member
Error

Line: 99 Column: 34

                        input_dim=20,
          output_dim=10,
          input_length=max_words,
          embeddings_initializer=keras.initializers.RandomUniform(0, 1))

      a_rep = submodel(word_embed, word_ids_a).outputs[0]
      b_rep = submodel(word_embed, word_ids_b).outputs[0]
      sim = keras.layers.Dot(axes=1, normalize=True)([a_rep, b_rep])


            

Reported by Pylint.

Value 'submodel(word_embed, word_ids_a).outputs' is unsubscriptable
Error

Line: 101 Column: 15

                        input_length=max_words,
          embeddings_initializer=keras.initializers.RandomUniform(0, 1))

      a_rep = submodel(word_embed, word_ids_a).outputs[0]
      b_rep = submodel(word_embed, word_ids_b).outputs[0]
      sim = keras.layers.Dot(axes=1, normalize=True)([a_rep, b_rep])

      model = keras.Model(inputs=[word_ids_a, word_ids_b], outputs=[sim])


            

Reported by Pylint.

Value 'submodel(word_embed, word_ids_b).outputs' is unsubscriptable
Error

Line: 102 Column: 15

                        embeddings_initializer=keras.initializers.RandomUniform(0, 1))

      a_rep = submodel(word_embed, word_ids_a).outputs[0]
      b_rep = submodel(word_embed, word_ids_b).outputs[0]
      sim = keras.layers.Dot(axes=1, normalize=True)([a_rep, b_rep])

      model = keras.Model(inputs=[word_ids_a, word_ids_b], outputs=[sim])

      if initial_weights:

            

Reported by Pylint.

Method 'get_data_with_partial_last_batch' is abstract in class 'TestDistributionStrategyCorrectnessBase' but is not overridden
Error

Line: 26 Column: 1

              from keras.optimizer_v2 import gradient_descent as gradient_descent_keras


class DistributionStrategyEmbeddingModelCorrectnessTest(
    keras_correctness_test_base
    .TestDistributionStrategyEmbeddingModelCorrectnessBase):

  def get_model(self,
                max_words=10,

            

Reported by Pylint.

Method 'get_data_with_partial_last_batch_eval' is abstract in class 'TestDistributionStrategyCorrectnessBase' but is not overridden
Error

Line: 26 Column: 1

              from keras.optimizer_v2 import gradient_descent as gradient_descent_keras


class DistributionStrategyEmbeddingModelCorrectnessTest(
    keras_correctness_test_base
    .TestDistributionStrategyEmbeddingModelCorrectnessBase):

  def get_model(self,
                max_words=10,

            

Reported by Pylint.

Parameters differ from overridden 'get_model' method
Error

Line: 30 Column: 3

                  keras_correctness_test_base
    .TestDistributionStrategyEmbeddingModelCorrectnessBase):

  def get_model(self,
                max_words=10,
                initial_weights=None,
                distribution=None,
                input_shapes=None):
    del input_shapes

            

Reported by Pylint.

Attribute 'use_distributed_dense' defined outside __init__
Error

Line: 62 Column: 5

                def test_embedding_model_correctness(self, distribution, use_numpy,
                                       use_validation_data):

    self.use_distributed_dense = False
    self.run_correctness_test(distribution, use_numpy, use_validation_data)

  @tf.__internal__.distribute.combinations.generate(
      keras_correctness_test_base.test_combinations_for_embedding_model() +
      keras_correctness_test_base.multi_worker_mirrored_eager())

            

Reported by Pylint.

Attribute 'use_distributed_dense' defined outside __init__
Error

Line: 70 Column: 5

                    keras_correctness_test_base.multi_worker_mirrored_eager())
  def test_embedding_time_distributed_model_correctness(
      self, distribution, use_numpy, use_validation_data):
    self.use_distributed_dense = True
    self.run_correctness_test(distribution, use_numpy, use_validation_data)


class DistributionStrategySiameseEmbeddingModelCorrectnessTest(
    keras_correctness_test_base

            

Reported by Pylint.

Method 'get_data_with_partial_last_batch' is abstract in class 'TestDistributionStrategyCorrectnessBase' but is not overridden
Error

Line: 74 Column: 1

                  self.run_correctness_test(distribution, use_numpy, use_validation_data)


class DistributionStrategySiameseEmbeddingModelCorrectnessTest(
    keras_correctness_test_base
    .TestDistributionStrategyEmbeddingModelCorrectnessBase):

  def get_model(self,
                max_words=10,

            

Reported by Pylint.

keras/engine/training_integration_test.py
76 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""End-to-end tests for a variety of small models."""

import tensorflow.compat.v2 as tf

import collections
import itertools

from absl.testing import parameterized

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 22 Column: 1

              import collections
import itertools

from absl.testing import parameterized
import numpy as np

import keras
from keras import keras_parameterized
from keras import testing_utils

            

Reported by Pylint.

Bad option value 'g-complex-comprehension'
Error

Line: 100 Column: 1

              def _gather_test_cases():
  cases = []
  for layer_type, inp_shape, fuzz_dims, arg_dict, filter_fn in _LAYERS_TO_TEST:
    arg_combinations = [[(k, i) for i in v] for k, v in arg_dict.items()]  # pylint: disable=g-complex-comprehension
    for arguments in itertools.product(*arg_combinations):
      layer_kwargs = {k: v for k, v in arguments}
      if filter_fn is not None and not filter_fn(**layer_kwargs):
        continue


            

Reported by Pylint.

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

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

import collections
import itertools

from absl.testing import parameterized
import numpy as np


            

Reported by Pylint.

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

Line: 20 Column: 1

              import tensorflow.compat.v2 as tf

import collections
import itertools

from absl.testing import parameterized
import numpy as np

import keras

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

              

def _conv2d_filter(**kwargs):
  """Convolution with non-default strides and dilation rate is not supported."""
  return kwargs['strides'] <= 1 or kwargs['dilation_rate'] <= 1


# Scheme: (layer_class, data_shape, fuzz_dims, constructor_args, filter_fn)
#   layer_class:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

              
def _conv2d_filter(**kwargs):
  """Convolution with non-default strides and dilation rate is not supported."""
  return kwargs['strides'] <= 1 or kwargs['dilation_rate'] <= 1


# Scheme: (layer_class, data_shape, fuzz_dims, constructor_args, filter_fn)
#   layer_class:
#     A keras Layer class to be tested.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 98 Column: 1

              

def _gather_test_cases():
  cases = []
  for layer_type, inp_shape, fuzz_dims, arg_dict, filter_fn in _LAYERS_TO_TEST:
    arg_combinations = [[(k, i) for i in v] for k, v in arg_dict.items()]  # pylint: disable=g-complex-comprehension
    for arguments in itertools.product(*arg_combinations):
      layer_kwargs = {k: v for k, v in arguments}
      if filter_fn is not None and not filter_fn(**layer_kwargs):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 99 Column: 1

              
def _gather_test_cases():
  cases = []
  for layer_type, inp_shape, fuzz_dims, arg_dict, filter_fn in _LAYERS_TO_TEST:
    arg_combinations = [[(k, i) for i in v] for k, v in arg_dict.items()]  # pylint: disable=g-complex-comprehension
    for arguments in itertools.product(*arg_combinations):
      layer_kwargs = {k: v for k, v in arguments}
      if filter_fn is not None and not filter_fn(**layer_kwargs):
        continue

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 100 Column: 1

              def _gather_test_cases():
  cases = []
  for layer_type, inp_shape, fuzz_dims, arg_dict, filter_fn in _LAYERS_TO_TEST:
    arg_combinations = [[(k, i) for i in v] for k, v in arg_dict.items()]  # pylint: disable=g-complex-comprehension
    for arguments in itertools.product(*arg_combinations):
      layer_kwargs = {k: v for k, v in arguments}
      if filter_fn is not None and not filter_fn(**layer_kwargs):
        continue


            

Reported by Pylint.

keras/layers/kernelized.py
76 issues
Bad option value 'g-classes-have-attributes'
Error

Line: 15 Column: 1

              # See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
# pylint: disable=g-classes-have-attributes
"""Keras layers that implement explicit (approximate) kernel feature maps."""

import tensorflow.compat.v2 as tf

import numpy as np

            

Reported by Pylint.

Unable to import 'tensorflow.compat.v2'
Error

Line: 18 Column: 1

              # pylint: disable=g-classes-have-attributes
"""Keras layers that implement explicit (approximate) kernel feature maps."""

import tensorflow.compat.v2 as tf

import numpy as np
from keras import initializers
from keras.engine import base_layer
from keras.engine import input_spec

            

Reported by Pylint.

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

Line: 24 Column: 1

              from keras import initializers
from keras.engine import base_layer
from keras.engine import input_spec
from tensorflow.python.util.tf_export import keras_export

_SUPPORTED_RBF_KERNEL_TYPES = ['gaussian', 'laplacian']


@keras_export('keras.layers.experimental.RandomFourierFeatures')

            

Reported by Pylint.

TODO(pmol): Allow higher dimension inputs. Currently the input is expected
Error

Line: 166 Column: 3

              
  def build(self, input_shape):
    input_shape = tf.TensorShape(input_shape)
    # TODO(pmol): Allow higher dimension inputs. Currently the input is expected
    # to have shape [batch_size, dimension].
    if input_shape.rank != 2:
      raise ValueError(
          'The rank of the input tensor should be 2. '
          f'Received input with rank {input_shape.ndims} instead. '

            

Reported by Pylint.

Attribute 'unscaled_kernel' defined outside __init__
Error

Line: 184 Column: 5

                  kernel_initializer = _get_random_features_initializer(
        self.kernel_initializer, shape=(input_dim, self.output_dim))

    self.unscaled_kernel = self.add_weight(
        name='unscaled_kernel',
        shape=(input_dim, self.output_dim),
        dtype=tf.float32,
        initializer=kernel_initializer,
        trainable=False)

            

Reported by Pylint.

Attribute 'bias' defined outside __init__
Error

Line: 191 Column: 5

                      initializer=kernel_initializer,
        trainable=False)

    self.bias = self.add_weight(
        name='bias',
        shape=(self.output_dim,),
        dtype=tf.float32,
        initializer=tf.compat.v1.random_uniform_initializer(
            minval=0.0, maxval=2 * np.pi, dtype=tf.float32),

            

Reported by Pylint.

Attribute 'kernel_scale' defined outside __init__
Error

Line: 201 Column: 5

              
    if self.scale is None:
      self.scale = _get_default_scale(self.kernel_initializer, input_dim)
    self.kernel_scale = self.add_weight(
        name='kernel_scale',
        shape=(1,),
        dtype=tf.float32,
        initializer=tf.compat.v1.constant_initializer(self.scale),
        trainable=True,

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 210 Column: 3

                      constraint='NonNeg')
    super(RandomFourierFeatures, self).build(input_shape)

  def call(self, inputs):
    inputs = tf.convert_to_tensor(inputs, dtype=self.dtype)
    inputs = tf.cast(inputs, tf.float32)
    kernel = (1.0 / self.kernel_scale) * self.unscaled_kernel
    outputs = tf.raw_ops.MatMul(a=inputs, b=kernel)
    outputs = tf.nn.bias_add(outputs, self.bias)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

              
@keras_export('keras.layers.experimental.RandomFourierFeatures')
class RandomFourierFeatures(base_layer.Layer):
  r"""Layer that projects its inputs into a random feature space.

  This layer implements a mapping from input space to a space with `output_dim`
  dimensions, which approximates shift-invariant kernels. A kernel function
  `K(x, y)` is shift-invariant if `K(x, y) == k(x - y)` for some function `k`.
  Many popular Radial Basis Functions (RBF), including Gaussian and

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 140 Column: 3

                  name: String, name to use for this layer.
  """

  def __init__(self,
               output_dim,
               kernel_initializer='gaussian',
               scale=None,
               trainable=False,
               name=None,

            

Reported by Pylint.

keras/layers/preprocessing/preprocessing_test_utils.py
76 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 19 Column: 1

              
import collections
import numpy as np
import tensorflow.compat.v2 as tf


class PreprocessingLayerTest(tf.test.TestCase):
  """Base test class for preprocessing layer API validation."""
  # TODO(b/137303934): Consider incorporating something like this Close vs All

            

Reported by Pylint.

TODO(b/137303934): Consider incorporating something like this Close vs All
Error

Line: 24 Column: 3

              
class PreprocessingLayerTest(tf.test.TestCase):
  """Base test class for preprocessing layer API validation."""
  # TODO(b/137303934): Consider incorporating something like this Close vs All
  # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 23 Column: 1

              

class PreprocessingLayerTest(tf.test.TestCase):
  """Base test class for preprocessing layer API validation."""
  # TODO(b/137303934): Consider incorporating something like this Close vs All
  # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""

            

Reported by Pylint.

Method name "assertAllCloseOrEqual" doesn't conform to snake_case naming style
Error

Line: 27 Column: 3

                # TODO(b/137303934): Consider incorporating something like this Close vs All
  # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 27 Column: 1

                # TODO(b/137303934): Consider incorporating something like this Close vs All
  # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))

            

Reported by Pylint.

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

Line: 27 Column: 3

                # TODO(b/137303934): Consider incorporating something like this Close vs All
  # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))

            

Reported by Pylint.

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

Line: 27 Column: 3

                # TODO(b/137303934): Consider incorporating something like this Close vs All
  # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 28 Column: 1

                # behavior into core tf.test.TestCase.

  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))
      for a_value, b_value in zip(a, b):

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 29 Column: 1

              
  def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))
      for a_value, b_value in zip(a, b):
        self.assertAllCloseOrEqual(a_value, b_value, msg=msg)

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 30 Column: 1

                def assertAllCloseOrEqual(self, a, b, msg=None):
    """Asserts that elements are close (if numeric) or equal (if string)."""
    if a is None or b is None:
      self.assertAllEqual(a, b, msg=msg)
    elif isinstance(a, (list, tuple)):
      self.assertEqual(len(a), len(b))
      for a_value, b_value in zip(a, b):
        self.assertAllCloseOrEqual(a_value, b_value, msg=msg)
    elif isinstance(a, collections.abc.Mapping):

            

Reported by Pylint.

keras/layers/advanced_activations_test.py
76 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for advanced activation layers."""

import tensorflow.compat.v2 as tf

import numpy as np

import keras
from keras import keras_parameterized

            

Reported by Pylint.

Missing class docstring
Error

Line: 27 Column: 1

              

@keras_parameterized.run_all_keras_modes
class AdvancedActivationsTest(keras_parameterized.TestCase):

  def test_leaky_relu(self):
    for alpha in [0., .5]:
      testing_utils.layer_test(keras.layers.LeakyReLU,
                               kwargs={'alpha': alpha},

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              @keras_parameterized.run_all_keras_modes
class AdvancedActivationsTest(keras_parameterized.TestCase):

  def test_leaky_relu(self):
    for alpha in [0., .5]:
      testing_utils.layer_test(keras.layers.LeakyReLU,
                               kwargs={'alpha': alpha},
                               input_shape=(2, 3, 4),
                               supports_masking=True)

            

Reported by Pylint.

Method could be a function
Error

Line: 29 Column: 3

              @keras_parameterized.run_all_keras_modes
class AdvancedActivationsTest(keras_parameterized.TestCase):

  def test_leaky_relu(self):
    for alpha in [0., .5]:
      testing_utils.layer_test(keras.layers.LeakyReLU,
                               kwargs={'alpha': alpha},
                               input_shape=(2, 3, 4),
                               supports_masking=True)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 29 Column: 3

              @keras_parameterized.run_all_keras_modes
class AdvancedActivationsTest(keras_parameterized.TestCase):

  def test_leaky_relu(self):
    for alpha in [0., .5]:
      testing_utils.layer_test(keras.layers.LeakyReLU,
                               kwargs={'alpha': alpha},
                               input_shape=(2, 3, 4),
                               supports_masking=True)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 30 Column: 1

              class AdvancedActivationsTest(keras_parameterized.TestCase):

  def test_leaky_relu(self):
    for alpha in [0., .5]:
      testing_utils.layer_test(keras.layers.LeakyReLU,
                               kwargs={'alpha': alpha},
                               input_shape=(2, 3, 4),
                               supports_masking=True)


            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 31 Column: 1

              
  def test_leaky_relu(self):
    for alpha in [0., .5]:
      testing_utils.layer_test(keras.layers.LeakyReLU,
                               kwargs={'alpha': alpha},
                               input_shape=(2, 3, 4),
                               supports_masking=True)

  def test_prelu(self):

            

Reported by Pylint.

Method could be a function
Error

Line: 36 Column: 3

                                             input_shape=(2, 3, 4),
                               supports_masking=True)

  def test_prelu(self):
    testing_utils.layer_test(keras.layers.PReLU, kwargs={},
                             input_shape=(2, 3, 4),
                             supports_masking=True)

  def test_prelu_share(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 3

                                             input_shape=(2, 3, 4),
                               supports_masking=True)

  def test_prelu(self):
    testing_utils.layer_test(keras.layers.PReLU, kwargs={},
                             input_shape=(2, 3, 4),
                             supports_masking=True)

  def test_prelu_share(self):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 36 Column: 1

                                             input_shape=(2, 3, 4),
                               supports_masking=True)

  def test_prelu(self):
    testing_utils.layer_test(keras.layers.PReLU, kwargs={},
                             input_shape=(2, 3, 4),
                             supports_masking=True)

  def test_prelu_share(self):

            

Reported by Pylint.

keras/layers/preprocessing/index_lookup_distribution_test.py
75 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Distribution tests for keras.layers.preprocessing.index_lookup."""

import tensorflow.compat.v2 as tf

import os
import numpy as np

import keras

            

Reported by Pylint.

TODO(b/180614455): remove this check when MLIR bridge is always enabled.
Error

Line: 49 Column: 3

                  return vocab_path

  def test_strategy(self, strategy):
    # TODO(b/180614455): remove this check when MLIR bridge is always enabled.
    if backend.is_tpu_strategy(strategy):
      self.skipTest("This test needs MLIR bridge on TPU.")

    vocab_data = [[
        "earth", "earth", "earth", "earth", "wind", "wind", "wind", "and",

            

Reported by Pylint.

TODO(b/180614455): remove this check when MLIR bridge is always enabled.
Error

Line: 82 Column: 3

                  self.assertAllEqual(expected_output, output_dataset)

  def test_strategy_with_file(self, strategy):
    # TODO(b/180614455): remove this check when MLIR bridge is always enabled.
    if backend.is_tpu_strategy(strategy):
      self.skipTest("This test needs MLIR bridge on TPU.")

    vocab_data = ["earth", "wind", "and", "fire"]
    vocab_file = self._write_to_temp_file("temp", vocab_data)

            

Reported by Pylint.

TODO(b/180614455): remove this check when MLIR bridge is always enabled.
Error

Line: 113 Column: 3

                  self.assertAllEqual(expected_output, output_dataset)

  def test_tpu_with_multiple_oov(self, strategy):
    # TODO(b/180614455): remove this check when MLIR bridge is always enabled.
    if backend.is_tpu_strategy(strategy):
      self.skipTest("This test needs MLIR bridge on TPU.")

    vocab_data = [[
        "earth", "earth", "earth", "earth", "wind", "wind", "wind", "and",

            

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 numpy as np

import keras
from keras import backend
from keras import keras_parameterized

            

Reported by Pylint.

Missing class docstring
Error

Line: 35 Column: 1

                      strategy=strategy_combinations.all_strategies +
        strategy_combinations.multi_worker_mirrored_strategies,
        mode=["eager"]))  # Eager-only, no graph: b/158793009
class IndexLookupDistributionTest(
    keras_parameterized.TestCase,
    preprocessing_test_utils.PreprocessingLayerTest):

  def _write_to_temp_file(self, file_name, vocab_list):
    vocab_path = os.path.join(self.get_temp_dir(), file_name + ".txt")

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 39 Column: 1

                  keras_parameterized.TestCase,
    preprocessing_test_utils.PreprocessingLayerTest):

  def _write_to_temp_file(self, file_name, vocab_list):
    vocab_path = os.path.join(self.get_temp_dir(), file_name + ".txt")
    with tf.io.gfile.GFile(vocab_path, "w") as writer:
      for vocab in vocab_list:
        writer.write(vocab + "\n")
      writer.flush()

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 40 Column: 1

                  preprocessing_test_utils.PreprocessingLayerTest):

  def _write_to_temp_file(self, file_name, vocab_list):
    vocab_path = os.path.join(self.get_temp_dir(), file_name + ".txt")
    with tf.io.gfile.GFile(vocab_path, "w") as writer:
      for vocab in vocab_list:
        writer.write(vocab + "\n")
      writer.flush()
      writer.close()

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 41 Column: 1

              
  def _write_to_temp_file(self, file_name, vocab_list):
    vocab_path = os.path.join(self.get_temp_dir(), file_name + ".txt")
    with tf.io.gfile.GFile(vocab_path, "w") as writer:
      for vocab in vocab_list:
        writer.write(vocab + "\n")
      writer.flush()
      writer.close()
    return vocab_path

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 42 Column: 1

                def _write_to_temp_file(self, file_name, vocab_list):
    vocab_path = os.path.join(self.get_temp_dir(), file_name + ".txt")
    with tf.io.gfile.GFile(vocab_path, "w") as writer:
      for vocab in vocab_list:
        writer.write(vocab + "\n")
      writer.flush()
      writer.close()
    return vocab_path


            

Reported by Pylint.

keras/legacy_tf_layers/pooling.py
75 issues
Bad option value 'g-classes-have-attributes'
Error

Line: 15 Column: 1

              # See the License for the specific language governing permissions and
# limitations under the License.
# =============================================================================
# pylint: disable=g-classes-have-attributes
"""Contains the pooling layer classes and their functional aliases."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


            

Reported by Pylint.

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

Line: 25 Column: 1

              
from keras import layers as keras_layers
from keras.legacy_tf_layers import base
from tensorflow.python.util.tf_export import keras_export
from tensorflow.python.util.tf_export import tf_export


@keras_export(v1=['keras.__internal__.legacy.layers.AveragePooling1D'])
@tf_export(v1=['layers.AveragePooling1D'])

            

Reported by Pylint.

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

Line: 26 Column: 1

              from keras import layers as keras_layers
from keras.legacy_tf_layers import base
from tensorflow.python.util.tf_export import keras_export
from tensorflow.python.util.tf_export import tf_export


@keras_export(v1=['keras.__internal__.legacy.layers.AveragePooling1D'])
@tf_export(v1=['layers.AveragePooling1D'])
class AveragePooling1D(keras_layers.AveragePooling1D, base.Layer):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

              @keras_export(v1=['keras.__internal__.legacy.layers.AveragePooling1D'])
@tf_export(v1=['layers.AveragePooling1D'])
class AveragePooling1D(keras_layers.AveragePooling1D, base.Layer):
  """Average Pooling layer for 1D inputs.

  Args:
    pool_size: An integer or tuple/list of a single integer,
      representing the size of the pooling window.
    strides: An integer or tuple/list of a single integer, specifying the

            

Reported by Pylint.

Too many arguments (6/5)
Error

Line: 76 Column: 3

                @end_compatibility
  """

  def __init__(self, pool_size, strides,
               padding='valid', data_format='channels_last',
               name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 76 Column: 1

                @end_compatibility
  """

  def __init__(self, pool_size, strides,
               padding='valid', data_format='channels_last',
               name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 79 Column: 1

                def __init__(self, pool_size, strides,
               padding='valid', data_format='channels_last',
               name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(
        pool_size=pool_size,
        strides=strides,
        padding=padding,

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 80 Column: 1

                             padding='valid', data_format='channels_last',
               name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(
        pool_size=pool_size,
        strides=strides,
        padding=padding,
        data_format=data_format,

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 81 Column: 5

                             name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(
        pool_size=pool_size,
        strides=strides,
        padding=padding,
        data_format=data_format,
        name=name,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 81 Column: 1

                             name=None, **kwargs):
    if strides is None:
      raise ValueError('Argument `strides` must not be None.')
    super(AveragePooling1D, self).__init__(
        pool_size=pool_size,
        strides=strides,
        padding=padding,
        data_format=data_format,
        name=name,

            

Reported by Pylint.

keras/mixed_precision/layer_correctness_test.py
75 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests various Layer subclasses have correct outputs with mixed precision."""

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np
from keras import keras_parameterized
from keras import layers

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np
from keras import keras_parameterized
from keras import layers
from keras import models
from keras.layers import advanced_activations

            

Reported by Pylint.

Value 'f32_model.outputs' is unsubscriptable
Error

Line: 251 Column: 36

                      atol=atol)

    # Run fit() on models
    output = np.random.normal(size=f32_model.outputs[0].shape).astype('float16')
    for model in f32_model, mp_model, distributed_mp_model:
      model.fit(input_data, output, batch_size=global_batch_size)

    # Assert all models have close weights
    f32_weights = f32_model.get_weights()

            

Reported by Pylint.

Access to a protected member _compute_dtype of a client class
Error

Line: 204 Column: 31

                  f32_layer = f32_layer_fn()

    # Create the layers
    assert f32_layer.dtype == f32_layer._compute_dtype == 'float32'
    config = f32_layer.get_config()
    config['dtype'] = policy.Policy('mixed_float16')
    mp_layer = f32_layer.__class__.from_config(config)
    distributed_mp_layer = f32_layer.__class__.from_config(config)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 44 Column: 1

              from keras.mixed_precision import policy


def create_mirrored_strategy():
  # The test creates two virtual CPUs, and we use both of them to test with
  # multiple devices.
  return tf.distribute.MirroredStrategy(['cpu:0', 'cpu:1'])



            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 47 Column: 1

              def create_mirrored_strategy():
  # The test creates two virtual CPUs, and we use both of them to test with
  # multiple devices.
  return tf.distribute.MirroredStrategy(['cpu:0', 'cpu:1'])


def _create_normalization_layer_with_adapt():
  layer = normalization.Normalization()
  layer.adapt(np.random.normal(size=(10, 4)))

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 51 Column: 1

              

def _create_normalization_layer_with_adapt():
  layer = normalization.Normalization()
  layer.adapt(np.random.normal(size=(10, 4)))
  return layer


def _create_normalization_layer_without_adapt():

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 52 Column: 1

              
def _create_normalization_layer_with_adapt():
  layer = normalization.Normalization()
  layer.adapt(np.random.normal(size=(10, 4)))
  return layer


def _create_normalization_layer_without_adapt():
  return normalization.Normalization(

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 53 Column: 1

              def _create_normalization_layer_with_adapt():
  layer = normalization.Normalization()
  layer.adapt(np.random.normal(size=(10, 4)))
  return layer


def _create_normalization_layer_without_adapt():
  return normalization.Normalization(
      mean=np.random.normal(size=(4,)),

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 57 Column: 1

              

def _create_normalization_layer_without_adapt():
  return normalization.Normalization(
      mean=np.random.normal(size=(4,)),
      variance=np.random.uniform(0.5, 2., size=(4,))
  )



            

Reported by Pylint.