The following issues were found
keras/engine/training_test.py
2764 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for training routines."""
import tensorflow.compat.v2 as tf
import collections
import io
import tempfile
import sys
Reported by Pylint.
Line: 24
Column: 1
import tempfile
import sys
from absl.testing import parameterized
import numpy as np
from tensorflow.python.framework import test_util as tf_test_util
from keras import backend
from keras import combinations
from keras import keras_parameterized
Reported by Pylint.
Line: 26
Column: 1
from absl.testing import parameterized
import numpy as np
from tensorflow.python.framework import test_util as tf_test_util
from keras import backend
from keras import combinations
from keras import keras_parameterized
from keras import layers as layers_module
from keras import losses
Reported by Pylint.
Line: 42
Column: 1
from keras.engine import training_utils_v1
from keras.utils import data_utils
from keras.utils import np_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.training.rmsprop import RMSPropOptimizer
try:
import scipy.sparse as scipy_sparse # pylint: disable=g-import-not-at-top
except ImportError:
Reported by Pylint.
Line: 43
Column: 1
from keras.utils import data_utils
from keras.utils import np_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.training.rmsprop import RMSPropOptimizer
try:
import scipy.sparse as scipy_sparse # pylint: disable=g-import-not-at-top
except ImportError:
scipy_sparse = None
Reported by Pylint.
Line: 46
Column: 1
from tensorflow.python.training.rmsprop import RMSPropOptimizer
try:
import scipy.sparse as scipy_sparse # pylint: disable=g-import-not-at-top
except ImportError:
scipy_sparse = None
class TrainingTest(keras_parameterized.TestCase):
Reported by Pylint.
Line: 894
Column: 26
self.assertEqual([], model.layers)
self.assertEqual([], model.updates)
self.assertEqual([], model.losses)
self.assertEqual([], model.templates.layers)
self.assertEqual([], model.templates.updates)
self.assertEqual([], model.templates.losses)
@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
def test_logs_passed_to_callbacks(self):
Reported by Pylint.
Line: 895
Column: 26
self.assertEqual([], model.updates)
self.assertEqual([], model.losses)
self.assertEqual([], model.templates.layers)
self.assertEqual([], model.templates.updates)
self.assertEqual([], model.templates.losses)
@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
def test_logs_passed_to_callbacks(self):
input_dim = 5
Reported by Pylint.
Line: 896
Column: 26
self.assertEqual([], model.losses)
self.assertEqual([], model.templates.layers)
self.assertEqual([], model.templates.updates)
self.assertEqual([], model.templates.losses)
@keras_parameterized.run_all_keras_modes(always_skip_v1=True)
def test_logs_passed_to_callbacks(self):
input_dim = 5
num_classes = 1
Reported by Pylint.
Line: 62
Column: 21
]
model = testing_utils.get_model_from_layers(layers, input_shape=(1,))
self.assertTrue(model._instrumented_keras_api)
self.assertTrue(model._instrumented_keras_model_class)
self.assertFalse(model._instrumented_keras_layer_class)
@keras_parameterized.run_with_all_model_types
@keras_parameterized.run_all_keras_modes
Reported by Pylint.
keras/backend.py
2249 issues
Line: 18
Column: 1
# pylint: disable=protected-access
# pylint: disable=redefined-outer-name
# pylint: disable=redefined-builtin
# pylint: disable=g-classes-have-attributes
"""Keras backend API."""
import tensorflow.compat.v2 as tf
import collections
Reported by Pylint.
Line: 21
Column: 1
# pylint: disable=g-classes-have-attributes
"""Keras backend API."""
import tensorflow.compat.v2 as tf
import collections
import itertools
import json
import os
Reported by Pylint.
Line: 34
Column: 1
import numpy as np
from tensorflow.core.protobuf import config_pb2
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import config
from keras import backend_config
from keras.distribute import distribute_coordinator_utils as dc
Reported by Pylint.
Line: 35
Column: 1
import numpy as np
from tensorflow.core.protobuf import config_pb2
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import config
from keras import backend_config
from keras.distribute import distribute_coordinator_utils as dc
from keras.engine import keras_tensor
Reported by Pylint.
Line: 36
Column: 1
from tensorflow.core.protobuf import config_pb2
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import config
from keras import backend_config
from keras.distribute import distribute_coordinator_utils as dc
from keras.engine import keras_tensor
from keras.utils import control_flow_util
Reported by Pylint.
Line: 37
Column: 1
from tensorflow.core.protobuf import config_pb2
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import config
from keras import backend_config
from keras.distribute import distribute_coordinator_utils as dc
from keras.engine import keras_tensor
from keras.utils import control_flow_util
from keras.utils import object_identity
Reported by Pylint.
Line: 45
Column: 1
from keras.utils import object_identity
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
py_all = all
py_sum = sum
Reported by Pylint.
Line: 46
Column: 1
from keras.utils import tf_contextlib
from keras.utils import tf_inspect
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
py_all = all
py_sum = sum
py_any = any
Reported by Pylint.
Line: 47
Column: 1
from keras.utils import tf_inspect
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
py_all = all
py_sum = sum
py_any = any
Reported by Pylint.
Line: 473
Column: 3
'will be removed after 2020-10-11. To update it, simply '
'pass a True/False value to the `training` argument of the '
'`__call__` method of your layer or model.')
with deprecated_internal_learning_phase_scope(value):
try:
yield
finally:
pass
Reported by Pylint.
keras/engine/functional_test.py
2001 issues
Line: 17
Column: 1
#,============================================================================
"""Tests for layer graphs construction & handling."""
import tensorflow.compat.v2 as tf
import warnings
import numpy as np
from keras import backend
Reported by Pylint.
Line: 37
Column: 1
from keras.engine import training as training_lib
from keras.utils import layer_utils
from keras.utils import tf_utils
from tensorflow.python.training.tracking.util import Checkpoint
class NetworkConstructionTest(keras_parameterized.TestCase):
def test_default_model_name(self):
Reported by Pylint.
Line: 1767
Column: 22
self.assertIn('ignored by the model', str(w[-1].message))
# Make sure the model inputs are sorted with the dict keys.
self.assertEqual(model.inputs[0]._keras_history.layer.name, 'b')
self.assertEqual(model.inputs[1]._keras_history.layer.name, 'a')
class GraphUtilsTest(tf.test.TestCase):
Reported by Pylint.
Line: 1768
Column: 22
# Make sure the model inputs are sorted with the dict keys.
self.assertEqual(model.inputs[0]._keras_history.layer.name, 'b')
self.assertEqual(model.inputs[1]._keras_history.layer.name, 'a')
class GraphUtilsTest(tf.test.TestCase):
def testGetReachableFromInputs(self):
Reported by Pylint.
Line: 2479
Column: 22
m = MixedFunctionalSubclassModel(foo='123')
self.assertTrue(m._is_graph_network)
self.assertLen(m.weights, 2)
self.assertEqual(m.outputs[0].shape.as_list(), [None, 32])
self.assertEqual(m.get_foo(), '123')
def testFunctionalSubclassPostMixin(self):
# Make sure the the mixin class is also init correct when the order changed.
Reported by Pylint.
Line: 24
Column: 1
import numpy as np
from keras import backend
from keras import combinations
from keras import initializers
from keras import keras_parameterized
from keras import layers
from keras import losses
from keras import models
from keras import testing_utils
Reported by Pylint.
Line: 59
Column: 9
class MyLayer(layers.Layer):
def build(self, input_shape):
self.a = self.add_variable('a',
(1, 1),
'float32',
trainable=False)
self.b = self.add_variable('b',
(1, 1),
Reported by Pylint.
Line: 63
Column: 9
(1, 1),
'float32',
trainable=False)
self.b = self.add_variable('b',
(1, 1),
'float32',
trainable=False)
self.add_update(tf.compat.v1.assign_add(self.a, [[1.]],
name='unconditional_update'))
Reported by Pylint.
Line: 71
Column: 7
name='unconditional_update'))
self.built = True
def call(self, inputs):
self.add_update(tf.compat.v1.assign_add(self.b, inputs,
name='conditional_update'),
inputs=True)
return inputs + 1
Reported by Pylint.
Line: 214
Column: 7
class PowersLayer(layers.Layer):
def call(self, inputs):
return [inputs**2, inputs**3]
x = input_layer_lib.Input(shape=(32,))
test_layer = PowersLayer()
p1, p2 = test_layer(x) # pylint: disable=not-callable
Reported by Pylint.
keras/metrics_test.py
1889 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for Keras metrics functions."""
import tensorflow.compat.v2 as tf
import json
import math
import os
Reported by Pylint.
Line: 23
Column: 1
import math
import os
from absl.testing import parameterized
import numpy as np
from keras import backend
from keras import combinations
from keras import keras_parameterized
from keras import layers
Reported by Pylint.
Line: 156
Column: 3
class MeanTest(keras_parameterized.TestCase):
# TODO(b/120949004): Re-enable garbage collection check
# @test_util.run_in_graph_and_eager_modes(assert_no_eager_garbage=True)
@keras_parameterized.run_all_keras_modes
def test_mean(self):
m = metrics.Mean(name='my_mean')
Reported by Pylint.
Line: 603
Column: 5
return np.multiply(x, x_inv_norm)
def setup(self, axis=1):
self.np_y_true = np.asarray([[1, 9, 2], [-5, -2, 6]], dtype=np.float32)
self.np_y_pred = np.asarray([[4, 8, 12], [8, 1, 3]], dtype=np.float32)
y_true = self.l2_norm(self.np_y_true, axis)
y_pred = self.l2_norm(self.np_y_pred, axis)
self.expected_loss = np.sum(np.multiply(y_true, y_pred), axis=(axis,))
Reported by Pylint.
Line: 604
Column: 5
def setup(self, axis=1):
self.np_y_true = np.asarray([[1, 9, 2], [-5, -2, 6]], dtype=np.float32)
self.np_y_pred = np.asarray([[4, 8, 12], [8, 1, 3]], dtype=np.float32)
y_true = self.l2_norm(self.np_y_true, axis)
y_pred = self.l2_norm(self.np_y_pred, axis)
self.expected_loss = np.sum(np.multiply(y_true, y_pred), axis=(axis,))
Reported by Pylint.
Line: 608
Column: 5
y_true = self.l2_norm(self.np_y_true, axis)
y_pred = self.l2_norm(self.np_y_pred, axis)
self.expected_loss = np.sum(np.multiply(y_true, y_pred), axis=(axis,))
self.y_true = tf.constant(self.np_y_true)
self.y_pred = tf.constant(self.np_y_pred)
def test_config(self):
Reported by Pylint.
Line: 610
Column: 5
y_pred = self.l2_norm(self.np_y_pred, axis)
self.expected_loss = np.sum(np.multiply(y_true, y_pred), axis=(axis,))
self.y_true = tf.constant(self.np_y_true)
self.y_pred = tf.constant(self.np_y_pred)
def test_config(self):
cosine_obj = metrics.CosineSimilarity(
axis=2, name='my_cos', dtype=tf.int32)
Reported by Pylint.
Line: 611
Column: 5
self.expected_loss = np.sum(np.multiply(y_true, y_pred), axis=(axis,))
self.y_true = tf.constant(self.np_y_true)
self.y_pred = tf.constant(self.np_y_pred)
def test_config(self):
cosine_obj = metrics.CosineSimilarity(
axis=2, name='my_cos', dtype=tf.int32)
self.assertEqual(cosine_obj.name, 'my_cos')
Reported by Pylint.
Line: 617
Column: 22
cosine_obj = metrics.CosineSimilarity(
axis=2, name='my_cos', dtype=tf.int32)
self.assertEqual(cosine_obj.name, 'my_cos')
self.assertEqual(cosine_obj._dtype, tf.int32)
# Check save and restore config
cosine_obj2 = metrics.CosineSimilarity.from_config(cosine_obj.get_config())
self.assertEqual(cosine_obj2.name, 'my_cos')
self.assertEqual(cosine_obj2._dtype, tf.int32)
Reported by Pylint.
Line: 622
Column: 22
# Check save and restore config
cosine_obj2 = metrics.CosineSimilarity.from_config(cosine_obj.get_config())
self.assertEqual(cosine_obj2.name, 'my_cos')
self.assertEqual(cosine_obj2._dtype, tf.int32)
def test_unweighted(self):
self.setup()
cosine_obj = metrics.CosineSimilarity()
self.evaluate(tf.compat.v1.variables_initializer(cosine_obj.variables))
Reported by Pylint.
keras/callbacks_test.py
1871 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for Keras callbacks."""
import tensorflow.compat.v2 as tf
import collections
import csv
import json
import os
Reported by Pylint.
Line: 30
Column: 1
import time
import unittest
from absl.testing import parameterized
import numpy as np
import keras
from keras import keras_parameterized
from keras import testing_utils
from keras.callbacks import BackupAndRestore
Reported by Pylint.
Line: 42
Column: 1
from keras.optimizer_v2 import gradient_descent
from keras.optimizer_v2 import learning_rate_schedule
from keras.utils import np_utils
from tensorflow.python.platform import tf_logging as logging
try:
import h5py # pylint:disable=g-import-not-at-top
except ImportError:
h5py = None
Reported by Pylint.
Line: 45
Column: 1
from tensorflow.python.platform import tf_logging as logging
try:
import h5py # pylint:disable=g-import-not-at-top
except ImportError:
h5py = None
try:
import requests # pylint:disable=g-import-not-at-top
Reported by Pylint.
Line: 50
Column: 1
h5py = None
try:
import requests # pylint:disable=g-import-not-at-top
except ImportError:
requests = None
TRAIN_SAMPLES = 10
Reported by Pylint.
Line: 1631
Column: 19
y_train = np_utils.to_categorical(y_train)
cbks = [keras.callbacks.TerminateOnNaN()]
model = keras.models.Sequential()
initializer = keras.initializers.Constant(value=1e5)
for _ in range(5):
model.add(
keras.layers.Dense(
2,
input_dim=INPUT_DIM,
Reported by Pylint.
Line: 79
Column: 3
run.
"""
def __init__(self):
self.method_counts = collections.defaultdict(int)
for method_name in CALLBACK_HOOKS:
setattr(self, method_name,
self.wrap_with_counts(method_name, getattr(self, method_name)))
Reported by Pylint.
Line: 97
Column: 3
class CallAllHooks(keras.callbacks.Callback):
"""A callback that calls self._run for all hooks"""
def __init__(self):
for method_name in CALLBACK_HOOKS:
setattr(self, method_name, self._run)
def _run(self, *args, logs=None):
raise NotImplementedError
Reported by Pylint.
Line: 290
Column: 7
super(AddAllOnes, self).__init__(name=name, **kwargs)
self.total = self.add_weight(name='total', initializer='zeros')
def update_state(self, y_true, y_pred, sample_weight=None):
self.total.assign_add(
tf.cast(tf.reduce_sum(y_true), dtype=tf.float32))
def result(self):
return self.total
Reported by Pylint.
Line: 290
Column: 38
super(AddAllOnes, self).__init__(name=name, **kwargs)
self.total = self.add_weight(name='total', initializer='zeros')
def update_state(self, y_true, y_pred, sample_weight=None):
self.total.assign_add(
tf.cast(tf.reduce_sum(y_true), dtype=tf.float32))
def result(self):
return self.total
Reported by Pylint.
keras/backend_test.py
1733 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for Keras backend."""
import tensorflow.compat.v2 as tf
import gc
import warnings
from absl.testing import parameterized
Reported by Pylint.
Line: 22
Column: 1
import gc
import warnings
from absl.testing import parameterized
import numpy as np
import scipy.sparse
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import test_util
Reported by Pylint.
Line: 24
Column: 1
from absl.testing import parameterized
import numpy as np
import scipy.sparse
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import test_util
from keras import activations
from keras import backend
Reported by Pylint.
Line: 25
Column: 1
from absl.testing import parameterized
import numpy as np
import scipy.sparse
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import test_util
from keras import activations
from keras import backend
from keras import combinations
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
import scipy.sparse
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import test_util
from keras import activations
from keras import backend
from keras import combinations
from keras.engine import input_layer
Reported by Pylint.
Line: 27
Column: 1
import scipy.sparse
from tensorflow.python.eager import context
from tensorflow.python.eager.context import get_config
from tensorflow.python.framework import test_util
from keras import activations
from keras import backend
from keras import combinations
from keras.engine import input_layer
from keras.layers import advanced_activations
Reported by Pylint.
Line: 155
Column: 7
backend.set_learning_phase(2)
# Test running with a learning-phase-consuming layer
with backend.learning_phase_scope(0):
x = input_layer.Input((3,))
y = batch_normalization_v1.BatchNormalization()(x)
if not tf.executing_eagerly():
self.evaluate(tf.compat.v1.global_variables_initializer())
sess.run(y, feed_dict={x: np.random.random((2, 3))})
Reported by Pylint.
Line: 170
Column: 5
def test_learning_phase_scope(self):
initial_learning_phase = backend.learning_phase()
with backend.learning_phase_scope(1):
self.assertEqual(backend.learning_phase(), 1)
self.assertEqual(backend.learning_phase(), initial_learning_phase)
with backend.learning_phase_scope(0):
self.assertEqual(backend.learning_phase(), 0)
self.assertEqual(backend.learning_phase(), initial_learning_phase)
Reported by Pylint.
Line: 173
Column: 5
with backend.learning_phase_scope(1):
self.assertEqual(backend.learning_phase(), 1)
self.assertEqual(backend.learning_phase(), initial_learning_phase)
with backend.learning_phase_scope(0):
self.assertEqual(backend.learning_phase(), 0)
self.assertEqual(backend.learning_phase(), initial_learning_phase)
with self.assertRaises(ValueError):
with backend.learning_phase_scope(None):
pass
Reported by Pylint.
Line: 177
Column: 7
self.assertEqual(backend.learning_phase(), 0)
self.assertEqual(backend.learning_phase(), initial_learning_phase)
with self.assertRaises(ValueError):
with backend.learning_phase_scope(None):
pass
self.assertEqual(backend.learning_phase(), initial_learning_phase)
new_learning_phase = 0
backend.set_learning_phase(new_learning_phase)
Reported by Pylint.
keras/distribute/distribute_strategy_test.py
1678 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for tf.keras models using tf.distribute.Strategy."""
import tensorflow.compat.v2 as tf
import os
from absl.testing import parameterized
import numpy as np
Reported by Pylint.
Line: 21
Column: 1
import os
from absl.testing import parameterized
import numpy as np
import keras
from tensorflow.python.distribute.cluster_resolver import SimpleClusterResolver
from keras import backend
Reported by Pylint.
Line: 25
Column: 1
import numpy as np
import keras
from tensorflow.python.distribute.cluster_resolver import SimpleClusterResolver
from keras import backend
from keras import testing_utils
from keras.distribute import distributed_training_utils
from keras.distribute import distributed_training_utils_v1
from keras.distribute import multi_worker_testing_utils
Reported by Pylint.
Line: 51
Column: 3
# Note: Please make sure the tests in this file are also covered in
# keras_backward_compat_test for features that are supported with both APIs.
# TODO(anjalisridhar): Add a decorator that will allow us to run these tests as
# part of the tf.keras unit tests suite.
def simple_sequential_model():
model = keras.models.Sequential()
Reported by Pylint.
Line: 65
Column: 3
def simple_subclassed_model(num_labels=_NUM_CLASS):
class _SimpleMLP(keras.Model):
def __init__(self, num_labels):
super(_SimpleMLP, self).__init__()
self.dense = keras.layers.Dense(num_labels)
Reported by Pylint.
Line: 71
Column: 5
super(_SimpleMLP, self).__init__()
self.dense = keras.layers.Dense(num_labels)
def call(self, inputs):
return self.dense(inputs)
return _SimpleMLP(num_labels)
Reported by Pylint.
Line: 193
Column: 3
def multi_input_output_model():
a = keras.layers.Input(shape=(3,), name='input_a')
b = keras.layers.Input(shape=(5,), name='input_b')
# TODO(anjalisridhar): Change the output dimension of the second Dense layer
# once the iterator output validation issue has been fixed.
dense_1 = keras.layers.Dense(7, name='dense_1')
dense_2 = keras.layers.Dense(7, name='dense_2')
c = dense_1(a)
d = dense_2(b)
Reported by Pylint.
Line: 462
Column: 3
verbose=0,
validation_data=(inputs, targets))
# TODO(anjalisridhar): We need tests for when the batch size and steps
# are smaller and results in a 0 batch_size and steps value.
model.evaluate(inputs, targets)
model.evaluate(inputs, targets, batch_size=8)
model.predict(inputs)
Reported by Pylint.
Line: 539
Column: 9
class MyLayer(keras.layers.Layer):
def build(self, _):
self.v1 = self.add_weight('v', ())
self.v2 = self.add_weight('v', ())
def call(self, inp):
inp += self.v1
return self.v2 + inp
Reported by Pylint.
Line: 540
Column: 9
def build(self, _):
self.v1 = self.add_weight('v', ())
self.v2 = self.add_weight('v', ())
def call(self, inp):
inp += self.v1
return self.v2 + inp
Reported by Pylint.
keras/engine/base_layer_test.py
1552 issues
Line: 16
Column: 1
# limitations under the License.
# ==============================================================================
"""Tests for TensorFlow 2.0 layer behavior."""
# pylint: disable=g-bad-import-order
import tensorflow.compat.v2 as tf
import copy
import os
Reported by Pylint.
Line: 17
Column: 1
# ==============================================================================
"""Tests for TensorFlow 2.0 layer behavior."""
# pylint: disable=g-bad-import-order
import tensorflow.compat.v2 as tf
import copy
import os
import numpy as np
Reported by Pylint.
Line: 325
Column: 5
self.assertEqual(get_learning_phase_value(), 0)
# Test scope.
with backend.learning_phase_scope(1):
self.assertEqual(get_learning_phase_value(), 1)
# The effects of the scope end after exiting it.
self.assertEqual(get_learning_phase_value(), 0)
Reported by Pylint.
Line: 1058
Column: 1
try:
_ = TypeErrorLayer()(inputs)
except TypeError as e:
self.assertIn('easily_identifiable_name', str(e)) # pylint: disable=g-assert-in-except
@combinations.generate(combinations.combine(mode=['graph', 'eager']))
def test_summaries_in_tf_function(self):
if not tf.executing_eagerly():
return
Reported by Pylint.
Line: 43
Column: 3
def __init__(self, dynamic=False, **kwargs):
super(DynamicLayer, self).__init__(dynamic=dynamic, **kwargs)
def call(self, inputs):
samples = tf.TensorArray(
dtype=tf.float32, size=tf.shape(inputs)[0])
for idx, sample in enumerate(inputs):
samples = samples.write(idx, tf.square(sample))
return samples.stack()
Reported by Pylint.
Line: 56
Column: 3
class InvalidLayer(base_layer.Layer):
def call(self, inputs):
raise ValueError('You did something wrong!')
class BaseLayerTest(keras_parameterized.TestCase):
Reported by Pylint.
Line: 65
Column: 21
@combinations.generate(combinations.keras_mode_combinations())
def test_layer_instrumentation(self):
layer = layers.Add()
self.assertTrue(layer._instrumented_keras_api)
self.assertTrue(layer._instrumented_keras_layer_class)
self.assertFalse(layer._instrumented_keras_model_class)
self.assertTrue(base_layer.keras_api_gauge.get_cell('tf.keras.layers.Add'))
# Verify this was not instrumented as a legacy layer
Reported by Pylint.
Line: 66
Column: 21
def test_layer_instrumentation(self):
layer = layers.Add()
self.assertTrue(layer._instrumented_keras_api)
self.assertTrue(layer._instrumented_keras_layer_class)
self.assertFalse(layer._instrumented_keras_model_class)
self.assertTrue(base_layer.keras_api_gauge.get_cell('tf.keras.layers.Add'))
# Verify this was not instrumented as a legacy layer
self.assertFalse(
Reported by Pylint.
Line: 67
Column: 22
layer = layers.Add()
self.assertTrue(layer._instrumented_keras_api)
self.assertTrue(layer._instrumented_keras_layer_class)
self.assertFalse(layer._instrumented_keras_model_class)
self.assertTrue(base_layer.keras_api_gauge.get_cell('tf.keras.layers.Add'))
# Verify this was not instrumented as a legacy layer
self.assertFalse(
base_layer.keras_api_gauge.get_cell('legacy_layer').value())
Reported by Pylint.
Line: 124
Column: 9
def build(self, input_shape):
self.build_counter += 1
self.build_shape = input_shape
def call(self, inputs):
return inputs
layer = BuildCounter(dtype=tf.float64)
Reported by Pylint.
keras/engine/base_layer.py
1448 issues
Line: 16
Column: 1
# limitations under the License.
# ==============================================================================
# pylint: disable=protected-access
# pylint: disable=g-classes-have-attributes
# pylint: disable=g-bad-import-order
"""Contains the base Layer class, from which all layers inherit."""
import tensorflow.compat.v2 as tf
Reported by Pylint.
Line: 17
Column: 1
# ==============================================================================
# pylint: disable=protected-access
# pylint: disable=g-classes-have-attributes
# pylint: disable=g-bad-import-order
"""Contains the base Layer class, from which all layers inherit."""
import tensorflow.compat.v2 as tf
import collections
Reported by Pylint.
Line: 20
Column: 1
# pylint: disable=g-bad-import-order
"""Contains the base Layer class, from which all layers inherit."""
import tensorflow.compat.v2 as tf
import collections
import copy
import functools
import itertools
Reported by Pylint.
Line: 33
Column: 1
import numpy as np
from google.protobuf import json_format
from keras import backend
from keras import constraints
from keras import initializers
from keras import regularizers
from keras.engine import base_layer_utils
Reported by Pylint.
Line: 56
Column: 1
# A module that only depends on `keras.layers` import these from here.
from keras.utils.generic_utils import to_snake_case # pylint: disable=unused-import
from keras.utils.tf_utils import is_tensor_or_tensor_list # pylint: disable=unused-import
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import get_canonical_name_for_symbol
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
# pylint: disable=g-inconsistent-quotes
Reported by Pylint.
Line: 57
Column: 1
from keras.utils.generic_utils import to_snake_case # pylint: disable=unused-import
from keras.utils.tf_utils import is_tensor_or_tensor_list # pylint: disable=unused-import
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import get_canonical_name_for_symbol
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
# pylint: disable=g-inconsistent-quotes
metrics_mod = generic_utils.LazyLoader(
Reported by Pylint.
Line: 58
Column: 1
from keras.utils.tf_utils import is_tensor_or_tensor_list # pylint: disable=unused-import
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import get_canonical_name_for_symbol
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
# pylint: disable=g-inconsistent-quotes
metrics_mod = generic_utils.LazyLoader(
"metrics_mod", globals(),
Reported by Pylint.
Line: 59
Column: 1
from tensorflow.python.platform import tf_logging
from tensorflow.python.util.tf_export import get_canonical_name_for_symbol
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
# pylint: disable=g-inconsistent-quotes
metrics_mod = generic_utils.LazyLoader(
"metrics_mod", globals(),
"keras.metrics")
Reported by Pylint.
Line: 61
Column: 1
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
# pylint: disable=g-inconsistent-quotes
metrics_mod = generic_utils.LazyLoader(
"metrics_mod", globals(),
"keras.metrics")
# pylint: enable=g-inconsistent-quotes
Reported by Pylint.
Line: 65
Column: 1
metrics_mod = generic_utils.LazyLoader(
"metrics_mod", globals(),
"keras.metrics")
# pylint: enable=g-inconsistent-quotes
# Prefix that is added to the TF op layer names.
_TF_OP_LAYER_NAME_PREFIX = 'tf_op_layer_'
# TODO(mdan): Should we have a single generic type for types that can be passed
Reported by Pylint.
keras/layers/recurrent_test.py
1417 issues
Line: 20
Column: 1
See also: lstm_test.py, gru_test.py, simplernn_test.py.
"""
import tensorflow.compat.v2 as tf
import collections
from absl.testing import parameterized
import numpy as np
Reported by Pylint.
Line: 24
Column: 1
import collections
from absl.testing import parameterized
import numpy as np
import keras
from keras import keras_parameterized
from keras import testing_utils
Reported by Pylint.
Line: 35
Column: 1
from keras.layers import recurrent_v2 as rnn_v2
from keras.layers.legacy_rnn import rnn_cell_impl
from keras.utils import generic_utils
from tensorflow.python.training.tracking import util as trackable_util
# Used for nested input/output/state RNN test.
NestedInput = collections.namedtuple('NestedInput', ['t1', 't2'])
NestedState = collections.namedtuple('NestedState', ['s1', 's2'])
Reported by Pylint.
Line: 140
Column: 9
super(MinimalRNNCell, self).__init__(**kwargs)
def build(self, input_shape):
self.kernel = self.add_weight(shape=(input_shape[-1], self.units),
initializer='uniform',
name='kernel')
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units),
initializer='uniform',
Reported by Pylint.
Line: 143
Column: 9
self.kernel = self.add_weight(shape=(input_shape[-1], self.units),
initializer='uniform',
name='kernel')
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units),
initializer='uniform',
name='recurrent_kernel')
self.built = True
Reported by Pylint.
Line: 149
Column: 7
name='recurrent_kernel')
self.built = True
def call(self, inputs, states):
prev_output = states[0]
h = keras.backend.dot(inputs, self.kernel)
output = h + keras.backend.dot(prev_output, self.recurrent_kernel)
return output, [output]
Reported by Pylint.
Line: 224
Column: 9
return self.units
def build(self, input_shape):
self.kernel = self.add_weight(shape=(input_shape[-1], self.units),
initializer='uniform',
name='kernel')
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units),
initializer='uniform',
Reported by Pylint.
Line: 227
Column: 9
self.kernel = self.add_weight(shape=(input_shape[-1], self.units),
initializer='uniform',
name='kernel')
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units),
initializer='uniform',
name='recurrent_kernel')
self.built = True
Reported by Pylint.
Line: 597
Column: 3
x[0, 0, 0] * cells[0].kernel)
update_2 = tf.compat.v1.assign_add(cells[0].kernel,
tf.ones_like(cells[0].kernel))
# TODO(b/128682878): Remove when RNNCells are __call__'d.
with base_layer_utils.call_context().enter(layer, x, True, None):
cells[0].add_update(update_1, inputs=x)
cells[0].add_update(update_2)
self.assertEqual(len(layer.updates), 2)
Reported by Pylint.
Line: 665
Column: 9
super(CustomRNNCell, self).__init__(**kwargs)
def build(self, input_shape):
self.kernel = self.add_weight(shape=(input_shape[-1], self.units),
initializer='uniform',
name='kernel')
self.recurrent_kernel = self.add_weight(
shape=(self.units, self.units),
initializer='uniform',
Reported by Pylint.