The following issues were found

keras/layers/legacy_rnn/rnn_cell_impl.py
624 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
"""Module implementing RNN Cells.

This module provides a number of basic commonly used RNN cells, such as LSTM
(Long Short Term Memory) or GRU (Gated Recurrent Unit), and a number of
operators that allow adding dropouts, projections, or embeddings for inputs.

            

Reported by Pylint.

Unable to import 'tensorflow.compat.v2'
Error

Line: 28 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow.compat.v2 as tf

import collections
import warnings
from keras import activations
from keras import backend

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 32 Column: 1

              
import collections
import warnings
from keras import activations
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 33 Column: 1

              import collections
import warnings
from keras import activations
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 34 Column: 1

              import warnings
from keras import activations
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer
from keras.utils import tf_utils

            

Reported by Pylint.

Unable to import 'keras.engine'
Error

Line: 35 Column: 1

              from keras import activations
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging

            

Reported by Pylint.

Unable to import 'keras.engine'
Error

Line: 36 Column: 1

              from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export

            

Reported by Pylint.

Unable to import 'keras.layers.legacy_rnn'
Error

Line: 37 Column: 1

              from keras import initializers
from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
from tensorflow.python.util.tf_export import tf_export

            

Reported by Pylint.

Unable to import 'keras.legacy_tf_layers'
Error

Line: 38 Column: 1

              from keras.engine import base_layer_utils
from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
from tensorflow.python.util.tf_export import tf_export


            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 39 Column: 1

              from keras.engine import input_spec
from keras.layers.legacy_rnn import rnn_cell_wrapper_impl
from keras.legacy_tf_layers import base as base_layer
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
from tensorflow.python.util.tf_export import tf_export

_BIAS_VARIABLE_NAME = "bias"

            

Reported by Pylint.

keras/utils/generic_utils.py
585 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Python utilities required by Keras."""

import tensorflow.compat.v2 as tf

import binascii
import codecs
import importlib
import marshal

            

Reported by Pylint.

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

Line: 36 Column: 1

              
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from tensorflow.python.util.tf_export import keras_export

# Flag that determines whether to skip the NotImplementedError when calling
# get_config in custom models and layers. This is only enabled when saving to
# SavedModel, when the config isn't required.
_SKIP_FAILED_SERIALIZATION = False

            

Reported by Pylint.

Bad option value 'g-classes-have-attributes'
Error

Line: 58 Column: 1

              GLOBAL_CUSTOM_OBJECTS = CustomObjectsContext()


@keras_export('keras.utils.custom_object_scope',  # pylint: disable=g-classes-have-attributes
              'keras.utils.CustomObjectScope')
class CustomObjectScope:
  """Exposes custom classes/functions to Keras deserialization internals.

  Under a scope `with custom_object_scope(objects_dict)`, Keras methods such

            

Reported by Pylint.

Bad option value 'g-bad-exception-name'
Error

Line: 469 Column: 1

                return None


# pylint: disable=g-bad-exception-name
class CustomMaskWarning(Warning):
  pass
# pylint: enable=g-bad-exception-name



            

Reported by Pylint.

Bad option value 'g-bad-exception-name'
Error

Line: 472 Column: 1

              # pylint: disable=g-bad-exception-name
class CustomMaskWarning(Warning):
  pass
# pylint: enable=g-bad-exception-name


@keras_export('keras.utils.serialize_keras_object')
def serialize_keras_object(instance):
  """Serialize a Keras object into a JSON-compatible representation.

            

Reported by Pylint.

Attribute '_orig_loading_scope' defined outside __init__
Error

Line: 164 Column: 5

              
  def __enter__(self):
    SHARED_OBJECT_DISABLED.disabled = True
    self._orig_loading_scope = _shared_object_loading_scope()
    self._orig_saving_scope = _shared_object_saving_scope()

  def __exit__(self, *args, **kwargs):
    SHARED_OBJECT_DISABLED.disabled = False
    SHARED_OBJECT_LOADING.scope = self._orig_loading_scope

            

Reported by Pylint.

Attribute '_orig_saving_scope' defined outside __init__
Error

Line: 165 Column: 5

                def __enter__(self):
    SHARED_OBJECT_DISABLED.disabled = True
    self._orig_loading_scope = _shared_object_loading_scope()
    self._orig_saving_scope = _shared_object_saving_scope()

  def __exit__(self, *args, **kwargs):
    SHARED_OBJECT_DISABLED.disabled = False
    SHARED_OBJECT_LOADING.scope = self._orig_loading_scope
    SHARED_OBJECT_SAVING.scope = self._orig_saving_scope

            

Reported by Pylint.

Using the global statement
Error

Line: 200 Column: 5

                  if _shared_object_disabled():
      return NoopLoadingScope()

    global SHARED_OBJECT_LOADING
    SHARED_OBJECT_LOADING.scope = self
    self._obj_ids_to_obj = {}
    return self

  def get(self, object_id):

            

Reported by Pylint.

Attribute '_obj_ids_to_obj' defined outside __init__
Error

Line: 202 Column: 5

              
    global SHARED_OBJECT_LOADING
    SHARED_OBJECT_LOADING.scope = self
    self._obj_ids_to_obj = {}
    return self

  def get(self, object_id):
    """Given a shared object ID, returns a previously instantiated object.


            

Reported by Pylint.

Using the global statement
Error

Line: 228 Column: 5

                  self._obj_ids_to_obj[object_id] = obj

  def __exit__(self, *args, **kwargs):
    global SHARED_OBJECT_LOADING
    SHARED_OBJECT_LOADING.scope = NoopLoadingScope()


class SharedObjectConfig(dict):
  """A configuration container that keeps track of references.

            

Reported by Pylint.

keras/tests/tracking_test.py
582 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
import numpy
from keras import combinations
from keras import keras_parameterized

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 20 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy
from keras import combinations
from keras import keras_parameterized
from keras.engine import sequential
from keras.engine import training

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 22 Column: 1

              
from absl.testing import parameterized
import numpy
from keras import combinations
from keras import keras_parameterized
from keras.engine import sequential
from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 23 Column: 1

              from absl.testing import parameterized
import numpy
from keras import combinations
from keras import keras_parameterized
from keras.engine import sequential
from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures

            

Reported by Pylint.

Unable to import 'keras.engine'
Error

Line: 24 Column: 1

              import numpy
from keras import combinations
from keras import keras_parameterized
from keras.engine import sequential
from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures
from tensorflow.python.training.tracking import util

            

Reported by Pylint.

Unable to import 'keras.engine'
Error

Line: 25 Column: 1

              from keras import combinations
from keras import keras_parameterized
from keras.engine import sequential
from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures
from tensorflow.python.training.tracking import util


            

Reported by Pylint.

Unable to import 'keras.layers'
Error

Line: 26 Column: 1

              from keras import keras_parameterized
from keras.engine import sequential
from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures
from tensorflow.python.training.tracking import util



            

Reported by Pylint.

Unable to import 'keras.layers.normalization'
Error

Line: 27 Column: 1

              from keras.engine import sequential
from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures
from tensorflow.python.training.tracking import util


class HasList(training.Model):

            

Reported by Pylint.

Unable to import 'tensorflow.python.training.tracking'
Error

Line: 28 Column: 1

              from keras.engine import training
from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures
from tensorflow.python.training.tracking import util


class HasList(training.Model):


            

Reported by Pylint.

Unable to import 'tensorflow.python.training.tracking'
Error

Line: 29 Column: 1

              from keras.layers import core
from keras.layers.normalization import batch_normalization_v1
from tensorflow.python.training.tracking import data_structures
from tensorflow.python.training.tracking import util


class HasList(training.Model):

  def __init__(self):

            

Reported by Pylint.

keras/legacy_tf_layers/base_test.py
574 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 21 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow.compat.v2 as tf

import copy

from absl.testing import parameterized
import numpy as np

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 25 Column: 1

              
import copy

from absl.testing import parameterized
import numpy as np
from keras import backend
from keras import combinations
from keras.engine import base_layer as keras_base_layer
from keras.engine import input_spec

            

Reported by Pylint.

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

Line: 80 Column: 5

                        'my_var', [2, 2], initializer=tf.compat.v1.zeros_initializer())
    self.assertEqual(variable.name, 'my_layer/my_var:0')

    with base_layers.keras_style_scope():
      layer = base_layers.Layer(name='my_layer')
    # Assert that the layer was not instrumented as a Keras layer
    self.assertFalse(layer._instrumented_keras_api)
    # Test basic variable creation.
    with backend.name_scope('bar'):

            

Reported by Pylint.

Access to a protected member _instrumented_keras_api of a client class
Error

Line: 52 Column: 22

                  self.assertEqual(layer.trainable, False)

    # Assert that the layer was not instrumented as a Keras layer
    self.assertFalse(layer._instrumented_keras_api)

    # Assert this was instrumented as a legacy layer
    self.assertTrue(
        keras_base_layer.keras_api_gauge.get_cell('legacy_layer').value())
    keras_base_layer.keras_api_gauge.get_cell('legacy_layer').set(False)

            

Reported by Pylint.

Access to a protected member _instrumented_keras_api of a client class
Error

Line: 83 Column: 22

                  with base_layers.keras_style_scope():
      layer = base_layers.Layer(name='my_layer')
    # Assert that the layer was not instrumented as a Keras layer
    self.assertFalse(layer._instrumented_keras_api)
    # Test basic variable creation.
    with backend.name_scope('bar'):
      variable = layer.add_variable(
          'my_var', [2, 2], initializer=tf.compat.v1.zeros_initializer())
    self.assertEqual(variable.name, 'bar/my_var:0')

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 185 Column: 7

              
    class MyLayer(base_layers.Layer):

      def call(self, inputs):
        return tf.square(inputs)

    layer = MyLayer(name='my_layer')
    inputs = tf.random.uniform((5,), seed=1)
    outputs = layer.apply(inputs)

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 201 Column: 7

              
    class MyLayer(base_layers.Layer):

      def call(self, inputs):
        return tf.square(inputs)

    layer = MyLayer(name='my_layer')
    layer._private_tensor = tf.random.uniform(())
    inputs = tf.random.uniform((5,), seed=1)

            

Reported by Pylint.

Access to a protected member _private_tensor of a client class
Error

Line: 205 Column: 5

                      return tf.square(inputs)

    layer = MyLayer(name='my_layer')
    layer._private_tensor = tf.random.uniform(())
    inputs = tf.random.uniform((5,), seed=1)
    outputs = layer.apply(inputs)
    self.assertEqual(layer.built, True)
    if not tf.executing_eagerly():
      # op only supported in GRAPH mode.

            

Reported by Pylint.

Attribute '_private_tensor' defined outside __init__
Error

Line: 205 Column: 5

                      return tf.square(inputs)

    layer = MyLayer(name='my_layer')
    layer._private_tensor = tf.random.uniform(())
    inputs = tf.random.uniform((5,), seed=1)
    outputs = layer.apply(inputs)
    self.assertEqual(layer.built, True)
    if not tf.executing_eagerly():
      # op only supported in GRAPH mode.

            

Reported by Pylint.

Access to a protected member _scope of a client class
Error

Line: 215 Column: 22

              
    layer_copy = copy.deepcopy(layer)
    self.assertEqual(layer_copy.name, layer.name)
    self.assertEqual(layer_copy._scope.name, layer._scope.name)
    self.assertEqual(layer_copy._private_tensor, layer._private_tensor)

  @combinations.generate(combinations.combine(mode=['graph', 'eager']))
  def testScopeNaming(self):


            

Reported by Pylint.

keras/optimizer_v2/optimizer_v2.py
570 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Version 2 of class Optimizer."""

import tensorflow.compat.v2 as tf
# pylint: disable=g-bad-name

import abc
import contextlib
import functools

            

Reported by Pylint.

Bad option value 'g-bad-name'
Error

Line: 18 Column: 1

              """Version 2 of class Optimizer."""

import tensorflow.compat.v2 as tf
# pylint: disable=g-bad-name

import abc
import contextlib
import functools
import warnings

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 24 Column: 1

              import contextlib
import functools
import warnings
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 25 Column: 1

              import functools
import warnings
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils

            

Reported by Pylint.

Unable to import 'keras.engine'
Error

Line: 26 Column: 1

              import warnings
from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils
from keras.utils import tf_inspect

            

Reported by Pylint.

Unable to import 'keras.optimizer_v2'
Error

Line: 27 Column: 1

              from keras import backend
from keras import initializers
from keras.engine import base_layer_utils
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils
from keras.utils import tf_inspect
from keras.utils import tf_utils

            

Reported by Pylint.

Unable to import 'keras.optimizer_v2'
Error

Line: 28 Column: 1

              from keras import initializers
from keras.engine import base_layer_utils
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils
from keras.utils import tf_inspect
from keras.utils import tf_utils
from tensorflow.python.util.tf_export import keras_export

            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 29 Column: 1

              from keras.engine import base_layer_utils
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils
from keras.utils import tf_inspect
from keras.utils import tf_utils
from tensorflow.python.util.tf_export import keras_export


            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 30 Column: 1

              from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils
from keras.utils import tf_inspect
from keras.utils import tf_utils
from tensorflow.python.util.tf_export import keras_export



            

Reported by Pylint.

Unable to import 'keras.utils'
Error

Line: 31 Column: 1

              from keras.optimizer_v2 import utils as optimizer_utils
from keras.utils import generic_utils
from keras.utils import layer_utils
from keras.utils import tf_inspect
from keras.utils import tf_utils
from tensorflow.python.util.tf_export import keras_export


keras_optimizers_gauge = tf.__internal__.monitoring.BoolGauge(

            

Reported by Pylint.

keras/engine/compile_utils_test.py
569 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for compile utitilies."""

import tensorflow.compat.v2 as tf
from keras import backend
from keras import keras_parameterized
from keras import losses as losses_mod
from keras import metrics as metrics_mod
from keras.engine import compile_utils

            

Reported by Pylint.

Access to a protected member _built of a client class
Error

Line: 32 Column: 21

                  y_t, y_p = tf.ones((10, 5)), tf.zeros((10, 5))
    total_loss = loss_container(y_t, y_p)

    self.assertTrue(loss_container._built)
    self.assertLen(loss_container._losses, 1)
    self.assertEqual(total_loss.numpy(), 1.)
    self.assertLen(loss_container.metrics, 1)

    loss_metric = loss_container.metrics[0]

            

Reported by Pylint.

Access to a protected member _losses of a client class
Error

Line: 33 Column: 20

                  total_loss = loss_container(y_t, y_p)

    self.assertTrue(loss_container._built)
    self.assertLen(loss_container._losses, 1)
    self.assertEqual(total_loss.numpy(), 1.)
    self.assertLen(loss_container.metrics, 1)

    loss_metric = loss_container.metrics[0]
    self.assertEqual(loss_metric.name, 'loss')

            

Reported by Pylint.

Access to a protected member _output_names of a client class
Error

Line: 53 Column: 22

              
    total_loss = loss_container(y_t, y_p, sample_weight=sw)

    self.assertEqual(loss_container._output_names, ['output_1', 'output_2'])

    self.assertLen(loss_container._losses, 2)
    self.assertEqual(total_loss.numpy(), 0.25)

    loss_metric = loss_container.metrics[0]

            

Reported by Pylint.

Access to a protected member _losses of a client class
Error

Line: 55 Column: 20

              
    self.assertEqual(loss_container._output_names, ['output_1', 'output_2'])

    self.assertLen(loss_container._losses, 2)
    self.assertEqual(total_loss.numpy(), 0.25)

    loss_metric = loss_container.metrics[0]
    self.assertEqual(loss_metric.name, 'loss')
    self.assertEqual(loss_metric.result().numpy(), 0.25)

            

Reported by Pylint.

Access to a protected member _losses of a client class
Error

Line: 91 Column: 20

              
    total_loss = loss_container(y_t, y_p, sample_weight=sw)

    self.assertLen(loss_container._losses, 2)
    self.assertEqual(total_loss.numpy(), 0.25)
    self.assertLen(loss_container.metrics, 3)

    loss_metric = loss_container.metrics[0]
    self.assertEqual(loss_metric.name, 'loss')

            

Reported by Pylint.

Access to a protected member _keras_mask of a client class
Error

Line: 301 Column: 5

                  loss_container = compile_utils.LossesContainer('mae')
    y_p = tf.constant([[[1], [1]], [[0], [0]]], dtype=tf.float32)
    y_t = tf.constant([[[1], [1]], [[1], [1]]], dtype=tf.float32)
    y_p._keras_mask = tf.constant([[1, 0], [1, 0]],
                                           dtype=tf.float32)

    total_loss = loss_container(y_t, y_p)
    self.assertAlmostEqual(total_loss.numpy(), .25)  # sum over batch size


            

Reported by Pylint.

Access to a protected member _keras_mask of a client class
Error

Line: 332 Column: 5

                  y_p = tf.constant([[[1], [1]], [[0], [0]]], dtype=tf.float32)
    y_t = tf.constant([[[1], [1]], [[1], [1]]], dtype=tf.float32)
    sw = tf.constant([[.2, .3], [.5, 0]], dtype=tf.float32)
    y_p._keras_mask = tf.constant([[1, 0], [1, 0]],
                                           dtype=tf.float32)

    total_loss = loss_container(y_t, y_p, sample_weight=sw)
    # (0 * .2 + 1 * .5) / 4
    self.assertAlmostEqual(total_loss.numpy(), .125)  # sum over batch size

            

Reported by Pylint.

Access to a protected member _losses of a client class
Error

Line: 359 Column: 22

                  y_t, y_p = tf.ones((10, 5)), tf.zeros((10, 5))
    loss_container(y_t, y_p)

    self.assertEqual(loss_container._losses[0].name, 'custom_loss_fn')
    self.assertEqual(loss_container._losses[1].name, 'custom_loss_class')

  def test_ragged_tensor_output(self):
    """Ensure that ragged tensors can be passed as targets and predictions."""


            

Reported by Pylint.

Access to a protected member _losses of a client class
Error

Line: 360 Column: 22

                  loss_container(y_t, y_p)

    self.assertEqual(loss_container._losses[0].name, 'custom_loss_fn')
    self.assertEqual(loss_container._losses[1].name, 'custom_loss_class')

  def test_ragged_tensor_output(self):
    """Ensure that ragged tensors can be passed as targets and predictions."""

    def custom_loss_fn(y_true, y_pred):

            

Reported by Pylint.

keras/feature_column/dense_features_test.py
563 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 21 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np
from tensorflow.python.eager import backprop
from tensorflow.python.framework import test_util

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 23 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np
from tensorflow.python.eager import backprop
from tensorflow.python.framework import test_util
from keras import combinations
from keras import keras_parameterized

            

Reported by Pylint.

Unable to import 'tensorflow.python.eager'
Error

Line: 25 Column: 1

              
from absl.testing import parameterized
import numpy as np
from tensorflow.python.eager import backprop
from tensorflow.python.framework import test_util
from keras import combinations
from keras import keras_parameterized
from keras.feature_column import dense_features as df


            

Reported by Pylint.

Unable to import 'tensorflow.python.framework'
Error

Line: 26 Column: 1

              from absl.testing import parameterized
import numpy as np
from tensorflow.python.eager import backprop
from tensorflow.python.framework import test_util
from keras import combinations
from keras import keras_parameterized
from keras.feature_column import dense_features as df



            

Reported by Pylint.

Access to a protected member _var_offset of a client class
Error

Line: 104 Column: 16

                  embedding_dimension = 2

    def _embedding_column_initializer(shape, dtype, partition_info=None):
      offset = partition_info._var_offset[0]
      del shape  # unused
      del dtype  # unused
      if offset == 0:
        embedding_values = (
            (1, 0),  # id 0

            

Reported by Pylint.

Access to a protected member _feature_columns of a client class
Error

Line: 1070 Column: 20

              
    self.assertEqual(new_layer.name, orig_layer.name)
    self.assertEqual(new_layer.trainable, trainable)
    self.assertLen(new_layer._feature_columns, 3)
    self.assertEqual(new_layer._feature_columns[0].name, 'a')
    self.assertEqual(new_layer._feature_columns[1].initializer.mean, 0.0)
    self.assertEqual(new_layer._feature_columns[1].categorical_column.name, 'b')
    self.assertIsInstance(new_layer._feature_columns[0], cols[0].__class__)
    self.assertIsInstance(new_layer._feature_columns[1], cols[1].__class__)

            

Reported by Pylint.

Access to a protected member _feature_columns of a client class
Error

Line: 1071 Column: 22

                  self.assertEqual(new_layer.name, orig_layer.name)
    self.assertEqual(new_layer.trainable, trainable)
    self.assertLen(new_layer._feature_columns, 3)
    self.assertEqual(new_layer._feature_columns[0].name, 'a')
    self.assertEqual(new_layer._feature_columns[1].initializer.mean, 0.0)
    self.assertEqual(new_layer._feature_columns[1].categorical_column.name, 'b')
    self.assertIsInstance(new_layer._feature_columns[0], cols[0].__class__)
    self.assertIsInstance(new_layer._feature_columns[1], cols[1].__class__)
    self.assertIsInstance(new_layer._feature_columns[2], cols[2].__class__)

            

Reported by Pylint.

Access to a protected member _feature_columns of a client class
Error

Line: 1072 Column: 22

                  self.assertEqual(new_layer.trainable, trainable)
    self.assertLen(new_layer._feature_columns, 3)
    self.assertEqual(new_layer._feature_columns[0].name, 'a')
    self.assertEqual(new_layer._feature_columns[1].initializer.mean, 0.0)
    self.assertEqual(new_layer._feature_columns[1].categorical_column.name, 'b')
    self.assertIsInstance(new_layer._feature_columns[0], cols[0].__class__)
    self.assertIsInstance(new_layer._feature_columns[1], cols[1].__class__)
    self.assertIsInstance(new_layer._feature_columns[2], cols[2].__class__)


            

Reported by Pylint.

Access to a protected member _feature_columns of a client class
Error

Line: 1073 Column: 22

                  self.assertLen(new_layer._feature_columns, 3)
    self.assertEqual(new_layer._feature_columns[0].name, 'a')
    self.assertEqual(new_layer._feature_columns[1].initializer.mean, 0.0)
    self.assertEqual(new_layer._feature_columns[1].categorical_column.name, 'b')
    self.assertIsInstance(new_layer._feature_columns[0], cols[0].__class__)
    self.assertIsInstance(new_layer._feature_columns[1], cols[1].__class__)
    self.assertIsInstance(new_layer._feature_columns[2], cols[2].__class__)

  def test_crossed_column(self):

            

Reported by Pylint.

Access to a protected member _feature_columns of a client class
Error

Line: 1074 Column: 27

                  self.assertEqual(new_layer._feature_columns[0].name, 'a')
    self.assertEqual(new_layer._feature_columns[1].initializer.mean, 0.0)
    self.assertEqual(new_layer._feature_columns[1].categorical_column.name, 'b')
    self.assertIsInstance(new_layer._feature_columns[0], cols[0].__class__)
    self.assertIsInstance(new_layer._feature_columns[1], cols[1].__class__)
    self.assertIsInstance(new_layer._feature_columns[2], cols[2].__class__)

  def test_crossed_column(self):
    a = tf.feature_column.categorical_column_with_vocabulary_list(

            

Reported by Pylint.

keras/layers/preprocessing/image_preprocessing.py
560 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Keras image preprocessing layers."""

import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes

import numpy as np
from keras import backend
from keras.engine import base_layer

            

Reported by Pylint.

Bad option value 'g-classes-have-attributes'
Error

Line: 18 Column: 1

              """Keras image preprocessing layers."""

import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes

import numpy as np
from keras import backend
from keras.engine import base_layer
from keras.engine import base_preprocessing_layer

            

Reported by Pylint.

Unable to import 'tensorflow.python.ops'
Error

Line: 26 Column: 1

              from keras.engine import base_preprocessing_layer
from keras.preprocessing import image as image_preprocessing
from keras.utils import control_flow_util
from tensorflow.python.ops import stateless_random_ops
from tensorflow.python.util.tf_export import keras_export

ResizeMethod = tf.image.ResizeMethod

_RESIZE_METHODS = {

            

Reported by Pylint.

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

Line: 27 Column: 1

              from keras.preprocessing import image as image_preprocessing
from keras.utils import control_flow_util
from tensorflow.python.ops import stateless_random_ops
from tensorflow.python.util.tf_export import keras_export

ResizeMethod = tf.image.ResizeMethod

_RESIZE_METHODS = {
    'bilinear': ResizeMethod.BILINEAR,

            

Reported by Pylint.

Bad option value 'g-long-lambda'
Error

Line: 262 Column: 1

                    input_height_t = input_shape[H_AXIS]
      input_width_t = input_shape[W_AXIS]
      ratio_cond = (input_height_t / input_width_t > (self.height / self.width))
      # pylint: disable=g-long-lambda
      resized_height = control_flow_util.smart_cond(
          ratio_cond,
          lambda: tf.cast(self.width * input_height_t / input_width_t,
                          input_height_t.dtype), lambda: self.height)
      resized_width = control_flow_util.smart_cond(

            

Reported by Pylint.

Bad option value 'g-long-lambda'
Error

Line: 271 Column: 1

                        ratio_cond, lambda: self.width,
          lambda: tf.cast(self.height * input_width_t / input_height_t,
                          input_width_t.dtype))
      # pylint: enable=g-long-lambda
      resized_inputs = tf.image.resize(
          images=inputs, size=tf.stack([resized_height, resized_width]))

      img_hd_diff = resized_height - self.height
      img_wd_diff = resized_width - self.width

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 92 Column: 3

                  super(Resizing, self).__init__(**kwargs)
    base_preprocessing_layer.keras_kpl_gauge.get_cell('Resizing').set(True)

  def call(self, inputs):
    if self.crop_to_aspect_ratio:
      outputs = image_preprocessing.smart_resize(
          inputs,
          size=[self.target_height, self.target_width],
          interpolation=self._interpolation_method)

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 149 Column: 3

                  super(CenterCrop, self).__init__(**kwargs)
    base_preprocessing_layer.keras_kpl_gauge.get_cell('CenterCrop').set(True)

  def call(self, inputs):
    inputs = tf.convert_to_tensor(inputs)
    inputs_shape = tf.shape(inputs)
    unbatched = inputs.shape.rank == 3
    img_hd = inputs_shape[H_AXIS]
    img_wd = inputs_shape[W_AXIS]

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 229 Column: 3

                  super(RandomCrop, self).__init__(**kwargs)
    base_preprocessing_layer.keras_kpl_gauge.get_cell('RandomCrop').set(True)

  def call(self, inputs, training=True):
    if training is None:
      training = backend.learning_phase()

    inputs = tf.convert_to_tensor(inputs)
    unbatched = inputs.shape.rank == 3

            

Reported by Pylint.

TODO(b/143885775): Share logic with Resize and CenterCrop.
Error

Line: 255 Column: 3

                          seed=self._rng.make_seeds()[:, 0]) % limit
        return tf.slice(inputs, offset, crop_size)

    # TODO(b/143885775): Share logic with Resize and CenterCrop.
    def resize_and_center_cropped_inputs():
      """Deterministically resize to shorter side and center crop."""
      input_shape = tf.shape(inputs)
      input_height_t = input_shape[H_AXIS]
      input_width_t = input_shape[W_AXIS]

            

Reported by Pylint.

keras/layers/gru_v2_test.py
556 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for GRU V2 layer."""

import tensorflow.compat.v2 as tf

import copy
import os
import shutil


            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 23 Column: 1

              import os
import shutil

from absl.testing import parameterized
import numpy as np
from tensorflow.core.protobuf import rewriter_config_pb2
import keras
from tensorflow.python.framework import test_util as tf_test_util
from keras import combinations

            

Reported by Pylint.

Unable to import 'tensorflow.core.protobuf'
Error

Line: 25 Column: 1

              
from absl.testing import parameterized
import numpy as np
from tensorflow.core.protobuf import rewriter_config_pb2
import keras
from tensorflow.python.framework import test_util as tf_test_util
from keras import combinations
from keras import keras_parameterized
from keras import testing_utils

            

Reported by Pylint.

Unable to import 'tensorflow.python.framework'
Error

Line: 27 Column: 1

              import numpy as np
from tensorflow.core.protobuf import rewriter_config_pb2
import keras
from tensorflow.python.framework import test_util as tf_test_util
from keras import combinations
from keras import keras_parameterized
from keras import testing_utils
from keras.layers import recurrent as rnn_v1
from keras.layers import recurrent_v2 as rnn

            

Reported by Pylint.

Access to a protected member _could_use_gpu_kernel of a client class
Error

Line: 66 Column: 22

                                  unroll=unroll,
                    use_bias=use_bias,
                    reset_after=reset_after)
    self.assertFalse(layer._could_use_gpu_kernel)

  @testing_utils.run_v2_only
  def test_use_on_default_activation_with_gpu_kernel(self):
    layer = rnn.GRU(1, activation=tf.tanh)
    self.assertTrue(layer._could_use_gpu_kernel)

            

Reported by Pylint.

Access to a protected member _could_use_gpu_kernel of a client class
Error

Line: 71 Column: 21

                @testing_utils.run_v2_only
  def test_use_on_default_activation_with_gpu_kernel(self):
    layer = rnn.GRU(1, activation=tf.tanh)
    self.assertTrue(layer._could_use_gpu_kernel)

    layer = rnn.GRU(1, recurrent_activation=tf.sigmoid)
    self.assertTrue(layer._could_use_gpu_kernel)

  def test_keras_model_with_gru(self):

            

Reported by Pylint.

Access to a protected member _could_use_gpu_kernel of a client class
Error

Line: 74 Column: 21

                  self.assertTrue(layer._could_use_gpu_kernel)

    layer = rnn.GRU(1, recurrent_activation=tf.sigmoid)
    self.assertTrue(layer._could_use_gpu_kernel)

  def test_keras_model_with_gru(self):
    input_shape = 10
    rnn_state_size = 8
    output_shape = 8

            

Reported by Pylint.

TODO (b/169895267): test with xla_gpu is disabled.
Error

Line: 621 Column: 3

                  # Make sure it doesn't crash with cudnn kernel.
    model.predict(inputs)

  # TODO (b/169895267): test with xla_gpu is disabled.
  def test_deepcopy(self):
    if not tf.executing_eagerly():
      self.skipTest('v2-only test')
    original_layer = rnn.GRU(5)
    copied_layer = copy.deepcopy(original_layer)

            

Reported by Pylint.

Access to a protected member _RUNTIME_GPU of a client class
Error

Line: 708 Column: 42

              
    _, runtime_value = model.predict(x_train)
    if tf.test.is_gpu_available():
      self.assertEqual(runtime_value[0], rnn._RUNTIME_GPU)
    else:
      self.assertEqual(runtime_value[0], rnn._RUNTIME_CPU)

  @testing_utils.run_v2_only
  def test_GRU_runtime(self):

            

Reported by Pylint.

Access to a protected member _RUNTIME_CPU of a client class
Error

Line: 710 Column: 42

                  if tf.test.is_gpu_available():
      self.assertEqual(runtime_value[0], rnn._RUNTIME_GPU)
    else:
      self.assertEqual(runtime_value[0], rnn._RUNTIME_CPU)

  @testing_utils.run_v2_only
  def test_GRU_runtime(self):
    layer = rnn.GRU(self.rnn_state_size, return_runtime=True)


            

Reported by Pylint.

keras/testing_utils.py
554 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 contextlib
import functools
import itertools

            

Reported by Pylint.

Unable to import 'tensorflow.python.framework'
Error

Line: 26 Column: 1

              import threading

import numpy as np
from tensorflow.python.framework import test_util
from keras import backend
from keras import layers
from keras import models
from keras.engine import base_layer_utils
from keras.optimizer_v2 import adadelta as adadelta_v2

            

Reported by Pylint.

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

Line: 434 Column: 1

                return models.Model(inputs, outputs)


class SmallSubclassMLP(models.Model):
  """A subclass model based small MLP."""

  def __init__(self,
               num_hidden,
               num_classes,

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 455 Column: 1

                  if self.use_bn:
      self.bn = layers.BatchNormalization(axis=-1)

  def call(self, inputs, **kwargs):
    x = self.layer_a(inputs)
    if self.use_dp:
      x = self.dp(x)
    if self.use_bn:
      x = self.bn(x)

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 455 Column: 3

                  if self.use_bn:
      self.bn = layers.BatchNormalization(axis=-1)

  def call(self, inputs, **kwargs):
    x = self.layer_a(inputs)
    if self.use_dp:
      x = self.dp(x)
    if self.use_bn:
      x = self.bn(x)

            

Reported by Pylint.

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

Line: 464 Column: 1

                  return self.layer_b(x)


class _SmallSubclassMLPCustomBuild(models.Model):
  """A subclass model small MLP that uses a custom build method."""

  def __init__(self, num_hidden, num_classes):
    super(_SmallSubclassMLPCustomBuild, self).__init__()
    self.layer_a = None

            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 479 Column: 1

                  activation = 'sigmoid' if self.num_classes == 1 else 'softmax'
    self.layer_b = layers.Dense(self.num_classes, activation=activation)

  def call(self, inputs, **kwargs):
    x = self.layer_a(inputs)
    return self.layer_b(x)


def get_small_subclass_mlp(num_hidden, num_classes):

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 479 Column: 3

                  activation = 'sigmoid' if self.num_classes == 1 else 'softmax'
    self.layer_b = layers.Dense(self.num_classes, activation=activation)

  def call(self, inputs, **kwargs):
    x = self.layer_a(inputs)
    return self.layer_b(x)


def get_small_subclass_mlp(num_hidden, num_classes):

            

Reported by Pylint.

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

Line: 506 Column: 1

                raise ValueError('Unknown model type {}'.format(model_type))


class _SubclassModel(models.Model):
  """A Keras subclass model."""

  def __init__(self, model_layers, *args, **kwargs):
    """Instantiate a model.


            

Reported by Pylint.

Unused argument 'kwargs'
Error

Line: 534 Column: 1

                def _layer_name_for_i(self, i):
    return 'layer{}'.format(i)

  def call(self, inputs, **kwargs):
    x = inputs
    for i in range(self.num_layers):
      layer = getattr(self, self._layer_name_for_i(i))
      x = layer(x)
    return x

            

Reported by Pylint.