The following issues were found

keras/benchmarks/saved_model_benchmarks/saved_model_benchmark_util.py
26 issues
Unable to import 'tensorflow'
Error

Line: 21 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow as tf

import tempfile
import time



            

Reported by Pylint.

standard import "import tempfile" should be placed before "import tensorflow as tf"
Error

Line: 23 Column: 1

              
import tensorflow as tf

import tempfile
import time


def save_and_load_benchmark(app):
  """Util for saved model benchmarks."""

            

Reported by Pylint.

standard import "import time" should be placed before "import tensorflow as tf"
Error

Line: 24 Column: 1

              import tensorflow as tf

import tempfile
import time


def save_and_load_benchmark(app):
  """Util for saved model benchmarks."""
  trials = 3

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

              

def save_and_load_benchmark(app):
  """Util for saved model benchmarks."""
  trials = 3

  model = app(weights=None)
  model_name = app.__name__


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              
def save_and_load_benchmark(app):
  """Util for saved model benchmarks."""
  trials = 3

  model = app(weights=None)
  model_name = app.__name__

  tmp_dir = tf.compat.v1.test.get_temp_dir()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

                """Util for saved model benchmarks."""
  trials = 3

  model = app(weights=None)
  model_name = app.__name__

  tmp_dir = tf.compat.v1.test.get_temp_dir()
  tf.io.gfile.makedirs(tmp_dir)
  save_dir = tempfile.mkdtemp(dir=tmp_dir)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 32 Column: 1

                trials = 3

  model = app(weights=None)
  model_name = app.__name__

  tmp_dir = tf.compat.v1.test.get_temp_dir()
  tf.io.gfile.makedirs(tmp_dir)
  save_dir = tempfile.mkdtemp(dir=tmp_dir)


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 34 Column: 1

                model = app(weights=None)
  model_name = app.__name__

  tmp_dir = tf.compat.v1.test.get_temp_dir()
  tf.io.gfile.makedirs(tmp_dir)
  save_dir = tempfile.mkdtemp(dir=tmp_dir)

  total_save_time = 0
  total_load_time = 0

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 35 Column: 1

                model_name = app.__name__

  tmp_dir = tf.compat.v1.test.get_temp_dir()
  tf.io.gfile.makedirs(tmp_dir)
  save_dir = tempfile.mkdtemp(dir=tmp_dir)

  total_save_time = 0
  total_load_time = 0


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 36 Column: 1

              
  tmp_dir = tf.compat.v1.test.get_temp_dir()
  tf.io.gfile.makedirs(tmp_dir)
  save_dir = tempfile.mkdtemp(dir=tmp_dir)

  total_save_time = 0
  total_load_time = 0

  # Run one untimed iteration of saving/loading.

            

Reported by Pylint.

keras/layers/preprocessing/string_lookup.py
26 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Keras string lookup preprocessing layer."""

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

import numpy as np
from keras.engine import base_preprocessing_layer
from keras.layers.preprocessing import index_lookup

            

Reported by Pylint.

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

Line: 18 Column: 1

              """Keras string lookup preprocessing layer."""

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

import numpy as np
from keras.engine import base_preprocessing_layer
from keras.layers.preprocessing import index_lookup
from tensorflow.python.util.tf_export import keras_export

            

Reported by Pylint.

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

Line: 23 Column: 1

              import numpy as np
from keras.engine import base_preprocessing_layer
from keras.layers.preprocessing import index_lookup
from tensorflow.python.util.tf_export import keras_export


@keras_export(
    "keras.layers.StringLookup",
    "keras.layers.experimental.preprocessing.StringLookup",

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

                  "keras.layers.experimental.preprocessing.StringLookup",
    v1=[])
class StringLookup(index_lookup.IndexLookup):
  """Maps strings from a vocabulary to integer indices.

  This layer translates a set of arbitrary strings into an integer output via a
  table-based vocabulary lookup.

  The vocabulary for the layer must be either supplied on construction or

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 291 Column: 1

                vocabulary either directly or via `adapt()` before calling `get_vocabulary()`.
  """

  def __init__(self,
               max_tokens=None,
               num_oov_indices=1,
               mask_token=None,
               oov_token="[UNK]",
               vocabulary=None,

            

Reported by Pylint.

Possible hardcoded password: '[UNK]'
Security

Line: 291
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b107_hardcoded_password_default.html

                vocabulary either directly or via `adapt()` before calling `get_vocabulary()`.
  """

  def __init__(self,
               max_tokens=None,
               num_oov_indices=1,
               mask_token=None,
               oov_token="[UNK]",
               vocabulary=None,

            

Reported by Bandit.

Too many arguments (11/5)
Error

Line: 291 Column: 3

                vocabulary either directly or via `adapt()` before calling `get_vocabulary()`.
  """

  def __init__(self,
               max_tokens=None,
               num_oov_indices=1,
               mask_token=None,
               oov_token="[UNK]",
               vocabulary=None,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 303 Column: 1

                             sparse=False,
               pad_to_max_tokens=False,
               **kwargs):
    allowed_dtypes = [tf.string]

    if "dtype" in kwargs and kwargs["dtype"] not in allowed_dtypes:
      raise ValueError(
          f"The value of the `dtype` for `StringLookup` may "
          f"only be one of {allowed_dtypes}, but received {kwargs['dtype']}.")

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 305 Column: 1

                             **kwargs):
    allowed_dtypes = [tf.string]

    if "dtype" in kwargs and kwargs["dtype"] not in allowed_dtypes:
      raise ValueError(
          f"The value of the `dtype` for `StringLookup` may "
          f"only be one of {allowed_dtypes}, but received {kwargs['dtype']}.")

    if "dtype" not in kwargs:

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 306 Column: 1

                  allowed_dtypes = [tf.string]

    if "dtype" in kwargs and kwargs["dtype"] not in allowed_dtypes:
      raise ValueError(
          f"The value of the `dtype` for `StringLookup` may "
          f"only be one of {allowed_dtypes}, but received {kwargs['dtype']}.")

    if "dtype" not in kwargs:
      kwargs["dtype"] = tf.string

            

Reported by Pylint.

keras/backend_config.py
26 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Keras backend config API."""

import tensorflow.compat.v2 as tf
from tensorflow.python.util.tf_export import keras_export

# The type of float to use throughout a session.
_FLOATX = 'float32'


            

Reported by Pylint.

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

Line: 18 Column: 1

              """Keras backend config API."""

import tensorflow.compat.v2 as tf
from tensorflow.python.util.tf_export import keras_export

# The type of float to use throughout a session.
_FLOATX = 'float32'

# Epsilon fuzz factor used throughout the codebase.

            

Reported by Pylint.

Using the global statement
Error

Line: 60 Column: 3

                1e-05
   >>> tf.keras.backend.set_epsilon(1e-7)
  """
  global _EPSILON
  _EPSILON = value


@keras_export('keras.backend.floatx')
def floatx():

            

Reported by Pylint.

Using the global statement
Error

Line: 105 Column: 3

                Raises:
      ValueError: In case of invalid value.
  """
  global _FLOATX
  accepted_dtypes = {'float16', 'float32', 'float64'}
  if value not in accepted_dtypes:
    raise ValueError(
        f'Unknown `floatx` value: {value}. Expected one of {accepted_dtypes}')
  _FLOATX = str(value)

            

Reported by Pylint.

Using the global statement
Error

Line: 146 Column: 3

                Raises:
      ValueError: In case of invalid `data_format` value.
  """
  global _IMAGE_DATA_FORMAT
  accepted_formats = {'channels_last', 'channels_first'}
  if data_format not in accepted_formats:
    raise ValueError(
        f'Unknown `data_format`: {data_format}. '
        f'Expected one of {accepted_formats}')

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 33 Column: 1

              @keras_export('keras.backend.epsilon')
@tf.__internal__.dispatch.add_dispatch_support
def epsilon():
  """Returns the value of the fuzz factor used in numeric expressions.

  Returns:
      A float.

  Example:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 42 Column: 1

                >>> tf.keras.backend.epsilon()
  1e-07
  """
  return _EPSILON


@keras_export('keras.backend.set_epsilon')
def set_epsilon(value):
  """Sets the value of the fuzz factor used in numeric expressions.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 47 Column: 1

              
@keras_export('keras.backend.set_epsilon')
def set_epsilon(value):
  """Sets the value of the fuzz factor used in numeric expressions.

  Args:
      value: float. New value of epsilon.

  Example:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 60 Column: 1

                1e-05
   >>> tf.keras.backend.set_epsilon(1e-7)
  """
  global _EPSILON
  _EPSILON = value


@keras_export('keras.backend.floatx')
def floatx():

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 61 Column: 1

                 >>> tf.keras.backend.set_epsilon(1e-7)
  """
  global _EPSILON
  _EPSILON = value


@keras_export('keras.backend.floatx')
def floatx():
  """Returns the default float type, as a string.

            

Reported by Pylint.

keras/datasets/boston_housing.py
25 issues
Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 20 Column: 1

              import numpy as np

from keras.utils.data_utils import get_file
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.datasets.boston_housing.load_data')
def load_data(path='boston_housing.npz', test_split=0.2, seed=113):
  """Loads the Boston Housing dataset.

            

Reported by Pylint.

Module 'numpy.random' has no 'RandomState' member
Error

Line: 66 Column: 9

                  x = f['x']
    y = f['y']

  rng = np.random.RandomState(seed)
  indices = np.arange(len(x))
  rng.shuffle(indices)
  x = x[indices]
  y = y[indices]


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 25 Column: 1

              
@keras_export('keras.datasets.boston_housing.load_data')
def load_data(path='boston_housing.npz', test_split=0.2, seed=113):
  """Loads the Boston Housing dataset.

  This is a dataset taken from the StatLib library which is maintained at
  Carnegie Mellon University.

  Samples contain 13 attributes of houses at different locations around the

            

Reported by Pylint.

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
Security

Line: 55
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b101_assert_used.html

                  target scalars. The targets are float scalars typically between 10 and
    50 that represent the home prices in k$.
  """
  assert 0 <= test_split < 1
  origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
  path = get_file(
      path,
      origin=origin_folder + 'boston_housing.npz',
      file_hash=

            

Reported by Bandit.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 55 Column: 1

                  target scalars. The targets are float scalars typically between 10 and
    50 that represent the home prices in k$.
  """
  assert 0 <= test_split < 1
  origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
  path = get_file(
      path,
      origin=origin_folder + 'boston_housing.npz',
      file_hash=

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 56 Column: 1

                  50 that represent the home prices in k$.
  """
  assert 0 <= test_split < 1
  origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
  path = get_file(
      path,
      origin=origin_folder + 'boston_housing.npz',
      file_hash=
      'f553886a1f8d56431e820c5b82552d9d95cfcb96d1e678153f8839538947dff5')

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 57 Column: 1

                """
  assert 0 <= test_split < 1
  origin_folder = 'https://storage.googleapis.com/tensorflow/tf-keras-datasets/'
  path = get_file(
      path,
      origin=origin_folder + 'boston_housing.npz',
      file_hash=
      'f553886a1f8d56431e820c5b82552d9d95cfcb96d1e678153f8839538947dff5')
  with np.load(path, allow_pickle=True) as f:  # pylint: disable=unexpected-keyword-arg

            

Reported by Pylint.

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

Line: 62 Column: 44

                    origin=origin_folder + 'boston_housing.npz',
      file_hash=
      'f553886a1f8d56431e820c5b82552d9d95cfcb96d1e678153f8839538947dff5')
  with np.load(path, allow_pickle=True) as f:  # pylint: disable=unexpected-keyword-arg
    x = f['x']
    y = f['y']

  rng = np.random.RandomState(seed)
  indices = np.arange(len(x))

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 62 Column: 1

                    origin=origin_folder + 'boston_housing.npz',
      file_hash=
      'f553886a1f8d56431e820c5b82552d9d95cfcb96d1e678153f8839538947dff5')
  with np.load(path, allow_pickle=True) as f:  # pylint: disable=unexpected-keyword-arg
    x = f['x']
    y = f['y']

  rng = np.random.RandomState(seed)
  indices = np.arange(len(x))

            

Reported by Pylint.

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

Line: 63 Column: 5

                    file_hash=
      'f553886a1f8d56431e820c5b82552d9d95cfcb96d1e678153f8839538947dff5')
  with np.load(path, allow_pickle=True) as f:  # pylint: disable=unexpected-keyword-arg
    x = f['x']
    y = f['y']

  rng = np.random.RandomState(seed)
  indices = np.arange(len(x))
  rng.shuffle(indices)

            

Reported by Pylint.

keras/distribute/keras_save_load_test.py
25 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for saving and loading using keras save/load APIs with DS."""

import tensorflow.compat.v2 as tf
from keras import testing_utils
from keras.distribute import saved_model_test_base as test_base
from keras.saving import save



            

Reported by Pylint.

Missing class docstring
Error

Line: 25 Column: 1

              
@testing_utils.run_all_without_tensor_float_32(
    'Uses Dense layers, which call matmul')
class KerasSaveLoadTest(test_base.TestSavedModelBase):

  def setUp(self):
    self._root_dir = 'keras_save_load'
    super(KerasSaveLoadTest, self).setUp()


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 27 Column: 1

                  'Uses Dense layers, which call matmul')
class KerasSaveLoadTest(test_base.TestSavedModelBase):

  def setUp(self):
    self._root_dir = 'keras_save_load'
    super(KerasSaveLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 28 Column: 1

              class KerasSaveLoadTest(test_base.TestSavedModelBase):

  def setUp(self):
    self._root_dir = 'keras_save_load'
    super(KerasSaveLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')


            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 29 Column: 5

              
  def setUp(self):
    self._root_dir = 'keras_save_load'
    super(KerasSaveLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')

  def _load_and_run_model(self,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 29 Column: 1

              
  def setUp(self):
    self._root_dir = 'keras_save_load'
    super(KerasSaveLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')

  def _load_and_run_model(self,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

                  self._root_dir = 'keras_save_load'
    super(KerasSaveLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')

  def _load_and_run_model(self,
                          distribution,
                          saved_dir,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 32 Column: 1

                  super(KerasSaveLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')

  def _load_and_run_model(self,
                          distribution,
                          saved_dir,
                          predict_dataset,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 34 Column: 1

                def _save_model(self, model, saved_dir):
    model.save(saved_dir, save_format='tf')

  def _load_and_run_model(self,
                          distribution,
                          saved_dir,
                          predict_dataset,
                          output_name='output_1'):
    restored_keras_model = save.load_model(saved_dir)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 39 Column: 1

                                        saved_dir,
                          predict_dataset,
                          output_name='output_1'):
    restored_keras_model = save.load_model(saved_dir)
    return restored_keras_model.predict(
        predict_dataset, steps=test_base.PREDICT_STEPS)

  @tf.__internal__.distribute.combinations.generate(test_base.simple_models_with_strategies())
  def test_save_no_strategy_restore_strategy(self, model_and_input,

            

Reported by Pylint.

keras/integration_test/distributed_training_test.py
25 issues
Unable to import 'tensorflow'
Error

Line: 20 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow as tf
ds_combinations = tf.__internal__.distribute.combinations

# Note: Strategy combinations are not (yet) public APIs, so they are subject
# to API changes and backward-compatibility is not guaranteed.
# TODO(b/188763034): Proceed to export the strategy combinations as public APIs.

            

Reported by Pylint.

TODO(b/188763034): Proceed to export the strategy combinations as public APIs.
Error

Line: 25 Column: 3

              
# Note: Strategy combinations are not (yet) public APIs, so they are subject
# to API changes and backward-compatibility is not guaranteed.
# TODO(b/188763034): Proceed to export the strategy combinations as public APIs.
STRATEGIES = [
    ds_combinations.default_strategy,
    ds_combinations.mirrored_strategy_with_cpu_1_and_2,
    ds_combinations.mirrored_strategy_with_two_gpus,
    ds_combinations.tpu_strategy,

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 43 Column: 1

              @ds_combinations.generate(
    tf.__internal__.test.combinations.combine(
        strategy=STRATEGIES, mode="eager"))
class DistributedTrainingTest(tf.test.TestCase):
  """Test to demonstrate basic Keras training with a variety of strategies."""

  def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 44 Column: 1

                  tf.__internal__.test.combinations.combine(
        strategy=STRATEGIES, mode="eager"))
class DistributedTrainingTest(tf.test.TestCase):
  """Test to demonstrate basic Keras training with a variety of strategies."""

  def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):

            

Reported by Pylint.

Method could be a function
Error

Line: 46 Column: 3

              class DistributedTrainingTest(tf.test.TestCase):
  """Test to demonstrate basic Keras training with a variety of strategies."""

  def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):
      batch_size = input_context.get_per_replica_batch_size(
          global_batch_size=64)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 46 Column: 3

              class DistributedTrainingTest(tf.test.TestCase):
  """Test to demonstrate basic Keras training with a variety of strategies."""

  def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):
      batch_size = input_context.get_per_replica_batch_size(
          global_batch_size=64)

            

Reported by Pylint.

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

Line: 46 Column: 3

              class DistributedTrainingTest(tf.test.TestCase):
  """Test to demonstrate basic Keras training with a variety of strategies."""

  def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):
      batch_size = input_context.get_per_replica_batch_size(
          global_batch_size=64)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 46 Column: 1

              class DistributedTrainingTest(tf.test.TestCase):
  """Test to demonstrate basic Keras training with a variety of strategies."""

  def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):
      batch_size = input_context.get_per_replica_batch_size(
          global_batch_size=64)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 49 Column: 1

                def testKerasTrainingAPI(self, strategy):

    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):
      batch_size = input_context.get_per_replica_batch_size(
          global_batch_size=64)
      x = tf.random.uniform((10, 10))
      y = tf.random.uniform((10,))
      dataset = tf.data.Dataset.from_tensor_slices((x, y)).shuffle(10).repeat()

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 50 Column: 1

              
    # A `dataset_fn` is required for `Model.fit` to work across all strategies.
    def dataset_fn(input_context):
      batch_size = input_context.get_per_replica_batch_size(
          global_batch_size=64)
      x = tf.random.uniform((10, 10))
      y = tf.random.uniform((10,))
      dataset = tf.data.Dataset.from_tensor_slices((x, y)).shuffle(10).repeat()
      dataset = dataset.shard(

            

Reported by Pylint.

keras/legacy_tf_layers/normalization.py
24 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 normalization 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.compat.v2'
Error

Line: 21 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow.compat.v2 as tf

import warnings

from keras.layers.normalization import batch_normalization_v1
from keras.legacy_tf_layers import base

            

Reported by Pylint.

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

Line: 27 Column: 1

              
from keras.layers.normalization import batch_normalization_v1
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.BatchNormalization'])
@tf_export(v1=['layers.BatchNormalization'])

            

Reported by Pylint.

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

Line: 28 Column: 1

              from keras.layers.normalization import batch_normalization_v1
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.BatchNormalization'])
@tf_export(v1=['layers.BatchNormalization'])
class BatchNormalization(batch_normalization_v1.BatchNormalization, base.Layer):

            

Reported by Pylint.

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

Line: 23 Column: 1

              
import tensorflow.compat.v2 as tf

import warnings

from keras.layers.normalization import batch_normalization_v1
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

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 34 Column: 1

              @keras_export(v1=['keras.__internal__.legacy.layers.BatchNormalization'])
@tf_export(v1=['layers.BatchNormalization'])
class BatchNormalization(batch_normalization_v1.BatchNormalization, base.Layer):
  """Batch Normalization layer from (Ioffe et al., 2015).

  Keras APIs handle BatchNormalization updates to the moving_mean and
  moving_variance as part of their `fit()` and `evaluate()` loops. However, if a
  custom training loop is used with an instance of `Model`, these updates need
  to be explicitly included.  Here's a simple example of how it can be done:

            

Reported by Pylint.

Line too long (134/100)
Error

Line: 122 Column: 1

                  Batch Renormalization - Towards Reducing Minibatch Dependence in
      Batch-Normalized Models:
      [Ioffe,
        2017](http://papers.nips.cc/paper/6790-batch-renormalization-towards-reducing-minibatch-dependence-in-batch-normalized-models)
      ([pdf](http://papers.nips.cc/paper/6790-batch-renormalization-towards-reducing-minibatch-dependence-in-batch-normalized-models.pdf))


  @compatibility(TF2)
  This API is not compatible with eager execution or `tf.function`.

            

Reported by Pylint.

Line too long (138/100)
Error

Line: 123 Column: 1

                    Batch-Normalized Models:
      [Ioffe,
        2017](http://papers.nips.cc/paper/6790-batch-renormalization-towards-reducing-minibatch-dependence-in-batch-normalized-models)
      ([pdf](http://papers.nips.cc/paper/6790-batch-renormalization-towards-reducing-minibatch-dependence-in-batch-normalized-models.pdf))


  @compatibility(TF2)
  This API is not compatible with eager execution or `tf.function`.


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 179 Column: 1

                @end_compatibility
  """

  def __init__(self,
               axis=-1,
               momentum=0.99,
               epsilon=1e-3,
               center=True,
               scale=True,

            

Reported by Pylint.

Too many arguments (22/5)
Error

Line: 179 Column: 3

                @end_compatibility
  """

  def __init__(self,
               axis=-1,
               momentum=0.99,
               epsilon=1e-3,
               center=True,
               scale=True,

            

Reported by Pylint.

keras/estimator/__init__.py
24 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Keras estimator API."""

import tensorflow.compat.v2 as tf

from tensorflow.python.util.tf_export import keras_export

# Keras has undeclared dependency on tensorflow/estimator:estimator_py.
# As long as you depend //third_party/py/tensorflow:tensorflow target

            

Reported by Pylint.

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

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from tensorflow.python.util.tf_export import keras_export

# Keras has undeclared dependency on tensorflow/estimator:estimator_py.
# As long as you depend //third_party/py/tensorflow:tensorflow target
# everything will work as normal.


            

Reported by Pylint.

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

Line: 163 Column: 1

                """

  try:
    from tensorflow_estimator.python.estimator import keras_lib  # pylint: disable=g-import-not-at-top
  except ImportError:
    raise NotImplementedError(
        'tf.keras.estimator.model_to_estimator function not available in your '
        'installation.')
  _model_to_estimator_usage_gauge.get_cell('v1').set(True)

            

Reported by Pylint.

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

Line: 351 Column: 1

                """

  try:
    from tensorflow_estimator.python.estimator import keras_lib  # pylint: disable=g-import-not-at-top
  except ImportError:
    raise NotImplementedError(
        'tf.keras.estimator.model_to_estimator function not available in your '
        'installation.')
  _model_to_estimator_usage_gauge.get_cell('v2').set(True)

            

Reported by Pylint.

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

Line: 165 Column: 5

                try:
    from tensorflow_estimator.python.estimator import keras_lib  # pylint: disable=g-import-not-at-top
  except ImportError:
    raise NotImplementedError(
        'tf.keras.estimator.model_to_estimator function not available in your '
        'installation.')
  _model_to_estimator_usage_gauge.get_cell('v1').set(True)
  return keras_lib.model_to_estimator(  # pylint:disable=unexpected-keyword-arg
      keras_model=keras_model,

            

Reported by Pylint.

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

Line: 353 Column: 5

                try:
    from tensorflow_estimator.python.estimator import keras_lib  # pylint: disable=g-import-not-at-top
  except ImportError:
    raise NotImplementedError(
        'tf.keras.estimator.model_to_estimator function not available in your '
        'installation.')
  _model_to_estimator_usage_gauge.get_cell('v2').set(True)
  return keras_lib.model_to_estimator(  # pylint:disable=unexpected-keyword-arg
      keras_model=keras_model,

            

Reported by Pylint.

Too many arguments (8/5)
Error

Line: 32 Column: 1

              
# LINT.IfChange
@keras_export(v1=['keras.estimator.model_to_estimator'])
def model_to_estimator(
    keras_model=None,
    keras_model_path=None,
    custom_objects=None,
    model_dir=None,
    config=None,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 41 Column: 1

                  checkpoint_format='saver',
    metric_names_map=None,
    export_outputs=None):
  """Constructs an `Estimator` instance from given keras model.

  If you use infrastructure or other tooling that relies on Estimators, you can
  still build a Keras model and use model_to_estimator to convert the Keras
  model to an Estimator for use with downstream systems.


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 162 Column: 1

                  ValueError: If an invalid checkpoint_format was given.
  """

  try:
    from tensorflow_estimator.python.estimator import keras_lib  # pylint: disable=g-import-not-at-top
  except ImportError:
    raise NotImplementedError(
        'tf.keras.estimator.model_to_estimator function not available in your '
        'installation.')

            

Reported by Pylint.

Import outside toplevel (tensorflow_estimator.python.estimator.keras_lib)
Error

Line: 163 Column: 5

                """

  try:
    from tensorflow_estimator.python.estimator import keras_lib  # pylint: disable=g-import-not-at-top
  except ImportError:
    raise NotImplementedError(
        'tf.keras.estimator.model_to_estimator function not available in your '
        'installation.')
  _model_to_estimator_usage_gauge.get_cell('v1').set(True)

            

Reported by Pylint.

keras/distribute/saved_model_mixed_api_test.py
24 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 23 Column: 1

              tf.saved_model.save().
"""

import tensorflow.compat.v2 as tf
from keras import testing_utils
from keras.distribute import saved_model_test_base as test_base
from keras.saving import save

_DEFAULT_FUNCTION_KEY = 'serving_default'

            

Reported by Pylint.

Missing class docstring
Error

Line: 33 Column: 1

              
@testing_utils.run_all_without_tensor_float_32(
    'Uses Dense layers, which call matmul')
class SavedModelSaveAndLoadTest(test_base.TestSavedModelBase):

  def setUp(self):
    self._root_dir = 'saved_model_save_load'
    super(SavedModelSaveAndLoadTest, self).setUp()


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 35 Column: 1

                  'Uses Dense layers, which call matmul')
class SavedModelSaveAndLoadTest(test_base.TestSavedModelBase):

  def setUp(self):
    self._root_dir = 'saved_model_save_load'
    super(SavedModelSaveAndLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 36 Column: 1

              class SavedModelSaveAndLoadTest(test_base.TestSavedModelBase):

  def setUp(self):
    self._root_dir = 'saved_model_save_load'
    super(SavedModelSaveAndLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')


            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 37 Column: 5

              
  def setUp(self):
    self._root_dir = 'saved_model_save_load'
    super(SavedModelSaveAndLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')

  def _load_and_run_model(self,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 37 Column: 1

              
  def setUp(self):
    self._root_dir = 'saved_model_save_load'
    super(SavedModelSaveAndLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')

  def _load_and_run_model(self,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 39 Column: 1

                  self._root_dir = 'saved_model_save_load'
    super(SavedModelSaveAndLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')

  def _load_and_run_model(self,
                          distribution,
                          saved_dir,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 40 Column: 1

                  super(SavedModelSaveAndLoadTest, self).setUp()

  def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')

  def _load_and_run_model(self,
                          distribution,
                          saved_dir,
                          predict_dataset,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 42 Column: 1

                def _save_model(self, model, saved_dir):
    save.save_model(model, saved_dir, save_format='tf')

  def _load_and_run_model(self,
                          distribution,
                          saved_dir,
                          predict_dataset,
                          output_name='output_1'):
    return test_base.load_and_run_with_saved_model_api(distribution, saved_dir,

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 47 Column: 1

                                        saved_dir,
                          predict_dataset,
                          output_name='output_1'):
    return test_base.load_and_run_with_saved_model_api(distribution, saved_dir,
                                                       predict_dataset,
                                                       output_name)

  @tf.__internal__.distribute.combinations.generate(test_base.simple_models_with_strategies())
  def test_save_no_strategy_restore_strategy(self, model_and_input,

            

Reported by Pylint.

keras/layers/core/repeat_vector.py
24 issues
Bad option value 'g-direct-tensorflow-import'
Error

Line: 16 Column: 1

              # limitations under the License.
# ==============================================================================
"""Contains the RepeatVector layer."""
# pylint: disable=g-classes-have-attributes,g-direct-tensorflow-import

from keras import backend as K
from keras.engine.base_layer import Layer
from keras.engine.input_spec import InputSpec
import tensorflow.compat.v2 as tf

            

Reported by Pylint.

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

Line: 16 Column: 1

              # limitations under the License.
# ==============================================================================
"""Contains the RepeatVector layer."""
# pylint: disable=g-classes-have-attributes,g-direct-tensorflow-import

from keras import backend as K
from keras.engine.base_layer import Layer
from keras.engine.input_spec import InputSpec
import tensorflow.compat.v2 as tf

            

Reported by Pylint.

Unable to import 'tensorflow.compat.v2'
Error

Line: 21 Column: 1

              from keras import backend as K
from keras.engine.base_layer import Layer
from keras.engine.input_spec import InputSpec
import tensorflow.compat.v2 as tf

from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.layers.RepeatVector')

            

Reported by Pylint.

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

Line: 23 Column: 1

              from keras.engine.input_spec import InputSpec
import tensorflow.compat.v2 as tf

from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.layers.RepeatVector')
class RepeatVector(Layer):
  """Repeats the input n times.

            

Reported by Pylint.

Parameters differ from overridden 'call' method
Error

Line: 59 Column: 3

                  input_shape = tf.TensorShape(input_shape).as_list()
    return tf.TensorShape([input_shape[0], self.n, input_shape[1]])

  def call(self, inputs):
    return K.repeat(inputs, self.n)

  def get_config(self):
    config = {'n': self.n}
    base_config = super(RepeatVector, self).get_config()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

              
@keras_export('keras.layers.RepeatVector')
class RepeatVector(Layer):
  """Repeats the input n times.

  Example:

  ```python
  model = Sequential()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 48 Column: 1

                Output shape: 3D tensor of shape `(num_samples, n, features)`.
  """

  def __init__(self, n, **kwargs):
    super(RepeatVector, self).__init__(**kwargs)
    self.n = n
    if not isinstance(n, int):
      raise TypeError(f'Expected an integer value for `n`, got {type(n)}.')
    self.input_spec = InputSpec(ndim=2)

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 49 Column: 5

                """

  def __init__(self, n, **kwargs):
    super(RepeatVector, self).__init__(**kwargs)
    self.n = n
    if not isinstance(n, int):
      raise TypeError(f'Expected an integer value for `n`, got {type(n)}.')
    self.input_spec = InputSpec(ndim=2)


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 49 Column: 1

                """

  def __init__(self, n, **kwargs):
    super(RepeatVector, self).__init__(**kwargs)
    self.n = n
    if not isinstance(n, int):
      raise TypeError(f'Expected an integer value for `n`, got {type(n)}.')
    self.input_spec = InputSpec(ndim=2)


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 50 Column: 1

              
  def __init__(self, n, **kwargs):
    super(RepeatVector, self).__init__(**kwargs)
    self.n = n
    if not isinstance(n, int):
      raise TypeError(f'Expected an integer value for `n`, got {type(n)}.')
    self.input_spec = InputSpec(ndim=2)

  def compute_output_shape(self, input_shape):

            

Reported by Pylint.