The following issues were found
keras/layers/preprocessing/discretization.py
108 issues
Line: 17
Column: 1
# ==============================================================================
"""Keras discretization preprocessing layer."""
# pylint: disable=g-classes-have-attributes
# pylint: disable=g-direct-tensorflow-import
from keras.engine import base_preprocessing_layer
from keras.layers.preprocessing import preprocessing_utils as utils
from keras.utils import tf_utils
Reported by Pylint.
Line: 18
Column: 1
"""Keras discretization preprocessing layer."""
# pylint: disable=g-classes-have-attributes
# pylint: disable=g-direct-tensorflow-import
from keras.engine import base_preprocessing_layer
from keras.layers.preprocessing import preprocessing_utils as utils
from keras.utils import tf_utils
import numpy as np
Reported by Pylint.
Line: 24
Column: 1
from keras.layers.preprocessing import preprocessing_utils as utils
from keras.utils import tf_utils
import numpy as np
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
def summarize(values, epsilon):
Reported by Pylint.
Line: 25
Column: 1
from keras.utils import tf_utils
import numpy as np
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
def summarize(values, epsilon):
"""Reduce a 1D sequence of values to a summary.
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
def summarize(values, epsilon):
"""Reduce a 1D sequence of values to a summary.
Reported by Pylint.
Line: 213
Column: 1
name="summary",
shape=(2, None),
dtype=tf.float32,
initializer=lambda shape, dtype: [[], []], # pylint: disable=unused-arguments
trainable=False)
def update_state(self, data):
if self.input_bin_boundaries is not None:
raise ValueError(
Reported by Pylint.
Line: 79
Column: 3
A 2D `np.ndarray` that is a compressed summary. First column is the
interpolated partition values, the second is the weights (counts).
"""
# TODO(b/184863356): remove the numpy escape hatch here.
return tf.numpy_function(
lambda s: _compress_summary_numpy(s, epsilon), [summary], tf.float32)
def _compress_summary_numpy(summary, epsilon):
Reported by Pylint.
Line: 209
Column: 5
# Summary contains two equal length vectors of bins at index 0 and weights
# at index 1.
self.summary = self.add_weight(
name="summary",
shape=(2, None),
dtype=tf.float32,
initializer=lambda shape, dtype: [[], []], # pylint: disable=unused-arguments
trainable=False)
Reported by Pylint.
Line: 258
Column: 3
def compute_output_shape(self, input_shape):
return input_shape
def compute_output_signature(self, input_spec):
output_shape = self.compute_output_shape(input_spec.shape.as_list())
output_dtype = tf.int64
if isinstance(input_spec, tf.SparseTensorSpec):
return tf.SparseTensorSpec(
shape=output_shape, dtype=output_dtype)
Reported by Pylint.
Line: 266
Column: 3
shape=output_shape, dtype=output_dtype)
return tf.TensorSpec(shape=output_shape, dtype=output_dtype)
def call(self, inputs):
def bucketize(inputs):
outputs = tf.raw_ops.Bucketize(
input=inputs, boundaries=self.bin_boundaries)
# All other preprocessing layers use int64 for int output, so we conform
# here. Sadly the underlying op only supports int32, so we need to cast.
Reported by Pylint.
keras/engine/training_arrays_test.py
108 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for model.fit calls with a Dataset object passed as validation_data."""
import tensorflow.compat.v2 as tf
import io
import sys
from absl.testing import parameterized
Reported by Pylint.
Line: 22
Column: 1
import io
import sys
from absl.testing import parameterized
import numpy as np
import keras
from tensorflow.python.framework import test_util
from keras import keras_parameterized
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
import keras
from tensorflow.python.framework import test_util
from keras import keras_parameterized
from keras import testing_utils
from keras.layers import core
Reported by Pylint.
Line: 113
Column: 5
@keras_parameterized.run_all_keras_modes
def test_dict_float64_input(self):
class MyModel(keras.Model):
def __init__(self):
super(MyModel, self).__init__(self)
self.dense1 = keras.layers.Dense(10, activation="relu")
self.dense2 = keras.layers.Dense(10, activation="relu")
Reported by Pylint.
Line: 122
Column: 7
self.concat = keras.layers.Concatenate()
self.dense3 = keras.layers.Dense(1, activation="sigmoid")
def call(self, inputs):
d1 = self.dense1(inputs["one"])
d2 = self.dense2(inputs["two"])
concat = self.concat([d1, d2])
return self.dense3(concat)
Reported by Pylint.
Line: 153
Column: 5
input_0 = keras.Input(shape=(None,), name="input_0")
input_1 = keras.Input(shape=(None,), name="input_1")
class my_model(keras.Model):
def __init__(self):
super(my_model, self).__init__(self)
self.hidden_layer_0 = keras.layers.Dense(100, activation="relu")
self.hidden_layer_1 = keras.layers.Dense(100, activation="relu")
Reported by Pylint.
Line: 162
Column: 7
self.concat = keras.layers.Concatenate()
self.out_layer = keras.layers.Dense(1, activation="sigmoid")
def call(self, inputs=[input_0, input_1]):
activation_0 = self.hidden_layer_0(inputs["input_0"])
activation_1 = self.hidden_layer_1(inputs["input_1"])
concat = self.concat([activation_0, activation_1])
return self.out_layer(concat)
Reported by Pylint.
Line: 162
Column: 7
self.concat = keras.layers.Concatenate()
self.out_layer = keras.layers.Dense(1, activation="sigmoid")
def call(self, inputs=[input_0, input_1]):
activation_0 = self.hidden_layer_0(inputs["input_0"])
activation_1 = self.hidden_layer_1(inputs["input_1"])
concat = self.concat([activation_0, activation_1])
return self.out_layer(concat)
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
import io
import sys
from absl.testing import parameterized
import numpy as np
Reported by Pylint.
Line: 20
Column: 1
import tensorflow.compat.v2 as tf
import io
import sys
from absl.testing import parameterized
import numpy as np
import keras
Reported by Pylint.
keras/preprocessing/dataset_utils.py
106 issues
Line: 17
Column: 1
# ==============================================================================
"""Keras image dataset loading utilities."""
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
import multiprocessing
import os
Reported by Pylint.
Line: 18
Column: 1
"""Keras image dataset loading utilities."""
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
import multiprocessing
import os
import numpy as np
Reported by Pylint.
Line: 121
Column: 11
# Shuffle globally to erase macro-structure
if seed is None:
seed = np.random.randint(1e6)
rng = np.random.RandomState(seed)
rng.shuffle(file_paths)
rng = np.random.RandomState(seed)
rng.shuffle(labels)
return file_paths, labels, class_names
Reported by Pylint.
Line: 123
Column: 11
seed = np.random.randint(1e6)
rng = np.random.RandomState(seed)
rng.shuffle(file_paths)
rng = np.random.RandomState(seed)
rng.shuffle(labels)
return file_paths, labels, class_names
def iter_valid_files(directory, follow_links, formats):
Reported by Pylint.
Line: 20
Column: 1
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
import multiprocessing
import os
import numpy as np
Reported by Pylint.
Line: 21
Column: 1
# pylint: disable=g-classes-have-attributes
import multiprocessing
import os
import numpy as np
def index_directory(directory,
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
def index_directory(directory,
labels,
formats,
class_names=None,
shuffle=True,
seed=None,
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
def index_directory(directory,
labels,
formats,
class_names=None,
shuffle=True,
seed=None,
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
def index_directory(directory,
labels,
formats,
class_names=None,
shuffle=True,
seed=None,
Reported by Pylint.
Line: 33
Column: 1
shuffle=True,
seed=None,
follow_links=False):
"""Make list of all files in the subdirs of `directory`, with their labels.
Args:
directory: The target directory (string).
labels: Either "inferred"
(labels are generated from the directory structure),
Reported by Pylint.
keras/distribute/sharded_variable_test.py
105 issues
Line: 18
Column: 1
# ==============================================================================
"""Tests for ClusterCoordinator and Keras models."""
import tensorflow.compat.v2 as tf
import keras
from keras.distribute import multi_worker_testing_utils
from keras.engine import base_layer
Reported by Pylint.
Line: 73
Column: 46
layer.trainable_variables)
self.assert_list_all_equal(layer.weights, layer.variables)
checkpoint_deps = set(dep.ref for dep in layer._checkpoint_dependencies)
self.assertEqual(checkpoint_deps, set([layer.w, layer.b]))
def test_keras_layer_add_weight(self):
class Layer(base_layer.Layer):
Reported by Pylint.
Line: 106
Column: 46
layer.trainable_variables)
self.assert_list_all_equal(layer.weights, layer.variables)
checkpoint_deps = set(dep.ref for dep in layer._checkpoint_dependencies)
self.assertEqual(checkpoint_deps, set([layer.w, layer.b]))
def test_keras_metrics(self):
with self.strategy.scope():
fp = keras.metrics.FalsePositives(thresholds=[0.2, 0.5, 0.7, 0.8])
Reported by Pylint.
Line: 24
Column: 1
from keras.engine import base_layer
class ShardedVariableTest(tf.test.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
Reported by Pylint.
Line: 26
Column: 1
class ShardedVariableTest(tf.test.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
multi_worker_testing_utils.make_parameter_server_cluster(3, 2),
variable_partitioner=tf.distribute.experimental.partitioners.FixedShardsPartitioner(2))
Reported by Pylint.
Line: 27
Column: 3
class ShardedVariableTest(tf.test.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
multi_worker_testing_utils.make_parameter_server_cluster(3, 2),
variable_partitioner=tf.distribute.experimental.partitioners.FixedShardsPartitioner(2))
Reported by Pylint.
Line: 27
Column: 3
class ShardedVariableTest(tf.test.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
multi_worker_testing_utils.make_parameter_server_cluster(3, 2),
variable_partitioner=tf.distribute.experimental.partitioners.FixedShardsPartitioner(2))
Reported by Pylint.
Line: 27
Column: 1
class ShardedVariableTest(tf.test.TestCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
multi_worker_testing_utils.make_parameter_server_cluster(3, 2),
variable_partitioner=tf.distribute.experimental.partitioners.FixedShardsPartitioner(2))
Reported by Pylint.
Line: 28
Column: 1
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
multi_worker_testing_utils.make_parameter_server_cluster(3, 2),
variable_partitioner=tf.distribute.experimental.partitioners.FixedShardsPartitioner(2))
def assert_list_all_equal(self, list1, list2):
Reported by Pylint.
Line: 29
Column: 1
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.strategy = tf.distribute.experimental.ParameterServerStrategy(
multi_worker_testing_utils.make_parameter_server_cluster(3, 2),
variable_partitioner=tf.distribute.experimental.partitioners.FixedShardsPartitioner(2))
def assert_list_all_equal(self, list1, list2):
"""Used in lieu of `assertAllEqual`.
Reported by Pylint.
keras/integration_test/gradients_test.py
105 issues
Line: 17
Column: 1
# ==============================================================================
import numpy as np
import tensorflow as tf
class TestKerasModelClass(tf.keras.Model):
"""A simple tensorflow keras Model class definition."""
Reported by Pylint.
Line: 27
Column: 19
super(TestKerasModelClass, self).__init__()
self.width = width
def build(self, input_shape):
self.weight = self.add_weight(
name="test_keras_var",
shape=(self.width,),
dtype=tf.float32,
trainable=True,
Reported by Pylint.
Line: 28
Column: 5
self.width = width
def build(self, input_shape):
self.weight = self.add_weight(
name="test_keras_var",
shape=(self.width,),
dtype=tf.float32,
trainable=True,
)
Reported by Pylint.
Line: 116
Column: 23
super().__init__(**kwargs)
self.embedding = None
def build(self, input_shape):
self.embedding = tf.Variable(tf.random.uniform([50, 16]))
def call(self, x):
return tf.nn.embedding_lookup(self.embedding, x)
Reported by Pylint.
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.
Line: 21
Column: 1
class TestKerasModelClass(tf.keras.Model):
"""A simple tensorflow keras Model class definition."""
def __init__(self, width):
super(TestKerasModelClass, self).__init__()
self.width = width
Reported by Pylint.
Line: 23
Column: 1
class TestKerasModelClass(tf.keras.Model):
"""A simple tensorflow keras Model class definition."""
def __init__(self, width):
super(TestKerasModelClass, self).__init__()
self.width = width
def build(self, input_shape):
self.weight = self.add_weight(
Reported by Pylint.
Line: 24
Column: 5
"""A simple tensorflow keras Model class definition."""
def __init__(self, width):
super(TestKerasModelClass, self).__init__()
self.width = width
def build(self, input_shape):
self.weight = self.add_weight(
name="test_keras_var",
Reported by Pylint.
Line: 24
Column: 1
"""A simple tensorflow keras Model class definition."""
def __init__(self, width):
super(TestKerasModelClass, self).__init__()
self.width = width
def build(self, input_shape):
self.weight = self.add_weight(
name="test_keras_var",
Reported by Pylint.
Line: 25
Column: 1
def __init__(self, width):
super(TestKerasModelClass, self).__init__()
self.width = width
def build(self, input_shape):
self.weight = self.add_weight(
name="test_keras_var",
shape=(self.width,),
Reported by Pylint.
keras/saving/utils_v1/export_utils.py
104 issues
Line: 26
Column: 1
from keras.saving.utils_v1 import mode_keys
from keras.saving.utils_v1 import unexported_constants
from keras.saving.utils_v1.mode_keys import KerasModeKeys as ModeKeys
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging as logging
# Mapping of the modes to appropriate MetaGraph tags in the SavedModel.
Reported by Pylint.
Line: 28
Column: 1
from keras.saving.utils_v1.mode_keys import KerasModeKeys as ModeKeys
import tensorflow.compat.v2 as tf
from tensorflow.python.platform import tf_logging as logging
# Mapping of the modes to appropriate MetaGraph tags in the SavedModel.
EXPORT_TAG_MAP = mode_keys.ModeKeyMap(**{
ModeKeys.PREDICT: [tf.saved_model.SERVING],
Reported by Pylint.
Line: 159
Column: 3
for signature_name, sig in signature_def_map.items():
sig_names_by_method_name[sig.method_name].append(signature_name)
# TODO(b/67733540): consider printing the full signatures, not just names
for method_name, sig_names in sig_names_by_method_name.items():
if method_name in _FRIENDLY_METHOD_NAMES:
method_name = _FRIENDLY_METHOD_NAMES[method_name]
logging.info('Signatures INCLUDED in export for {}: {}'.format(
method_name, sig_names if sig_names else 'None'))
Reported by Pylint.
Line: 60
Column: 1
export_outputs,
receiver_tensors_alternatives=None,
serving_only=True):
"""Build `SignatureDef`s for all export outputs.
Args:
receiver_tensors: a `Tensor`, or a dict of string to `Tensor`, specifying
input nodes where this receiver expects to be fed by default. Typically,
this is a single placeholder expecting serialized `tf.Example` protos.
Reported by Pylint.
Line: 86
Column: 1
Raises:
ValueError: if export_outputs is not a dict
"""
if not isinstance(receiver_tensors, dict):
receiver_tensors = {SINGLE_RECEIVER_DEFAULT_NAME: receiver_tensors}
if export_outputs is None or not isinstance(export_outputs, dict):
raise ValueError('`export_outputs` must be a dict. Received '
f'{export_outputs} with type '
f'{type(export_outputs).__name__}.')
Reported by Pylint.
Line: 87
Column: 1
ValueError: if export_outputs is not a dict
"""
if not isinstance(receiver_tensors, dict):
receiver_tensors = {SINGLE_RECEIVER_DEFAULT_NAME: receiver_tensors}
if export_outputs is None or not isinstance(export_outputs, dict):
raise ValueError('`export_outputs` must be a dict. Received '
f'{export_outputs} with type '
f'{type(export_outputs).__name__}.')
Reported by Pylint.
Line: 88
Column: 1
"""
if not isinstance(receiver_tensors, dict):
receiver_tensors = {SINGLE_RECEIVER_DEFAULT_NAME: receiver_tensors}
if export_outputs is None or not isinstance(export_outputs, dict):
raise ValueError('`export_outputs` must be a dict. Received '
f'{export_outputs} with type '
f'{type(export_outputs).__name__}.')
signature_def_map = {}
Reported by Pylint.
Line: 89
Column: 1
if not isinstance(receiver_tensors, dict):
receiver_tensors = {SINGLE_RECEIVER_DEFAULT_NAME: receiver_tensors}
if export_outputs is None or not isinstance(export_outputs, dict):
raise ValueError('`export_outputs` must be a dict. Received '
f'{export_outputs} with type '
f'{type(export_outputs).__name__}.')
signature_def_map = {}
excluded_signatures = {}
Reported by Pylint.
Line: 93
Column: 1
f'{export_outputs} with type '
f'{type(export_outputs).__name__}.')
signature_def_map = {}
excluded_signatures = {}
for output_key, export_output in export_outputs.items():
signature_name = '{}'.format(output_key or 'None')
try:
signature = export_output.as_signature_def(receiver_tensors)
Reported by Pylint.
Line: 94
Column: 1
f'{type(export_outputs).__name__}.')
signature_def_map = {}
excluded_signatures = {}
for output_key, export_output in export_outputs.items():
signature_name = '{}'.format(output_key or 'None')
try:
signature = export_output.as_signature_def(receiver_tensors)
signature_def_map[signature_name] = signature
Reported by Pylint.
keras/tests/convert_to_constants_test.py
103 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for convert_to_constants.py."""
import tensorflow.compat.v2 as tf
import os
import numpy as np
Reported by Pylint.
Line: 23
Column: 1
import numpy as np
import keras
from tensorflow.python.framework import convert_to_constants
from keras import testing_utils
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
Reported by Pylint.
Line: 24
Column: 1
import numpy as np
import keras
from tensorflow.python.framework import convert_to_constants
from keras import testing_utils
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
Reported by Pylint.
Line: 25
Column: 1
import keras
from tensorflow.python.framework import convert_to_constants
from keras import testing_utils
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
class VariablesToConstantsTest(tf.test.TestCase):
Reported by Pylint.
Line: 26
Column: 1
import keras
from tensorflow.python.framework import convert_to_constants
from keras import testing_utils
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
class VariablesToConstantsTest(tf.test.TestCase):
Reported by Pylint.
Line: 27
Column: 1
from tensorflow.python.framework import convert_to_constants
from keras import testing_utils
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
class VariablesToConstantsTest(tf.test.TestCase):
def _freezeModel(self, model):
Reported by Pylint.
Line: 61
Column: 36
"""Returns the number of ReadVariableOp in the graph."""
return sum(node.op == "ReadVariableOp" for node in graph_def.node)
def _testConvertedFunction(self, obj, func, converted_concrete_func,
input_data):
# Ensure the converted graph has no variables and no function calls.
constant_graph_def = converted_concrete_func.graph.as_graph_def()
self.assertEqual(0, self._getNumVariables(constant_graph_def))
self.assertFalse(self._hasStatefulPartitionedCallOp(constant_graph_def))
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
import os
import numpy as np
import keras
from tensorflow.python.framework import convert_to_constants
Reported by Pylint.
Line: 26
Column: 1
import keras
from tensorflow.python.framework import convert_to_constants
from keras import testing_utils
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
class VariablesToConstantsTest(tf.test.TestCase):
Reported by Pylint.
Line: 30
Column: 1
from tensorflow.python.saved_model.save import save
class VariablesToConstantsTest(tf.test.TestCase):
def _freezeModel(self, model):
"""Freezes the model.
Args:
Reported by Pylint.
keras/tests/saver_test.py
101 issues
Line: 17
Column: 1
# =============================================================================
"""Tests for tensorflow.python.training.saver.py."""
import tensorflow.compat.v2 as tf
import functools
import os
from keras.engine import training
from keras.layers import core
Reported by Pylint.
Line: 21
Column: 1
import functools
import os
from keras.engine import training
from keras.layers import core
from tensorflow.python.training.tracking import util as trackable_utils
class NonLayerTrackable(tf.Module):
Reported by Pylint.
Line: 22
Column: 1
import functools
import os
from keras.engine import training
from keras.layers import core
from tensorflow.python.training.tracking import util as trackable_utils
class NonLayerTrackable(tf.Module):
Reported by Pylint.
Line: 23
Column: 1
import os
from keras.engine import training
from keras.layers import core
from tensorflow.python.training.tracking import util as trackable_utils
class NonLayerTrackable(tf.Module):
def __init__(self):
Reported by Pylint.
Line: 66
Column: 19
self.evaluate(train_op)
# A regular variable, a slot variable, and a non-slot Optimizer variable
# with known values to check when loading.
self.evaluate(model._named_dense.bias.assign([1.]))
self.evaluate(optimizer.get_slot(
var=model._named_dense.bias, name="m").assign([2.]))
beta1_power, _ = optimizer._get_beta_accumulators()
self.evaluate(beta1_power.assign(3.))
return root_trackable
Reported by Pylint.
Line: 68
Column: 13
# with known values to check when loading.
self.evaluate(model._named_dense.bias.assign([1.]))
self.evaluate(optimizer.get_slot(
var=model._named_dense.bias, name="m").assign([2.]))
beta1_power, _ = optimizer._get_beta_accumulators()
self.evaluate(beta1_power.assign(3.))
return root_trackable
def _set_sentinels(self, root_trackable):
Reported by Pylint.
Line: 69
Column: 22
self.evaluate(model._named_dense.bias.assign([1.]))
self.evaluate(optimizer.get_slot(
var=model._named_dense.bias, name="m").assign([2.]))
beta1_power, _ = optimizer._get_beta_accumulators()
self.evaluate(beta1_power.assign(3.))
return root_trackable
def _set_sentinels(self, root_trackable):
self.evaluate(root_trackable.model._named_dense.bias.assign([101.]))
Reported by Pylint.
Line: 74
Column: 19
return root_trackable
def _set_sentinels(self, root_trackable):
self.evaluate(root_trackable.model._named_dense.bias.assign([101.]))
self.evaluate(
root_trackable.optimizer.get_slot(
var=root_trackable.model._named_dense.bias, name="m")
.assign([102.]))
beta1_power, _ = root_trackable.optimizer._get_beta_accumulators()
Reported by Pylint.
Line: 77
Column: 17
self.evaluate(root_trackable.model._named_dense.bias.assign([101.]))
self.evaluate(
root_trackable.optimizer.get_slot(
var=root_trackable.model._named_dense.bias, name="m")
.assign([102.]))
beta1_power, _ = root_trackable.optimizer._get_beta_accumulators()
self.evaluate(beta1_power.assign(103.))
def _check_sentinels(self, root_trackable):
Reported by Pylint.
Line: 79
Column: 22
root_trackable.optimizer.get_slot(
var=root_trackable.model._named_dense.bias, name="m")
.assign([102.]))
beta1_power, _ = root_trackable.optimizer._get_beta_accumulators()
self.evaluate(beta1_power.assign(103.))
def _check_sentinels(self, root_trackable):
self.assertAllEqual(
[1.], self.evaluate(root_trackable.model._named_dense.bias))
Reported by Pylint.
keras/optimizer_v2/nadam.py
99 issues
Line: 17
Column: 1
# ==============================================================================
"""Nadam optimizer implementation."""
import tensorflow.compat.v2 as tf
from keras import backend_config
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import optimizer_v2
from tensorflow.python.util.tf_export import keras_export
Reported by Pylint.
Line: 18
Column: 1
"""Nadam optimizer implementation."""
import tensorflow.compat.v2 as tf
from keras import backend_config
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import optimizer_v2
from tensorflow.python.util.tf_export import keras_export
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
from keras import backend_config
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import optimizer_v2
from tensorflow.python.util.tf_export import keras_export
@keras_export('keras.optimizers.Nadam')
Reported by Pylint.
Line: 20
Column: 1
import tensorflow.compat.v2 as tf
from keras import backend_config
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import optimizer_v2
from tensorflow.python.util.tf_export import keras_export
@keras_export('keras.optimizers.Nadam')
class Nadam(optimizer_v2.OptimizerV2):
Reported by Pylint.
Line: 21
Column: 1
from keras import backend_config
from keras.optimizer_v2 import learning_rate_schedule
from keras.optimizer_v2 import optimizer_v2
from tensorflow.python.util.tf_export import keras_export
@keras_export('keras.optimizers.Nadam')
class Nadam(optimizer_v2.OptimizerV2):
r"""Optimizer that implements the NAdam algorithm.
Reported by Pylint.
Line: 138
Column: 5
def _prepare(self, var_list):
# Get the value of the momentum cache before starting to apply gradients.
self._m_cache_read = tf.identity(self._m_cache)
return super(Nadam, self)._prepare(var_list)
def _resource_apply_dense(self, grad, var, apply_state=None):
var_device, var_dtype = var.device, var.dtype.base_dtype
coefficients = ((apply_state or {}).get((var_device, var_dtype))
Reported by Pylint.
Line: 25
Column: 1
@keras_export('keras.optimizers.Nadam')
class Nadam(optimizer_v2.OptimizerV2):
r"""Optimizer that implements the NAdam algorithm.
Much like Adam is essentially RMSprop with momentum, Nadam is Adam with
Nesterov momentum.
Args:
Reported by Pylint.
Line: 26
Column: 1
@keras_export('keras.optimizers.Nadam')
class Nadam(optimizer_v2.OptimizerV2):
r"""Optimizer that implements the NAdam algorithm.
Much like Adam is essentially RMSprop with momentum, Nadam is Adam with
Nesterov momentum.
Args:
learning_rate: A Tensor or a floating point value. The learning rate.
Reported by Pylint.
Line: 56
Column: 1
- [Dozat, 2015](http://cs229.stanford.edu/proj2015/054_report.pdf).
"""
_HAS_AGGREGATE_GRAD = True
def __init__(self,
learning_rate=0.001,
beta_1=0.9,
beta_2=0.999,
Reported by Pylint.
Line: 58
Column: 3
_HAS_AGGREGATE_GRAD = True
def __init__(self,
learning_rate=0.001,
beta_1=0.9,
beta_2=0.999,
epsilon=1e-7,
name='Nadam',
Reported by Pylint.
keras/layers/preprocessing/category_encoding.py
99 issues
Line: 17
Column: 1
# ==============================================================================
"""Keras CategoryEncoding preprocessing layer."""
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
import numpy as np
from keras import backend
from keras.engine import base_layer
Reported by Pylint.
Line: 18
Column: 1
"""Keras CategoryEncoding preprocessing layer."""
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
import numpy as np
from keras import backend
from keras.engine import base_layer
from keras.engine import base_preprocessing_layer
Reported by Pylint.
Line: 26
Column: 1
from keras.engine import base_preprocessing_layer
from keras.utils import layer_utils
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
INT = "int"
ONE_HOT = "one_hot"
MULTI_HOT = "multi_hot"
Reported by Pylint.
Line: 27
Column: 1
from keras.utils import layer_utils
from keras.utils import tf_utils
from tensorflow.python.platform import tf_logging as logging
from tensorflow.python.util.tf_export import keras_export
INT = "int"
ONE_HOT = "one_hot"
MULTI_HOT = "multi_hot"
COUNT = "count"
Reported by Pylint.
Line: 159
Column: 3
else:
return tf.TensorShape(input_shape[:-1] + [self.num_tokens])
def compute_output_signature(self, input_spec):
output_shape = self.compute_output_shape(input_spec.shape.as_list())
if self.sparse:
return tf.SparseTensorSpec(
shape=output_shape, dtype=tf.int64)
else:
Reported by Pylint.
Line: 176
Column: 3
base_config = super(CategoryEncoding, self).get_config()
return dict(list(base_config.items()) + list(config.items()))
def call(self, inputs, count_weights=None):
if isinstance(inputs, (list, np.ndarray)):
inputs = tf.convert_to_tensor(inputs)
def expand_dims(inputs, axis):
if tf_utils.is_sparse(inputs):
Reported by Pylint.
Line: 195
Column: 3
if inputs.shape[-1] != 1:
inputs = expand_dims(inputs, -1)
# TODO(b/190445202): remove output rank restriction.
if inputs.shape.rank > 2:
raise ValueError(
"Received input shape {}, which would result in output rank {}. "
"Currently only outputs up to rank 2 are supported.".format(
original_shape, inputs.shape.rank))
Reported by Pylint.
Line: 38
Column: 1
@keras_export("keras.layers.CategoryEncoding",
"keras.layers.experimental.preprocessing.CategoryEncoding")
class CategoryEncoding(base_layer.Layer):
"""Category encoding layer.
This layer provides options for condensing data into a categorical encoding
when the total number of tokens are known in advance. It accepts integer
values as inputs, and it outputs a dense representation of those
inputs. For integer inputs where the total number of tokens is not known,
Reported by Pylint.
Line: 112
Column: 1
`"multi_hot"` or `"one_hot"` modes.
"""
def __init__(self,
num_tokens=None,
output_mode="multi_hot",
sparse=False,
**kwargs):
# max_tokens is an old name for the num_tokens arg we continue to support
Reported by Pylint.
Line: 119
Column: 1
**kwargs):
# max_tokens is an old name for the num_tokens arg we continue to support
# because of usage.
if "max_tokens" in kwargs:
logging.warning(
"max_tokens is deprecated, please use num_tokens instead.")
num_tokens = kwargs["max_tokens"]
del kwargs["max_tokens"]
Reported by Pylint.