The following issues were found

keras/utils/losses_utils_test.py
49 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for losses_utils."""

import tensorflow.compat.v2 as tf
from keras import combinations
from keras.utils import losses_utils


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

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 24 Column: 1

              
@combinations.generate(combinations.combine(mode=['graph', 'eager']))
class RemoveSqueezableTest(tf.test.TestCase):
  """Test remove_squeezable_dimensions"""

  def test_ragged_3d_same_shape(self):
    """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 26 Column: 1

              class RemoveSqueezableTest(tf.test.TestCase):
  """Test remove_squeezable_dimensions"""

  def test_ragged_3d_same_shape(self):
    """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 27 Column: 1

                """Test remove_squeezable_dimensions"""

  def test_ragged_3d_same_shape(self):
    """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 28 Column: 1

              
  def test_ragged_3d_same_shape(self):
    """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

  def test_ragged_3d_4d_squeezable(self):

            

Reported by Pylint.

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

Line: 28 Column: 5

              
  def test_ragged_3d_same_shape(self):
    """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

  def test_ragged_3d_4d_squeezable(self):

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 29 Column: 1

                def test_ragged_3d_same_shape(self):
    """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

  def test_ragged_3d_4d_squeezable(self):
    """ shapes:

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 30 Column: 1

                  """ shape (2, (sequence={1, 2}), 3)"""
    x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

  def test_ragged_3d_4d_squeezable(self):
    """ shapes:


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 31 Column: 1

                  x = tf.ragged.constant([[[1, 2, 3]], [[4, 5, 6], [7, 8, 9]]])
    rank = x.shape.ndims
    x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

  def test_ragged_3d_4d_squeezable(self):
    """ shapes:

        x: (2, (sequence={1, 2}), 3)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 33 Column: 1

                  x_p, _ = losses_utils.remove_squeezable_dimensions(x, x)
    self.assertEqual(x_p.shape.ndims, rank)

  def test_ragged_3d_4d_squeezable(self):
    """ shapes:

        x: (2, (sequence={1, 2}), 3)
        y: (2, (sequence={1, 2}), 3, 1)
    """

            

Reported by Pylint.

keras/utils/control_flow_util.py
47 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 20 Column: 1

              This file is copied from tensorflow/python/ops/control_flow_util.py.
"""

import tensorflow.compat.v2 as tf


def InXlaContext(graph):
  ctxt = graph._get_control_flow_context()  # pylint: disable=protected-access
  return GetContainingXLAContext(ctxt) is not None

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

              import tensorflow.compat.v2 as tf


def InXlaContext(graph):
  ctxt = graph._get_control_flow_context()  # pylint: disable=protected-access
  return GetContainingXLAContext(ctxt) is not None


def GraphOrParentsInXlaContext(graph):

            

Reported by Pylint.

Function name "InXlaContext" doesn't conform to snake_case naming style
Error

Line: 23 Column: 1

              import tensorflow.compat.v2 as tf


def InXlaContext(graph):
  ctxt = graph._get_control_flow_context()  # pylint: disable=protected-access
  return GetContainingXLAContext(ctxt) is not None


def GraphOrParentsInXlaContext(graph):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 24 Column: 1

              

def InXlaContext(graph):
  ctxt = graph._get_control_flow_context()  # pylint: disable=protected-access
  return GetContainingXLAContext(ctxt) is not None


def GraphOrParentsInXlaContext(graph):
  while True:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 25 Column: 1

              
def InXlaContext(graph):
  ctxt = graph._get_control_flow_context()  # pylint: disable=protected-access
  return GetContainingXLAContext(ctxt) is not None


def GraphOrParentsInXlaContext(graph):
  while True:
    if InXlaContext(graph): return True

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

                return GetContainingXLAContext(ctxt) is not None


def GraphOrParentsInXlaContext(graph):
  while True:
    if InXlaContext(graph): return True
    try:
      graph = graph.outer_graph
    except AttributeError:

            

Reported by Pylint.

Function name "GraphOrParentsInXlaContext" doesn't conform to snake_case naming style
Error

Line: 28 Column: 1

                return GetContainingXLAContext(ctxt) is not None


def GraphOrParentsInXlaContext(graph):
  while True:
    if InXlaContext(graph): return True
    try:
      graph = graph.outer_graph
    except AttributeError:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              

def GraphOrParentsInXlaContext(graph):
  while True:
    if InXlaContext(graph): return True
    try:
      graph = graph.outer_graph
    except AttributeError:
      return False

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 30 Column: 1

              
def GraphOrParentsInXlaContext(graph):
  while True:
    if InXlaContext(graph): return True
    try:
      graph = graph.outer_graph
    except AttributeError:
      return False


            

Reported by Pylint.

More than one statement on a single line
Error

Line: 30 Column: 29

              
def GraphOrParentsInXlaContext(graph):
  while True:
    if InXlaContext(graph): return True
    try:
      graph = graph.outer_graph
    except AttributeError:
      return False


            

Reported by Pylint.

keras/benchmarks/keras_examples_benchmarks/mnist_conv_benchmark_test.py
46 issues
Unable to import 'tensorflow'
Error

Line: 20 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow as tf

import numpy as np

from keras.benchmarks import benchmark_util


            

Reported by Pylint.

Unable to import 'keras.benchmarks'
Error

Line: 24 Column: 1

              
import numpy as np

from keras.benchmarks import benchmark_util


class ConvMnistBenchmark(tf.test.Benchmark):
  """Benchmarks for Convnet using `tf.test.Benchmark`."""


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

              

class ConvMnistBenchmark(tf.test.Benchmark):
  """Benchmarks for Convnet using `tf.test.Benchmark`."""

  def __init__(self):
    super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 30 Column: 1

              class ConvMnistBenchmark(tf.test.Benchmark):
  """Benchmarks for Convnet using `tf.test.Benchmark`."""

  def __init__(self):
    super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 31 Column: 1

                """Benchmarks for Convnet using `tf.test.Benchmark`."""

  def __init__(self):
    super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255
    self.x_train = np.expand_dims(self.x_train, -1)

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 31 Column: 5

                """Benchmarks for Convnet using `tf.test.Benchmark`."""

  def __init__(self):
    super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255
    self.x_train = np.expand_dims(self.x_train, -1)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 32 Column: 1

              
  def __init__(self):
    super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255
    self.x_train = np.expand_dims(self.x_train, -1)
    self.y_train = tf.keras.utils.to_categorical(self.y_train, self.num_classes)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 33 Column: 1

                def __init__(self):
    super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255
    self.x_train = np.expand_dims(self.x_train, -1)
    self.y_train = tf.keras.utils.to_categorical(self.y_train, self.num_classes)
    self.epochs = 15

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 34 Column: 1

                  super(ConvMnistBenchmark, self).__init__()
    self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255
    self.x_train = np.expand_dims(self.x_train, -1)
    self.y_train = tf.keras.utils.to_categorical(self.y_train, self.num_classes)
    self.epochs = 15


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 35 Column: 1

                  self.num_classes = 10
    self.input_shape = (28, 28, 1)
    (self.x_train, self.y_train), _ = tf.keras.datasets.mnist.load_data()
    self.x_train = self.x_train.astype('float32') / 255
    self.x_train = np.expand_dims(self.x_train, -1)
    self.y_train = tf.keras.utils.to_categorical(self.y_train, self.num_classes)
    self.epochs = 15

  def _build_model(self):

            

Reported by Pylint.

keras/distribute/distributed_training_utils.py
46 issues
Unable to import 'absl'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Utilities related to distributed training."""

from absl import flags
from keras import backend

import tensorflow.compat.v2 as tf

FLAGS = flags.FLAGS

            

Reported by Pylint.

Unable to import 'tensorflow.compat.v2'
Error

Line: 20 Column: 1

              from absl import flags
from keras import backend

import tensorflow.compat.v2 as tf

FLAGS = flags.FLAGS


# TODO(b/118776054): Currently we support global batch size for TPUStrategy and

            

Reported by Pylint.

TODO(b/118776054): Currently we support global batch size for TPUStrategy and
Error

Line: 25 Column: 3

              FLAGS = flags.FLAGS


# TODO(b/118776054): Currently we support global batch size for TPUStrategy and
# core MirroredStrategy only. Remove this check when contrib MirroredStrategy is
# no longer needed.
def global_batch_size_supported(distribution_strategy):
  return distribution_strategy.extended._global_batch_size  # pylint: disable=protected-access


            

Reported by Pylint.

TODO(b/132666209): Remove this function when we support assign_*
Error

Line: 46 Column: 3

                Returns:
    The result of calling `fn`.
  """
  # TODO(b/132666209): Remove this function when we support assign_*
  # for replica-local variables.
  strategy = None
  if 'strategy' in kwargs:
    strategy = kwargs.pop('strategy')
  else:

            

Reported by Pylint.

TODO(b/120571621): TPUStrategy does not implement replica-local variables.
Error

Line: 55 Column: 3

                  if tf.distribute.has_strategy():
      strategy = tf.distribute.get_strategy()

  # TODO(b/120571621): TPUStrategy does not implement replica-local variables.
  is_tpu = backend.is_tpu_strategy(strategy)
  if ((not is_tpu) and strategy and tf.distribute.in_cross_replica_context()):
    with strategy.scope():
      return strategy.extended.call_for_each_replica(fn, args, kwargs)
  return fn(*args, **kwargs)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

              # TODO(b/118776054): Currently we support global batch size for TPUStrategy and
# core MirroredStrategy only. Remove this check when contrib MirroredStrategy is
# no longer needed.
def global_batch_size_supported(distribution_strategy):
  return distribution_strategy.extended._global_batch_size  # pylint: disable=protected-access


def call_replica_local_fn(fn, *args, **kwargs):
  """Call a function that uses replica-local variables.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              # core MirroredStrategy only. Remove this check when contrib MirroredStrategy is
# no longer needed.
def global_batch_size_supported(distribution_strategy):
  return distribution_strategy.extended._global_batch_size  # pylint: disable=protected-access


def call_replica_local_fn(fn, *args, **kwargs):
  """Call a function that uses replica-local variables.


            

Reported by Pylint.

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

Line: 32 Column: 1

                return distribution_strategy.extended._global_batch_size  # pylint: disable=protected-access


def call_replica_local_fn(fn, *args, **kwargs):
  """Call a function that uses replica-local variables.

  This function correctly handles calling `fn` in a cross-replica
  context.


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 33 Column: 1

              

def call_replica_local_fn(fn, *args, **kwargs):
  """Call a function that uses replica-local variables.

  This function correctly handles calling `fn` in a cross-replica
  context.

  Args:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 48 Column: 1

                """
  # TODO(b/132666209): Remove this function when we support assign_*
  # for replica-local variables.
  strategy = None
  if 'strategy' in kwargs:
    strategy = kwargs.pop('strategy')
  else:
    if tf.distribute.has_strategy():
      strategy = tf.distribute.get_strategy()

            

Reported by Pylint.

keras/saving/saved_model/save.py
46 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Keras SavedModel serialization."""

import tensorflow.compat.v2 as tf

import os

from keras import backend as K
from keras.protobuf import saved_metadata_pb2

            

Reported by Pylint.

Unable to import 'keras'
Error

Line: 21 Column: 1

              
import os

from keras import backend as K
from keras.protobuf import saved_metadata_pb2
from keras.protobuf import versions_pb2
from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl

            

Reported by Pylint.

Unable to import 'keras.protobuf'
Error

Line: 22 Column: 1

              import os

from keras import backend as K
from keras.protobuf import saved_metadata_pb2
from keras.protobuf import versions_pb2
from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils

            

Reported by Pylint.

Unable to import 'keras.protobuf'
Error

Line: 23 Column: 1

              
from keras import backend as K
from keras.protobuf import saved_metadata_pb2
from keras.protobuf import versions_pb2
from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader

            

Reported by Pylint.

Unable to import 'keras.saving'
Error

Line: 24 Column: 1

              from keras import backend as K
from keras.protobuf import saved_metadata_pb2
from keras.protobuf import versions_pb2
from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader
from keras.utils.io_utils import ask_to_proceed_with_overwrite

            

Reported by Pylint.

Unable to import 'keras.saving.saved_model'
Error

Line: 25 Column: 1

              from keras.protobuf import saved_metadata_pb2
from keras.protobuf import versions_pb2
from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader
from keras.utils.io_utils import ask_to_proceed_with_overwrite
from tensorflow.python.saved_model import save as save_lib

            

Reported by Pylint.

Unable to import 'keras.saving.saved_model'
Error

Line: 26 Column: 1

              from keras.protobuf import versions_pb2
from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader
from keras.utils.io_utils import ask_to_proceed_with_overwrite
from tensorflow.python.saved_model import save as save_lib


            

Reported by Pylint.

Unable to import 'keras.saving.saved_model'
Error

Line: 27 Column: 1

              from keras.saving import saving_utils
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader
from keras.utils.io_utils import ask_to_proceed_with_overwrite
from tensorflow.python.saved_model import save as save_lib

# To avoid circular dependencies between keras/engine and keras/saving,

            

Reported by Pylint.

Unable to import 'keras.utils.generic_utils'
Error

Line: 28 Column: 1

              from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader
from keras.utils.io_utils import ask_to_proceed_with_overwrite
from tensorflow.python.saved_model import save as save_lib

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

            

Reported by Pylint.

Unable to import 'keras.utils.io_utils'
Error

Line: 29 Column: 1

              from keras.saving.saved_model import save_impl
from keras.saving.saved_model import utils
from keras.utils.generic_utils import LazyLoader
from keras.utils.io_utils import ask_to_proceed_with_overwrite
from tensorflow.python.saved_model import save as save_lib

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


            

Reported by Pylint.

keras/saving/pickle_utils.py
45 issues
Bad option value 'g-bad-import-order'
Error

Line: 16 Column: 1

              # limitations under the License.
# ==============================================================================
"""Saving utilities to support Python's Pickle protocol."""
# pylint: disable=g-bad-import-order
import tensorflow.compat.v2 as tf

import os
import tarfile
import io

            

Reported by Pylint.

Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Saving utilities to support Python's Pickle protocol."""
# pylint: disable=g-bad-import-order
import tensorflow.compat.v2 as tf

import os
import tarfile
import io
import uuid

            

Reported by Pylint.

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

Line: 19 Column: 1

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

import os
import tarfile
import io
import uuid
import numpy


            

Reported by Pylint.

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

Line: 20 Column: 1

              import tensorflow.compat.v2 as tf

import os
import tarfile
import io
import uuid
import numpy

from keras.saving import save as save_module

            

Reported by Pylint.

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

Line: 21 Column: 1

              
import os
import tarfile
import io
import uuid
import numpy

from keras.saving import save as save_module


            

Reported by Pylint.

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

Line: 22 Column: 1

              import os
import tarfile
import io
import uuid
import numpy

from keras.saving import save as save_module



            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              

def deserialize_model_from_bytecode(serialized_model):
  """Reconstruct a Model from the output of `serialize_model_as_bytecode`.

  Args:
      serialized_model: (np.array) return value from
        `serialize_model_as_bytecode`.


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 38 Column: 1

                Returns:
      keras.Model: Keras Model instance.
  """
  temp_dir = f"ram://{uuid.uuid4()}"
  b = io.BytesIO(serialized_model)
  with tarfile.open(fileobj=b, mode="r") as archive:
    for name in archive.getnames():
      dest_path = os.path.join(temp_dir, name)
      member = archive.getmember(name)

            

Reported by Pylint.

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

Line: 39 Column: 3

                    keras.Model: Keras Model instance.
  """
  temp_dir = f"ram://{uuid.uuid4()}"
  b = io.BytesIO(serialized_model)
  with tarfile.open(fileobj=b, mode="r") as archive:
    for name in archive.getnames():
      dest_path = os.path.join(temp_dir, name)
      member = archive.getmember(name)
      tf.io.gfile.makedirs(os.path.dirname(dest_path))

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 39 Column: 1

                    keras.Model: Keras Model instance.
  """
  temp_dir = f"ram://{uuid.uuid4()}"
  b = io.BytesIO(serialized_model)
  with tarfile.open(fileobj=b, mode="r") as archive:
    for name in archive.getnames():
      dest_path = os.path.join(temp_dir, name)
      member = archive.getmember(name)
      tf.io.gfile.makedirs(os.path.dirname(dest_path))

            

Reported by Pylint.

keras/engine/keras_tensor_test.py
45 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""InputSpec tests."""

import tensorflow.compat.v2 as tf
from keras import layers
from keras.engine import keras_tensor


class KerasTensorTest(tf.test.TestCase):

            

Reported by Pylint.

Missing class docstring
Error

Line: 22 Column: 1

              from keras.engine import keras_tensor


class KerasTensorTest(tf.test.TestCase):

  def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 22 Column: 1

              from keras.engine import keras_tensor


class KerasTensorTest(tf.test.TestCase):

  def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 24 Column: 1

              
class KerasTensorTest(tf.test.TestCase):

  def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 3

              
class KerasTensorTest(tf.test.TestCase):

  def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"

            

Reported by Pylint.

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

Line: 25 Column: 5

              class KerasTensorTest(tf.test.TestCase):

  def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"
    self.assertEqual(expected_str, str(kt))

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 25 Column: 1

              class KerasTensorTest(tf.test.TestCase):

  def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"
    self.assertEqual(expected_str, str(kt))

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 27 Column: 1

                def test_repr_and_string(self):
    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"
    self.assertEqual(expected_str, str(kt))
    self.assertEqual(expected_repr, repr(kt))


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 29 Column: 1

                      type_spec=tf.TensorSpec(shape=(1, 2, 3), dtype=tf.float32))
    expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"
    self.assertEqual(expected_str, str(kt))
    self.assertEqual(expected_repr, repr(kt))

    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(2,), dtype=tf.int32),

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 30 Column: 1

                  expected_str = ("KerasTensor(type_spec=TensorSpec(shape=(1, 2, 3), "
                    "dtype=tf.float32, name=None))")
    expected_repr = "<KerasTensor: shape=(1, 2, 3) dtype=float32>"
    self.assertEqual(expected_str, str(kt))
    self.assertEqual(expected_repr, repr(kt))

    kt = keras_tensor.KerasTensor(
        type_spec=tf.TensorSpec(shape=(2,), dtype=tf.int32),
        inferred_value=[2, 3])

            

Reported by Pylint.

keras/feature_column/sequence_feature_column.py
45 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 24 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow.compat.v2 as tf
from keras import backend
from keras.feature_column import base_feature_layer as kfc
from tensorflow.python.util.tf_export import keras_export

# pylint: disable=protected-access

            

Reported by Pylint.

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

Line: 27 Column: 1

              import tensorflow.compat.v2 as tf
from keras import backend
from keras.feature_column import base_feature_layer as kfc
from tensorflow.python.util.tf_export import keras_export

# pylint: disable=protected-access


@keras_export('keras.experimental.SequenceFeatures')

            

Reported by Pylint.

Method '_output_shape' is abstract in class '_BaseFeaturesLayer' but is not overridden
Error

Line: 33 Column: 1

              

@keras_export('keras.experimental.SequenceFeatures')
class SequenceFeatures(kfc._BaseFeaturesLayer):
  """A layer for sequence input.

    All `feature_columns` must be sequence dense columns with the same
    `sequence_length`. The output of this method can be fed into sequence
    networks, such as RNN.

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 116 Column: 3

                def _target_shape(self, input_shape, total_elements):
    return (input_shape[0], input_shape[1], total_elements)

  def call(self, features, training=None):
    """Returns sequence input corresponding to the `feature_columns`.

    Args:
      features: A dict mapping keys to tensors.
      training: Python boolean or None, indicating whether to the layer is being

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 34 Column: 1

              
@keras_export('keras.experimental.SequenceFeatures')
class SequenceFeatures(kfc._BaseFeaturesLayer):
  """A layer for sequence input.

    All `feature_columns` must be sequence dense columns with the same
    `sequence_length`. The output of this method can be fed into sequence
    networks, such as RNN.


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 81 Column: 1

                  ```
  """

  def __init__(
      self,
      feature_columns,
      trainable=True,
      name=None,
      **kwargs):

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 87 Column: 1

                    trainable=True,
      name=None,
      **kwargs):
    """"Constructs a SequenceFeatures layer.

    Args:
      feature_columns: An iterable of dense sequence columns. Valid columns are
        - `embedding_column` that wraps a `sequence_categorical_column_with_*`
        - `sequence_numeric_column`.

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 102 Column: 1

                    ValueError: If any of the `feature_columns` is not a
        `SequenceDenseColumn`.
    """
    super(SequenceFeatures, self).__init__(
        feature_columns=feature_columns,
        trainable=trainable,
        name=name,
        expected_column_type=tf.__internal__.feature_column.SequenceDenseColumn,
        **kwargs)

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 102 Column: 5

                    ValueError: If any of the `feature_columns` is not a
        `SequenceDenseColumn`.
    """
    super(SequenceFeatures, self).__init__(
        feature_columns=feature_columns,
        trainable=trainable,
        name=name,
        expected_column_type=tf.__internal__.feature_column.SequenceDenseColumn,
        **kwargs)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 109 Column: 1

                      expected_column_type=tf.__internal__.feature_column.SequenceDenseColumn,
        **kwargs)

  @property
  def _is_feature_layer(self):
    return True

  def _target_shape(self, input_shape, total_elements):
    return (input_shape[0], input_shape[1], total_elements)

            

Reported by Pylint.

keras/mixed_precision/mixed_precision_graph_rewrite_test.py
44 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests Keras integration with enable_mixed_precision_graph_rewrite()."""

import tensorflow.compat.v2 as tf

import os
from keras import combinations
from keras import keras_parameterized
from keras import testing_utils

            

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
from keras import combinations
from keras import keras_parameterized
from keras import testing_utils
from keras.mixed_precision import loss_scale_optimizer as loss_scale_optimizer_v2
from keras.mixed_precision import policy

            

Reported by Pylint.

Missing class docstring
Error

Line: 28 Column: 1

              from keras.optimizer_v2 import gradient_descent as gradient_descent_v2


class MixedPrecisionTest(keras_parameterized.TestCase):

  IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 30 Column: 1

              
class MixedPrecisionTest(keras_parameterized.TestCase):

  IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.

            

Reported by Pylint.

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

Line: 32 Column: 3

              
  IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.
    self._original_ignore_perf_value = os.getenv(self.IGNORE_PERF_VAR)
    os.environ[self.IGNORE_PERF_VAR] = '1'

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 32 Column: 3

              
  IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.
    self._original_ignore_perf_value = os.getenv(self.IGNORE_PERF_VAR)
    os.environ[self.IGNORE_PERF_VAR] = '1'

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

              
  IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.
    self._original_ignore_perf_value = os.getenv(self.IGNORE_PERF_VAR)
    os.environ[self.IGNORE_PERF_VAR] = '1'

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 33 Column: 1

                IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.
    self._original_ignore_perf_value = os.getenv(self.IGNORE_PERF_VAR)
    os.environ[self.IGNORE_PERF_VAR] = '1'


            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 33 Column: 5

                IGNORE_PERF_VAR = 'TF_AUTO_MIXED_PRECISION_GRAPH_REWRITE_IGNORE_PERFORMANCE'

  def setUp(self):
    super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.
    self._original_ignore_perf_value = os.getenv(self.IGNORE_PERF_VAR)
    os.environ[self.IGNORE_PERF_VAR] = '1'


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 36 Column: 1

                  super(MixedPrecisionTest, self).setUp()
    # Enable the tests to be run on pre-Volta GPUs by telling the grappler pass
    # to ignore performance and always transform the graph.
    self._original_ignore_perf_value = os.getenv(self.IGNORE_PERF_VAR)
    os.environ[self.IGNORE_PERF_VAR] = '1'

  def tearDown(self):
    # Set the IGNORE_PERF_VAR variable back to it's original value.
    if self._original_ignore_perf_value is not None:

            

Reported by Pylint.

keras/layers/subclassed_layers_test.py
44 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for Keras subclassed layers utilizing desired user syntax."""

import tensorflow.compat.v2 as tf

import keras
from keras import keras_parameterized
from keras import testing_utils
from keras.utils import tf_utils

            

Reported by Pylint.

Attribute 'b' defined outside __init__
Error

Line: 34 Column: 9

                  class BuildConstantLayer(keras.layers.Layer):

      def build(self, input_shape):
        self.b = tf.convert_to_tensor(2.0)

      def call(self, inputs):
        return self.b * inputs

    layer = BuildConstantLayer()

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 36 Column: 7

                    def build(self, input_shape):
        self.b = tf.convert_to_tensor(2.0)

      def call(self, inputs):
        return self.b * inputs

    layer = BuildConstantLayer()
    model = testing_utils.get_model_from_layers(
        [layer, keras.layers.Dense(1)], input_shape=(1,))

            

Reported by Pylint.

Attribute 'variable' defined outside __init__
Error

Line: 57 Column: 9

                    def build(self, input_shape):
        a = tf.convert_to_tensor(1.0)
        b = 2.0 * a
        self.variable = tf.Variable(b)
        self.constant = tf.convert_to_tensor(self.variable)

      def call(self, inputs):
        return self.variable * self.constant * inputs


            

Reported by Pylint.

Attribute 'constant' defined outside __init__
Error

Line: 58 Column: 9

                      a = tf.convert_to_tensor(1.0)
        b = 2.0 * a
        self.variable = tf.Variable(b)
        self.constant = tf.convert_to_tensor(self.variable)

      def call(self, inputs):
        return self.variable * self.constant * inputs

    layer = BuildDerivedConstantLayer()

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 60 Column: 7

                      self.variable = tf.Variable(b)
        self.constant = tf.convert_to_tensor(self.variable)

      def call(self, inputs):
        return self.variable * self.constant * inputs

    layer = BuildDerivedConstantLayer()
    model = testing_utils.get_model_from_layers(
        [layer, keras.layers.Dense(1)], input_shape=(1,))

            

Reported by Pylint.

Missing class docstring
Error

Line: 27 Column: 1

              
@keras_parameterized.run_all_keras_modes
@keras_parameterized.run_with_all_model_types
class SubclassedLayersTest(keras_parameterized.TestCase):

  def test_simple_build_with_constant(self):

    class BuildConstantLayer(keras.layers.Layer):


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              @keras_parameterized.run_with_all_model_types
class SubclassedLayersTest(keras_parameterized.TestCase):

  def test_simple_build_with_constant(self):

    class BuildConstantLayer(keras.layers.Layer):

      def build(self, input_shape):
        self.b = tf.convert_to_tensor(2.0)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 29 Column: 3

              @keras_parameterized.run_with_all_model_types
class SubclassedLayersTest(keras_parameterized.TestCase):

  def test_simple_build_with_constant(self):

    class BuildConstantLayer(keras.layers.Layer):

      def build(self, input_shape):
        self.b = tf.convert_to_tensor(2.0)

            

Reported by Pylint.

Missing class docstring
Error

Line: 31 Column: 5

              
  def test_simple_build_with_constant(self):

    class BuildConstantLayer(keras.layers.Layer):

      def build(self, input_shape):
        self.b = tf.convert_to_tensor(2.0)

      def call(self, inputs):

            

Reported by Pylint.