The following issues were found

keras/integration_test/vectorized_map_test.py
24 issues
Unable to import 'tensorflow'
Error

Line: 16 Column: 1

              # limitations under the License.
# ==============================================================================

import tensorflow as tf


class VectorizedMapTest(tf.test.TestCase):

  def test_vectorized_map(self):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software

            

Reported by Pylint.

Missing class docstring
Error

Line: 19 Column: 1

              import tensorflow as tf


class VectorizedMapTest(tf.test.TestCase):

  def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 19 Column: 1

              import tensorflow as tf


class VectorizedMapTest(tf.test.TestCase):

  def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 3

              
class VectorizedMapTest(tf.test.TestCase):

  def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

    def model_fn(arg):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 21 Column: 1

              
class VectorizedMapTest(tf.test.TestCase):

  def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

    def model_fn(arg):

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 22 Column: 1

              class VectorizedMapTest(tf.test.TestCase):

  def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

    def model_fn(arg):
      with tf.GradientTape() as g:

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 23 Column: 1

              
  def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

    def model_fn(arg):
      with tf.GradientTape() as g:
        inp, label = arg

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 24 Column: 1

                def test_vectorized_map(self):
    batch_size = 10
    num_features = 32
    layer = tf.keras.layers.Dense(1)

    def model_fn(arg):
      with tf.GradientTape() as g:
        inp, label = arg
        inp = tf.expand_dims(inp, 0)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 26 Column: 1

                  num_features = 32
    layer = tf.keras.layers.Dense(1)

    def model_fn(arg):
      with tf.GradientTape() as g:
        inp, label = arg
        inp = tf.expand_dims(inp, 0)
        label = tf.expand_dims(label, 0)
        prediction = layer(inp)

            

Reported by Pylint.

keras/benchmarks/layer_benchmarks/layer_benchmarks_test_base.py
23 issues
Unable to import 'tensorflow'
Error

Line: 21 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow as tf

import time

from keras.benchmarks.layer_benchmarks import run_xprof


            

Reported by Pylint.

Unable to import 'keras.benchmarks.layer_benchmarks'
Error

Line: 25 Column: 1

              
import time

from keras.benchmarks.layer_benchmarks import run_xprof


class LayerBenchmarksBase(tf.test.Benchmark):
  """Run and report benchmark results.


            

Reported by Pylint.

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

Line: 23 Column: 1

              
import tensorflow as tf

import time

from keras.benchmarks.layer_benchmarks import run_xprof


class LayerBenchmarksBase(tf.test.Benchmark):

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 28 Column: 1

              from keras.benchmarks.layer_benchmarks import run_xprof


class LayerBenchmarksBase(tf.test.Benchmark):
  """Run and report benchmark results.

  The first run is without any profiling to purly measure running time.
  Second run is with xprof but no python trace.
  Third run is with xprof and python trace.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              

class LayerBenchmarksBase(tf.test.Benchmark):
  """Run and report benchmark results.

  The first run is without any profiling to purly measure running time.
  Second run is with xprof but no python trace.
  Third run is with xprof and python trace.
  Note: xprof runs fewer iterations, and the maximum iterations is 100.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 37 Column: 1

                Note: xprof runs fewer iterations, and the maximum iterations is 100.
  """

  def run_report(self, func, num_iters, metadata=None):
    """Run and report benchmark results for different settings."""

    # 0. Warm up.
    func()


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 38 Column: 1

                """

  def run_report(self, func, num_iters, metadata=None):
    """Run and report benchmark results for different settings."""

    # 0. Warm up.
    func()

    # 1. Run without profiling.

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 41 Column: 1

                  """Run and report benchmark results for different settings."""

    # 0. Warm up.
    func()

    # 1. Run without profiling.
    start = time.time()
    for _ in range(num_iters):
      func()

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 44 Column: 1

                  func()

    # 1. Run without profiling.
    start = time.time()
    for _ in range(num_iters):
      func()
    total_time = time.time() - start
    us_mean_time = total_time * 1e6 / num_iters


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 45 Column: 1

              
    # 1. Run without profiling.
    start = time.time()
    for _ in range(num_iters):
      func()
    total_time = time.time() - start
    us_mean_time = total_time * 1e6 / num_iters

    metrics = [

            

Reported by Pylint.

keras/utils/np_utils.py
23 issues
Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 18 Column: 1

              """Numpy-related utilities."""

import numpy as np
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.utils.to_categorical')
def to_categorical(y, num_classes=None, dtype='float32'):
  """Converts a class vector (integers) to binary class matrix.

            

Reported by Pylint.

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

Line: 22 Column: 1

              

@keras_export('keras.utils.to_categorical')
def to_categorical(y, num_classes=None, dtype='float32'):
  """Converts a class vector (integers) to binary class matrix.

  E.g. for use with `categorical_crossentropy`.

  Args:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 23 Column: 1

              
@keras_export('keras.utils.to_categorical')
def to_categorical(y, num_classes=None, dtype='float32'):
  """Converts a class vector (integers) to binary class matrix.

  E.g. for use with `categorical_crossentropy`.

  Args:
      y: Array-like with class values to be converted into a matrix

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 62 Column: 1

                >>> print(np.around(loss, 5))
  [0. 0. 0. 0.]
  """
  y = np.array(y, dtype='int')
  input_shape = y.shape
  if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
    input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 63 Column: 1

                [0. 0. 0. 0.]
  """
  y = np.array(y, dtype='int')
  input_shape = y.shape
  if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
    input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:
    num_classes = np.max(y) + 1

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 64 Column: 1

                """
  y = np.array(y, dtype='int')
  input_shape = y.shape
  if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
    input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:
    num_classes = np.max(y) + 1
  n = y.shape[0]

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 65 Column: 1

                y = np.array(y, dtype='int')
  input_shape = y.shape
  if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
    input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:
    num_classes = np.max(y) + 1
  n = y.shape[0]
  categorical = np.zeros((n, num_classes), dtype=dtype)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 66 Column: 1

                input_shape = y.shape
  if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
    input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:
    num_classes = np.max(y) + 1
  n = y.shape[0]
  categorical = np.zeros((n, num_classes), dtype=dtype)
  categorical[np.arange(n), y] = 1

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 67 Column: 1

                if input_shape and input_shape[-1] == 1 and len(input_shape) > 1:
    input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:
    num_classes = np.max(y) + 1
  n = y.shape[0]
  categorical = np.zeros((n, num_classes), dtype=dtype)
  categorical[np.arange(n), y] = 1
  output_shape = input_shape + (num_classes,)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 68 Column: 1

                  input_shape = tuple(input_shape[:-1])
  y = y.ravel()
  if not num_classes:
    num_classes = np.max(y) + 1
  n = y.shape[0]
  categorical = np.zeros((n, num_classes), dtype=dtype)
  categorical[np.arange(n), y] = 1
  output_shape = input_shape + (num_classes,)
  categorical = np.reshape(categorical, output_shape)

            

Reported by Pylint.

keras/distribute/worker_training_state_test.py
23 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests of `worker_training_state.py` utilities."""

import tensorflow.compat.v2 as tf

import os
import sys

from absl.testing import parameterized

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 22 Column: 1

              import os
import sys

from absl.testing import parameterized
from keras import callbacks
from keras.distribute import multi_worker_testing_utils


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

            

Reported by Pylint.

Access to a protected member _exit of a client class
Error

Line: 52 Column: 57

              

if __name__ == '__main__':
  with tf.compat.v1.test.mock.patch.object(sys, 'exit', os._exit):
    tf.test.main()

            

Reported by Pylint.

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

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

import os
import sys

from absl.testing import parameterized
from keras import callbacks
from keras.distribute import multi_worker_testing_utils

            

Reported by Pylint.

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

Line: 20 Column: 1

              import tensorflow.compat.v2 as tf

import os
import sys

from absl.testing import parameterized
from keras import callbacks
from keras.distribute import multi_worker_testing_utils


            

Reported by Pylint.

Missing class docstring
Error

Line: 27 Column: 1

              from keras.distribute import multi_worker_testing_utils


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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          mode=['eager'],
          file_format=['h5', 'tf'],

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 27 Column: 1

              from keras.distribute import multi_worker_testing_utils


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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          mode=['eager'],
          file_format=['h5', 'tf'],

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          mode=['eager'],
          file_format=['h5', 'tf'],
          save_weights_only=[True, False]))
  def testCheckpointExists(self, file_format, save_weights_only):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 34 Column: 3

                        mode=['eager'],
          file_format=['h5', 'tf'],
          save_weights_only=[True, False]))
  def testCheckpointExists(self, file_format, save_weights_only):
    train_ds, _ = multi_worker_testing_utils.mnist_synthetic_dataset(64, 2)
    model = multi_worker_testing_utils.get_mnist_model((28, 28, 1))
    saving_dir = self.get_temp_dir()
    saving_filepath = os.path.join(saving_dir, 'checkpoint.' + file_format)
    callbacks_list = [

            

Reported by Pylint.

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

Line: 34 Column: 3

                        mode=['eager'],
          file_format=['h5', 'tf'],
          save_weights_only=[True, False]))
  def testCheckpointExists(self, file_format, save_weights_only):
    train_ds, _ = multi_worker_testing_utils.mnist_synthetic_dataset(64, 2)
    model = multi_worker_testing_utils.get_mnist_model((28, 28, 1))
    saving_dir = self.get_temp_dir()
    saving_filepath = os.path.join(saving_dir, 'checkpoint.' + file_format)
    callbacks_list = [

            

Reported by Pylint.

keras/integration_test/preprocessing_applied_in_model_test.py
23 issues
Unable to import 'tensorflow'
Error

Line: 20 Column: 1

              from __future__ import division
from __future__ import print_function

import tensorflow as tf
from keras.integration_test import preprocessing_test_utils as utils

ds_combinations = tf.__internal__.distribute.combinations
multi_process_runner = tf.__internal__.distribute.multi_process_runner
test_combinations = tf.__internal__.test.combinations

            

Reported by Pylint.

Unable to import 'keras.integration_test'
Error

Line: 21 Column: 1

              from __future__ import print_function

import tensorflow as tf
from keras.integration_test import preprocessing_test_utils as utils

ds_combinations = tf.__internal__.distribute.combinations
multi_process_runner = tf.__internal__.distribute.multi_process_runner
test_combinations = tf.__internal__.test.combinations


            

Reported by Pylint.

TODO(b/183044870) TPU strategies with soft placement do not yet work.
Error

Line: 33 Column: 3

                  ds_combinations.default_strategy,
    ds_combinations.mirrored_strategy_with_cpu_1_and_2,
    ds_combinations.mirrored_strategy_with_two_gpus,
    # TODO(b/183044870) TPU strategies with soft placement do not yet work.
    # ds_combinations.tpu_strategy,
    # ds_combinations.cloud_tpu_strategy,
    ds_combinations.parameter_server_strategy_3worker_2ps_cpu,
    ds_combinations.parameter_server_strategy_3worker_2ps_1gpu,
    ds_combinations.multi_worker_mirrored_2x1_cpu,

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 46 Column: 1

              
@ds_combinations.generate(
    test_combinations.combine(strategy=STRATEGIES, mode="eager"))
class PreprocessingAppliedInModelTest(tf.test.TestCase):
  """Demonstrate Keras preprocessing layers applied inside a Model."""

  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 47 Column: 1

              @ds_combinations.generate(
    test_combinations.combine(strategy=STRATEGIES, mode="eager"))
class PreprocessingAppliedInModelTest(tf.test.TestCase):
  """Demonstrate Keras preprocessing layers applied inside a Model."""

  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())
      training_model = utils.make_training_model()

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 49 Column: 1

              class PreprocessingAppliedInModelTest(tf.test.TestCase):
  """Demonstrate Keras preprocessing layers applied inside a Model."""

  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())
      training_model = utils.make_training_model()
      # Merge the two separate models into a single model for training.
      inputs = preprocessing_model.inputs

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 49 Column: 3

              class PreprocessingAppliedInModelTest(tf.test.TestCase):
  """Demonstrate Keras preprocessing layers applied inside a Model."""

  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())
      training_model = utils.make_training_model()
      # Merge the two separate models into a single model for training.
      inputs = preprocessing_model.inputs

            

Reported by Pylint.

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

Line: 49 Column: 3

              class PreprocessingAppliedInModelTest(tf.test.TestCase):
  """Demonstrate Keras preprocessing layers applied inside a Model."""

  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())
      training_model = utils.make_training_model()
      # Merge the two separate models into a single model for training.
      inputs = preprocessing_model.inputs

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 50 Column: 1

                """Demonstrate Keras preprocessing layers applied inside a Model."""

  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())
      training_model = utils.make_training_model()
      # Merge the two separate models into a single model for training.
      inputs = preprocessing_model.inputs
      outputs = training_model(preprocessing_model(inputs))

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 51 Column: 1

              
  def testDistributedModelFit(self, strategy):
    with strategy.scope():
      preprocessing_model = utils.make_preprocessing_model(self.get_temp_dir())
      training_model = utils.make_training_model()
      # Merge the two separate models into a single model for training.
      inputs = preprocessing_model.inputs
      outputs = training_model(preprocessing_model(inputs))
      merged_model = tf.keras.Model(inputs, outputs)

            

Reported by Pylint.

keras/layers/preprocessing/image_preprocessing_distribution_test.py
22 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

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

import tensorflow.compat.v2 as tf

import numpy as np

import keras
from keras import keras_parameterized

            

Reported by Pylint.

TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
Error

Line: 40 Column: 3

                def test_distribution(self, strategy):
    if "CentralStorage" in type(strategy).__name__:
      self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(
        16, drop_remainder=True)

    with strategy.scope():

            

Reported by Pylint.

Missing class docstring
Error

Line: 33 Column: 1

                      strategy=strategy_combinations.all_strategies +
        strategy_combinations.multi_worker_mirrored_strategies,
        mode=["eager", "graph"]))
class ImagePreprocessingDistributionTest(
    keras_parameterized.TestCase,
    preprocessing_test_utils.PreprocessingLayerTest):

  def test_distribution(self, strategy):
    if "CentralStorage" in type(strategy).__name__:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 37 Column: 3

                  keras_parameterized.TestCase,
    preprocessing_test_utils.PreprocessingLayerTest):

  def test_distribution(self, strategy):
    if "CentralStorage" in type(strategy).__name__:
      self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 37 Column: 1

                  keras_parameterized.TestCase,
    preprocessing_test_utils.PreprocessingLayerTest):

  def test_distribution(self, strategy):
    if "CentralStorage" in type(strategy).__name__:
      self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 38 Column: 1

                  preprocessing_test_utils.PreprocessingLayerTest):

  def test_distribution(self, strategy):
    if "CentralStorage" in type(strategy).__name__:
      self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(
        16, drop_remainder=True)

            

Reported by Pylint.

Bad indentation. Found 6 spaces, expected 12
Style

Line: 39 Column: 1

              
  def test_distribution(self, strategy):
    if "CentralStorage" in type(strategy).__name__:
      self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(
        16, drop_remainder=True)


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 41 Column: 1

                  if "CentralStorage" in type(strategy).__name__:
      self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(
        16, drop_remainder=True)

    with strategy.scope():
      input_data = keras.Input(shape=(32, 32, 3), dtype=tf.float32)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 42 Column: 1

                    self.skipTest("Does not work with CentralStorageStrategy yet.")
    # TODO(b/159738418): large image input causes OOM in ubuntu multi gpu.
    np_images = np.random.random((32, 32, 32, 3)).astype(np.float32)
    image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(
        16, drop_remainder=True)

    with strategy.scope():
      input_data = keras.Input(shape=(32, 32, 3), dtype=tf.float32)
      image_preprocessor = keras.Sequential([

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 45 Column: 1

                  image_dataset = tf.data.Dataset.from_tensor_slices(np_images).batch(
        16, drop_remainder=True)

    with strategy.scope():
      input_data = keras.Input(shape=(32, 32, 3), dtype=tf.float32)
      image_preprocessor = keras.Sequential([
          image_preprocessing.Resizing(height=256, width=256),
          image_preprocessing.RandomCrop(height=224, width=224),
          image_preprocessing.RandomTranslation(.1, .1),

            

Reported by Pylint.

keras/saving/saved_model/load_context.py
22 issues
Bad indentation. Found 2 spaces, expected 4
Style

Line: 22 Column: 1

              

class LoadContext(threading.local):
  """A context for loading a model."""

  def __init__(self):
    super(LoadContext, self).__init__()
    self._load_options = None


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 24 Column: 1

              class LoadContext(threading.local):
  """A context for loading a model."""

  def __init__(self):
    super(LoadContext, self).__init__()
    self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options

            

Reported by Pylint.

Consider using Python 3 style super() without arguments
Error

Line: 25 Column: 5

                """A context for loading a model."""

  def __init__(self):
    super(LoadContext, self).__init__()
    self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 25 Column: 1

                """A context for loading a model."""

  def __init__(self):
    super(LoadContext, self).__init__()
    self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 26 Column: 1

              
  def __init__(self):
    super(LoadContext, self).__init__()
    self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options

  def clear_load_options(self):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 3

                  super(LoadContext, self).__init__()
    self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options

  def clear_load_options(self):
    self._load_options = None


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

                  super(LoadContext, self).__init__()
    self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options

  def clear_load_options(self):
    self._load_options = None


            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 29 Column: 1

                  self._load_options = None

  def set_load_options(self, load_options):
    self._load_options = load_options

  def clear_load_options(self):
    self._load_options = None

  def load_options(self):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

                def set_load_options(self, load_options):
    self._load_options = load_options

  def clear_load_options(self):
    self._load_options = None

  def load_options(self):
    return self._load_options


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 3

                def set_load_options(self, load_options):
    self._load_options = load_options

  def clear_load_options(self):
    self._load_options = None

  def load_options(self):
    return self._load_options


            

Reported by Pylint.

keras/distribute/keras_models_test.py
21 issues
Unable to import 'tensorflow.compat.v2'
Error

Line: 17 Column: 1

              # ==============================================================================
"""Tests for Keras high level APIs, e.g. fit, evaluate and predict."""

import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np

import keras

            

Reported by Pylint.

Unable to import 'absl.testing'
Error

Line: 19 Column: 1

              
import tensorflow.compat.v2 as tf

from absl.testing import parameterized
import numpy as np

import keras
from keras.distribute.strategy_combinations import all_strategies


            

Reported by Pylint.

Missing class docstring
Error

Line: 26 Column: 1

              from keras.distribute.strategy_combinations import all_strategies


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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 26 Column: 1

              from keras.distribute.strategy_combinations import all_strategies


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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 28 Column: 1

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

  @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):
    input_data = np.random.random([1, 32, 64, 64, 3])
    input_shape = tuple(input_data.shape[1:])

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 31 Column: 1

                @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):
    input_data = np.random.random([1, 32, 64, 64, 3])
    input_shape = tuple(input_data.shape[1:])

    def build_model():
      model = keras.models.Sequential()

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 3

                @tf.__internal__.distribute.combinations.generate(
      tf.__internal__.test.combinations.combine(
          distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):
    input_data = np.random.random([1, 32, 64, 64, 3])
    input_shape = tuple(input_data.shape[1:])

    def build_model():
      model = keras.models.Sequential()

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 32 Column: 1

                    tf.__internal__.test.combinations.combine(
          distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):
    input_data = np.random.random([1, 32, 64, 64, 3])
    input_shape = tuple(input_data.shape[1:])

    def build_model():
      model = keras.models.Sequential()
      model.add(

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 33 Column: 1

                        distribution=all_strategies, mode=["eager"]))
  def test_lstm_model_with_dynamic_batch(self, distribution):
    input_data = np.random.random([1, 32, 64, 64, 3])
    input_shape = tuple(input_data.shape[1:])

    def build_model():
      model = keras.models.Sequential()
      model.add(
          keras.layers.ConvLSTM2D(

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 35 Column: 1

                  input_data = np.random.random([1, 32, 64, 64, 3])
    input_shape = tuple(input_data.shape[1:])

    def build_model():
      model = keras.models.Sequential()
      model.add(
          keras.layers.ConvLSTM2D(
              4,
              kernel_size=(4, 4),

            

Reported by Pylint.

keras/benchmarks/layer_benchmarks/run_xprof.py
21 issues
Unable to import 'tensorflow.python.profiler'
Error

Line: 22 Column: 1

              import time
import uuid

from tensorflow.python.profiler import profiler_v2 as profiler

def run_with_xprof(self, func, num_iters_xprof=100, enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:

            

Reported by Pylint.

Undefined variable 'os'
Error

Line: 29 Column: 14

                suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
  else:
    options = profiler.ProfilerOptions(python_tracer_level=0)
    logdir = os.path.join(logdir, suid)

  start = time.time()

            

Reported by Pylint.

Undefined variable 'os'
Error

Line: 32 Column: 14

                  logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
  else:
    options = profiler.ProfilerOptions(python_tracer_level=0)
    logdir = os.path.join(logdir, suid)

  start = time.time()
  with profiler.Profile(logdir, options):
    for _ in range(num_iters_xprof):
      func()

            

Reported by Pylint.

Unused argument 'self'
Error

Line: 24 Column: 20

              
from tensorflow.python.profiler import profiler_v2 as profiler

def run_with_xprof(self, func, num_iters_xprof=100, enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")

            

Reported by Pylint.

Probable insecure usage of temp file/directory.
Security

Line: 25
Suggestion: https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html

              from tensorflow.python.profiler import profiler_v2 as profiler

def run_with_xprof(self, func, num_iters_xprof=100, enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
  else:

            

Reported by Bandit.

Missing module docstring
Error

Line: 1 Column: 1

              # Copyright 2020 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 1

              
from tensorflow.python.profiler import profiler_v2 as profiler

def run_with_xprof(self, func, num_iters_xprof=100, enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 26 Column: 1

              
def run_with_xprof(self, func, num_iters_xprof=100, enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
  else:
    options = profiler.ProfilerOptions(python_tracer_level=0)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 27 Column: 1

              def run_with_xprof(self, func, num_iters_xprof=100, enable_python_trace=True,
                   logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
  else:
    options = profiler.ProfilerOptions(python_tracer_level=0)
    logdir = os.path.join(logdir, suid)

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 28 Column: 1

                                 logdir='/tmp/layer_benchmark_xprof/'):
  suid = str(uuid.uuid4())
  if enable_python_trace:
    options = profiler.ProfilerOptions(python_tracer_level=1)
    logdir = os.path.join(logdir, str(uuid.uuid4()) + "_with_python")
  else:
    options = profiler.ProfilerOptions(python_tracer_level=0)
    logdir = os.path.join(logdir, suid)


            

Reported by Pylint.

keras/datasets/cifar10.py
21 issues
Unable to import 'tensorflow.python.util.tf_export'
Error

Line: 24 Column: 1

              from keras import backend
from keras.datasets.cifar import load_batch
from keras.utils.data_utils import get_file
from tensorflow.python.util.tf_export import keras_export


@keras_export('keras.datasets.cifar10.load_data')
def load_data():
  """Loads the CIFAR10 dataset.

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 29 Column: 1

              
@keras_export('keras.datasets.cifar10.load_data')
def load_data():
  """Loads the CIFAR10 dataset.

  This is a dataset of 50,000 32x32 color training images and 10,000 test
  images, labeled over 10 categories. See more info at the
  [CIFAR homepage](https://www.cs.toronto.edu/~kriz/cifar.html).


            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 77 Column: 1

                assert y_test.shape == (10000, 1)
  ```
  """
  dirname = 'cifar-10-batches-py'
  origin = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz'
  path = get_file(
      dirname,
      origin=origin,
      untar=True,

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 78 Column: 1

                ```
  """
  dirname = 'cifar-10-batches-py'
  origin = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz'
  path = get_file(
      dirname,
      origin=origin,
      untar=True,
      file_hash=

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 79 Column: 1

                """
  dirname = 'cifar-10-batches-py'
  origin = 'https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz'
  path = get_file(
      dirname,
      origin=origin,
      untar=True,
      file_hash=
      '6d958be074577803d12ecdefd02955f39262c83c16fe9348329d7fe0b5c001ce')

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 86 Column: 1

                    file_hash=
      '6d958be074577803d12ecdefd02955f39262c83c16fe9348329d7fe0b5c001ce')

  num_train_samples = 50000

  x_train = np.empty((num_train_samples, 3, 32, 32), dtype='uint8')
  y_train = np.empty((num_train_samples,), dtype='uint8')

  for i in range(1, 6):

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 88 Column: 1

              
  num_train_samples = 50000

  x_train = np.empty((num_train_samples, 3, 32, 32), dtype='uint8')
  y_train = np.empty((num_train_samples,), dtype='uint8')

  for i in range(1, 6):
    fpath = os.path.join(path, 'data_batch_' + str(i))
    (x_train[(i - 1) * 10000:i * 10000, :, :, :],

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 89 Column: 1

                num_train_samples = 50000

  x_train = np.empty((num_train_samples, 3, 32, 32), dtype='uint8')
  y_train = np.empty((num_train_samples,), dtype='uint8')

  for i in range(1, 6):
    fpath = os.path.join(path, 'data_batch_' + str(i))
    (x_train[(i - 1) * 10000:i * 10000, :, :, :],
     y_train[(i - 1) * 10000:i * 10000]) = load_batch(fpath)

            

Reported by Pylint.

Bad indentation. Found 2 spaces, expected 4
Style

Line: 91 Column: 1

                x_train = np.empty((num_train_samples, 3, 32, 32), dtype='uint8')
  y_train = np.empty((num_train_samples,), dtype='uint8')

  for i in range(1, 6):
    fpath = os.path.join(path, 'data_batch_' + str(i))
    (x_train[(i - 1) * 10000:i * 10000, :, :, :],
     y_train[(i - 1) * 10000:i * 10000]) = load_batch(fpath)

  fpath = os.path.join(path, 'test_batch')

            

Reported by Pylint.

Bad indentation. Found 4 spaces, expected 8
Style

Line: 92 Column: 1

                y_train = np.empty((num_train_samples,), dtype='uint8')

  for i in range(1, 6):
    fpath = os.path.join(path, 'data_batch_' + str(i))
    (x_train[(i - 1) * 10000:i * 10000, :, :, :],
     y_train[(i - 1) * 10000:i * 10000]) = load_batch(fpath)

  fpath = os.path.join(path, 'test_batch')
  x_test, y_test = load_batch(fpath)

            

Reported by Pylint.