The following issues were found
keras/premade/wide_deep.py
97 issues
Line: 17
Column: 1
# ==============================================================================
"""Built-in WideNDeep model classes."""
import tensorflow.compat.v2 as tf
from keras import activations
from keras import backend
from keras import layers as layer_module
from keras.engine import base_layer
from keras.engine import data_adapter
Reported by Pylint.
Line: 25
Column: 1
from keras.engine import data_adapter
from keras.engine import training as keras_training
from keras.utils import generic_utils
from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import
from tensorflow.python.util.tf_export import keras_export
@keras_export(
'keras.experimental.WideDeepModel',
Reported by Pylint.
Line: 25
Column: 1
from keras.engine import data_adapter
from keras.engine import training as keras_training
from keras.utils import generic_utils
from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import
from tensorflow.python.util.tf_export import keras_export
@keras_export(
'keras.experimental.WideDeepModel',
Reported by Pylint.
Line: 26
Column: 1
from keras.engine import training as keras_training
from keras.utils import generic_utils
from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import
from tensorflow.python.util.tf_export import keras_export
@keras_export(
'keras.experimental.WideDeepModel',
v1=['keras.experimental.WideDeepModel', 'keras.models.WideDeepModel'])
Reported by Pylint.
Line: 92
Column: 3
self.dnn_model = dnn_model
self.activation = activations.get(activation)
def call(self, inputs, training=None):
if not isinstance(inputs, (tuple, list)) or len(inputs) != 2:
linear_inputs = dnn_inputs = inputs
else:
linear_inputs, dnn_inputs = inputs
linear_output = self.linear_model(linear_inputs)
Reported by Pylint.
Line: 34
Column: 1
v1=['keras.experimental.WideDeepModel', 'keras.models.WideDeepModel'])
@deprecation.deprecated_endpoints('keras.experimental.WideDeepModel')
class WideDeepModel(keras_training.Model):
r"""Wide & Deep Model for regression and classification problems.
This model jointly train a linear and a dnn model.
Example:
Reported by Pylint.
Line: 73
Column: 1
"""
def __init__(self, linear_model, dnn_model, activation=None, **kwargs):
"""Create a Wide & Deep Model.
Args:
linear_model: a premade LinearModel, its output must match the output of
the dnn model.
Reported by Pylint.
Line: 74
Column: 1
"""
def __init__(self, linear_model, dnn_model, activation=None, **kwargs):
"""Create a Wide & Deep Model.
Args:
linear_model: a premade LinearModel, its output must match the output of
the dnn model.
dnn_model: a `tf.keras.Model`, its output must match the output of the
Reported by Pylint.
Line: 86
Column: 1
**kwargs: The keyword arguments that are passed on to BaseLayer.__init__.
Allowed keyword arguments include `name`.
"""
super(WideDeepModel, self).__init__(**kwargs)
base_layer.keras_premade_model_gauge.get_cell('WideDeep').set(True)
self.linear_model = linear_model
self.dnn_model = dnn_model
self.activation = activations.get(activation)
Reported by Pylint.
Line: 86
Column: 5
**kwargs: The keyword arguments that are passed on to BaseLayer.__init__.
Allowed keyword arguments include `name`.
"""
super(WideDeepModel, self).__init__(**kwargs)
base_layer.keras_premade_model_gauge.get_cell('WideDeep').set(True)
self.linear_model = linear_model
self.dnn_model = dnn_model
self.activation = activations.get(activation)
Reported by Pylint.
keras/saving/saved_model/layer_serialization.py
97 issues
Line: 17
Column: 1
# ==============================================================================
"""Classes and functions implementing Layer SavedModel serialization."""
from keras.mixed_precision import policy
from keras.saving.saved_model import base_serialization
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
Reported by Pylint.
Line: 18
Column: 1
"""Classes and functions implementing Layer SavedModel serialization."""
from keras.mixed_precision import policy
from keras.saving.saved_model import base_serialization
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
import tensorflow.compat.v2 as tf
Reported by Pylint.
Line: 19
Column: 1
from keras.mixed_precision import policy
from keras.saving.saved_model import base_serialization
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
import tensorflow.compat.v2 as tf
Reported by Pylint.
Line: 20
Column: 1
from keras.mixed_precision import policy
from keras.saving.saved_model import base_serialization
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
import tensorflow.compat.v2 as tf
Reported by Pylint.
Line: 21
Column: 1
from keras.saving.saved_model import base_serialization
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
import tensorflow.compat.v2 as tf
class LayerSavedModelSaver(base_serialization.SavedModelSaver):
Reported by Pylint.
Line: 22
Column: 1
from keras.saving.saved_model import constants
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
import tensorflow.compat.v2 as tf
class LayerSavedModelSaver(base_serialization.SavedModelSaver):
"""Implements Layer SavedModel serialization."""
Reported by Pylint.
Line: 23
Column: 1
from keras.saving.saved_model import save_impl
from keras.saving.saved_model import serialized_attributes
from keras.utils import generic_utils
import tensorflow.compat.v2 as tf
class LayerSavedModelSaver(base_serialization.SavedModelSaver):
"""Implements Layer SavedModel serialization."""
Reported by Pylint.
Line: 35
Column: 3
@property
def python_properties(self):
# TODO(kathywu): Add python property validator
return self._python_properties_internal()
def _python_properties_internal(self):
"""Returns dictionary of all python properties."""
# TODO(kathywu): Add support for metrics serialization.
Reported by Pylint.
Line: 40
Column: 3
def _python_properties_internal(self):
"""Returns dictionary of all python properties."""
# TODO(kathywu): Add support for metrics serialization.
# TODO(kathywu): Synchronize with the keras spec (go/keras-json-spec) once
# the python config serialization has caught up.
metadata = dict(
name=self.obj.name,
trainable=self.obj.trainable,
Reported by Pylint.
Line: 41
Column: 3
def _python_properties_internal(self):
"""Returns dictionary of all python properties."""
# TODO(kathywu): Add support for metrics serialization.
# TODO(kathywu): Synchronize with the keras spec (go/keras-json-spec) once
# the python config serialization has caught up.
metadata = dict(
name=self.obj.name,
trainable=self.obj.trainable,
expects_training_arg=self.obj._expects_training_arg, # pylint: disable=protected-access
Reported by Pylint.
keras/saving/saved_model/serialized_attributes.py
96 issues
Line: 18
Column: 1
"""Helper classes that list&validate all attributes to serialize to SavedModel.
"""
from keras.saving.saved_model import constants
from keras.saving.saved_model import order_preserving_set as ops
from keras.saving.saved_model import save_impl
from keras.utils.generic_utils import LazyLoader
import tensorflow.compat.v2 as tf
Reported by Pylint.
Line: 19
Column: 1
"""
from keras.saving.saved_model import constants
from keras.saving.saved_model import order_preserving_set as ops
from keras.saving.saved_model import save_impl
from keras.utils.generic_utils import LazyLoader
import tensorflow.compat.v2 as tf
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
Reported by Pylint.
Line: 20
Column: 1
from keras.saving.saved_model import constants
from keras.saving.saved_model import order_preserving_set as ops
from keras.saving.saved_model import save_impl
from keras.utils.generic_utils import LazyLoader
import tensorflow.compat.v2 as tf
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
Reported by Pylint.
Line: 21
Column: 1
from keras.saving.saved_model import constants
from keras.saving.saved_model import order_preserving_set as ops
from keras.saving.saved_model import save_impl
from keras.utils.generic_utils import LazyLoader
import tensorflow.compat.v2 as tf
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
# pylint:disable=g-inconsistent-quotes
Reported by Pylint.
Line: 22
Column: 1
from keras.saving.saved_model import order_preserving_set as ops
from keras.saving.saved_model import save_impl
from keras.utils.generic_utils import LazyLoader
import tensorflow.compat.v2 as tf
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
# pylint:disable=g-inconsistent-quotes
base_layer = LazyLoader(
Reported by Pylint.
Line: 26
Column: 1
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
# pylint:disable=g-inconsistent-quotes
base_layer = LazyLoader(
"base_layer", globals(),
"keras.engine.base_layer")
training_lib = LazyLoader(
"training_lib", globals(),
Reported by Pylint.
Line: 38
Column: 1
recurrent = LazyLoader(
"recurrent", globals(),
"keras.layers.recurrent")
# pylint:enable=g-inconsistent-quotes
class SerializedAttributes:
"""Class that tracks and validates all serialization attributes.
Reported by Pylint.
Line: 196
Column: 16
def set_and_validate_functions(self, function_dict):
"""Saves function dictionary, and validates dictionary values."""
for key in self.all_functions:
if key in function_dict:
if (function_dict[key] is not None and # Not all functions are required
not isinstance(function_dict[key],
(tf.__internal__.function.Function,
tf.types.experimental.ConcreteFunction,
Reported by Pylint.
Line: 220
Column: 16
def set_and_validate_objects(self, object_dict):
"""Saves objects to a dictionary, and validates the values."""
for key in self.all_checkpointable_objects:
if key in object_dict:
if not isinstance(object_dict[key], tf.__internal__.tracking.Trackable):
raise ValueError(
'The object dictionary contained a non-trackable object: '
f'{object_dict[key]} (for key {key}). Only trackable objects are '
Reported by Pylint.
Line: 24
Column: 3
from keras.utils.generic_utils import LazyLoader
import tensorflow.compat.v2 as tf
# TODO(b/134426265): Switch back to single-quotes to match the rest of the file
# once the issue with copybara is fixed.
# pylint:disable=g-inconsistent-quotes
base_layer = LazyLoader(
"base_layer", globals(),
"keras.engine.base_layer")
Reported by Pylint.
keras/benchmarks/benchmark_util.py
95 issues
Line: 17
Column: 1
# ==============================================================================
"""Common utils for benchmarks."""
import tensorflow as tf
import timeit
import numpy as np
from keras.benchmarks import distribution_util
Reported by Pylint.
Line: 83
Column: 28
self.startup_time = timeit.default_timer()
self.recorded_startup = False
def on_epoch_begin(self, e, logs):
self.epoch_start_time = self.timer()
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
Reported by Pylint.
Line: 83
Column: 31
self.startup_time = timeit.default_timer()
self.recorded_startup = False
def on_epoch_begin(self, e, logs):
self.epoch_start_time = self.timer()
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
Reported by Pylint.
Line: 84
Column: 5
self.recorded_startup = False
def on_epoch_begin(self, e, logs):
self.epoch_start_time = self.timer()
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
def on_batch_end(self, e, logs):
Reported by Pylint.
Line: 86
Column: 26
def on_epoch_begin(self, e, logs):
self.epoch_start_time = self.timer()
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
def on_batch_end(self, e, logs):
if not self.recorded_startup:
self.startup_time = self.timer() - self.startup_time
Reported by Pylint.
Line: 86
Column: 29
def on_epoch_begin(self, e, logs):
self.epoch_start_time = self.timer()
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
def on_batch_end(self, e, logs):
if not self.recorded_startup:
self.startup_time = self.timer() - self.startup_time
Reported by Pylint.
Line: 89
Column: 26
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
def on_batch_end(self, e, logs):
if not self.recorded_startup:
self.startup_time = self.timer() - self.startup_time
self.recorded_startup = True
Reported by Pylint.
Line: 89
Column: 29
def on_epoch_end(self, e, logs):
self.times.append(self.timer() - self.epoch_start_time)
def on_batch_end(self, e, logs):
if not self.recorded_startup:
self.startup_time = self.timer() - self.startup_time
self.recorded_startup = True
Reported by Pylint.
Line: 151
Column: 3
if num_gpus < 0:
raise ValueError('`num_gpus` cannot be negative')
# TODO(xingyulong): we will add tfds support later and
# get the `num_examples` from info.
num_examples = x.shape[0]
build_time_list, compile_time_list, startup_time_list = [], [], []
avg_epoch_time_list, wall_time_list, exp_per_sec_list = [], [], []
Reported by Pylint.
Line: 19
Column: 1
import tensorflow as tf
import timeit
import numpy as np
from keras.benchmarks import distribution_util
Reported by Pylint.
keras/constraints.py
94 issues
Line: 16
Column: 1
# limitations under the License.
# ==============================================================================
# pylint: disable=invalid-name
# pylint: disable=g-classes-have-attributes
"""Constraints: functions that impose constraints on weight values."""
import tensorflow.compat.v2 as tf
from keras import backend
from keras.utils.generic_utils import deserialize_keras_object
Reported by Pylint.
Line: 19
Column: 1
# pylint: disable=g-classes-have-attributes
"""Constraints: functions that impose constraints on weight values."""
import tensorflow.compat.v2 as tf
from keras import backend
from keras.utils.generic_utils import deserialize_keras_object
from keras.utils.generic_utils import serialize_keras_object
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
Reported by Pylint.
Line: 23
Column: 1
from keras import backend
from keras.utils.generic_utils import deserialize_keras_object
from keras.utils.generic_utils import serialize_keras_object
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
@keras_export('keras.constraints.Constraint')
class Constraint:
Reported by Pylint.
Line: 24
Column: 1
from keras.utils.generic_utils import deserialize_keras_object
from keras.utils.generic_utils import serialize_keras_object
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
@keras_export('keras.constraints.Constraint')
class Constraint:
"""Base class for weight constraints.
Reported by Pylint.
Line: 283
Column: 1
kernel_new = backend.switch(
backend.cast(tf.math.floormod(kernel_shape, 2), 'bool'),
lambda: kernel[start - 1:start, start - 1:start],
lambda: kernel[start - 1:start, start - 1:start] + backend.zeros( # pylint: disable=g-long-lambda
(2, 2), dtype=kernel.dtype))
index = backend.switch(
backend.cast(tf.math.floormod(kernel_shape, 2), 'bool'),
lambda: backend.constant(0, dtype='int32'),
lambda: backend.constant(1, dtype='int32'))
Reported by Pylint.
Line: 265
Column: 3
height, width, channels, kernels = w_shape
w = backend.reshape(w, (height, width, channels * kernels))
# TODO(cpeter): Switch map_fn for a faster tf.vectorized_map once
# backend.switch is supported.
w = backend.map_fn(
self._kernel_constraint,
backend.stack(tf.unstack(w, axis=-1), axis=0))
return backend.reshape(backend.stack(tf.unstack(w, axis=0), axis=-1),
Reported by Pylint.
Line: 23
Column: 1
from keras import backend
from keras.utils.generic_utils import deserialize_keras_object
from keras.utils.generic_utils import serialize_keras_object
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
@keras_export('keras.constraints.Constraint')
class Constraint:
Reported by Pylint.
Line: 24
Column: 1
from keras.utils.generic_utils import deserialize_keras_object
from keras.utils.generic_utils import serialize_keras_object
from tensorflow.python.util.tf_export import keras_export
from tensorflow.tools.docs import doc_controls
@keras_export('keras.constraints.Constraint')
class Constraint:
"""Base class for weight constraints.
Reported by Pylint.
Line: 29
Column: 1
@keras_export('keras.constraints.Constraint')
class Constraint:
"""Base class for weight constraints.
A `Constraint` instance works like a stateless function.
Users who subclass this
class should override the `__call__` method, which takes a single
weight parameter and return a projected version of that parameter
Reported by Pylint.
Line: 52
Column: 1
>>> tf.keras.layers.Dense(4, kernel_constraint=NonNegative())
"""
def __call__(self, w):
"""Applies the constraint to the input weight variable.
By default, the inputs weight variable is not modified.
Users should override this method to implement their own projection
function.
Reported by Pylint.
keras/utils/traceback_utils.py
93 issues
Line: 22
Column: 1
import sys
import traceback
import types
import tensorflow.compat.v2 as tf
_EXCLUDED_PATHS = (
os.path.abspath(os.path.join(__file__, '..', '..')),
os.path.join('tensorflow', 'python'),
Reported by Pylint.
Line: 119
Column: 21
arguments_context = '\n'.join(arguments_context)
# Get original error message and append information to it.
if isinstance(e, tf.errors.OpError):
message = e.message
elif e.args:
# Canonically, the 1st argument in an exception is the error message.
# This works for all built-in Python exceptions.
message = e.args[0]
else:
Reported by Pylint.
Line: 134
Column: 58
# Reraise exception, with added context
if isinstance(e, tf.errors.OpError):
new_e = e.__class__(e.node_def, e.op, message, e.error_code)
else:
try:
# For standard exceptions such as ValueError, TypeError, etc.
new_e = e.__class__(message)
except TypeError:
Reported by Pylint.
Line: 134
Column: 31
# Reraise exception, with added context
if isinstance(e, tf.errors.OpError):
new_e = e.__class__(e.node_def, e.op, message, e.error_code)
else:
try:
# For standard exceptions such as ValueError, TypeError, etc.
new_e = e.__class__(message)
except TypeError:
Reported by Pylint.
Line: 134
Column: 43
# Reraise exception, with added context
if isinstance(e, tf.errors.OpError):
new_e = e.__class__(e.node_def, e.op, message, e.error_code)
else:
try:
# For standard exceptions such as ValueError, TypeError, etc.
new_e = e.__class__(message)
except TypeError:
Reported by Pylint.
Line: 103
Column: 9
bound_signature = signature.bind(*args, **kwargs)
except TypeError:
# Likely unbindable arguments
raise e
# Add argument context
arguments_context = []
for arg in list(signature.parameters.values()):
if arg.name in bound_signature.arguments:
Reported by Pylint.
Line: 31
Column: 1
)
def include_frame(fname):
for exclusion in _EXCLUDED_PATHS:
if exclusion in fname:
return False
return True
Reported by Pylint.
Line: 32
Column: 1
def include_frame(fname):
for exclusion in _EXCLUDED_PATHS:
if exclusion in fname:
return False
return True
Reported by Pylint.
Line: 33
Column: 1
def include_frame(fname):
for exclusion in _EXCLUDED_PATHS:
if exclusion in fname:
return False
return True
def _process_traceback_frames(tb):
Reported by Pylint.
Line: 34
Column: 1
def include_frame(fname):
for exclusion in _EXCLUDED_PATHS:
if exclusion in fname:
return False
return True
def _process_traceback_frames(tb):
"""Iterate through traceback frames and return a new, filtered traceback."""
Reported by Pylint.
keras/optimizer_v2/legacy_learning_rate_decay.py
92 issues
Line: 17
Column: 1
# ==============================================================================
"""Various learning rate decay functions."""
import tensorflow.compat.v2 as tf
import functools
from keras.optimizer_v2 import learning_rate_schedule
from tensorflow.python.util.tf_export import tf_export
Reported by Pylint.
Line: 20
Column: 1
import tensorflow.compat.v2 as tf
import functools
from keras.optimizer_v2 import learning_rate_schedule
from tensorflow.python.util.tf_export import tf_export
@tf_export(v1=["train.exponential_decay"])
def exponential_decay(learning_rate,
Reported by Pylint.
Line: 21
Column: 1
import functools
from keras.optimizer_v2 import learning_rate_schedule
from tensorflow.python.util.tf_export import tf_export
@tf_export(v1=["train.exponential_decay"])
def exponential_decay(learning_rate,
global_step,
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
import functools
from keras.optimizer_v2 import learning_rate_schedule
from tensorflow.python.util.tf_export import tf_export
@tf_export(v1=["train.exponential_decay"])
Reported by Pylint.
Line: 25
Column: 1
@tf_export(v1=["train.exponential_decay"])
def exponential_decay(learning_rate,
global_step,
decay_steps,
decay_rate,
staircase=False,
name=None):
Reported by Pylint.
Line: 31
Column: 1
decay_rate,
staircase=False,
name=None):
"""Applies exponential decay to the learning rate.
When training a model, it is often recommended to lower the learning rate as
the training progresses. This function applies an exponential decay function
to a provided initial learning rate. It requires a `global_step` value to
compute the decayed learning rate. You can just pass a TensorFlow variable
Reported by Pylint.
Line: 91
Column: 1
the learning rate value across different invocations of optimizer functions.
@end_compatibility
"""
decayed_lr = learning_rate_schedule.ExponentialDecay(
learning_rate, decay_steps, decay_rate, staircase=staircase, name=name)
if not tf.executing_eagerly():
decayed_lr = decayed_lr(global_step)
else:
decayed_lr = functools.partial(decayed_lr, global_step)
Reported by Pylint.
Line: 93
Column: 1
"""
decayed_lr = learning_rate_schedule.ExponentialDecay(
learning_rate, decay_steps, decay_rate, staircase=staircase, name=name)
if not tf.executing_eagerly():
decayed_lr = decayed_lr(global_step)
else:
decayed_lr = functools.partial(decayed_lr, global_step)
return decayed_lr
Reported by Pylint.
Line: 94
Column: 1
decayed_lr = learning_rate_schedule.ExponentialDecay(
learning_rate, decay_steps, decay_rate, staircase=staircase, name=name)
if not tf.executing_eagerly():
decayed_lr = decayed_lr(global_step)
else:
decayed_lr = functools.partial(decayed_lr, global_step)
return decayed_lr
Reported by Pylint.
Line: 95
Column: 1
learning_rate, decay_steps, decay_rate, staircase=staircase, name=name)
if not tf.executing_eagerly():
decayed_lr = decayed_lr(global_step)
else:
decayed_lr = functools.partial(decayed_lr, global_step)
return decayed_lr
@tf_export(v1=["train.piecewise_constant_decay", "train.piecewise_constant"])
Reported by Pylint.
keras/preprocessing/text_test.py
92 issues
Line: 18
Column: 1
# ==============================================================================
"""Tests for text data preprocessing utils."""
import tensorflow.compat.v2 as tf
import numpy as np
from keras.preprocessing import text as preprocessing_text
Reported by Pylint.
Line: 25
Column: 1
from keras.preprocessing import text as preprocessing_text
class TestText(tf.test.TestCase):
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
Reported by Pylint.
Line: 27
Column: 1
class TestText(tf.test.TestCase):
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
Reported by Pylint.
Line: 27
Column: 3
class TestText(tf.test.TestCase):
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
Reported by Pylint.
Line: 28
Column: 1
class TestText(tf.test.TestCase):
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
Reported by Pylint.
Line: 29
Column: 1
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
# Test on unicode.
Reported by Pylint.
Line: 30
Column: 1
def test_one_hot(self):
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
# Test on unicode.
text = u'The cat sat on the mat.'
Reported by Pylint.
Line: 31
Column: 1
text = 'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
# Test on unicode.
text = u'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
Reported by Pylint.
Line: 32
Column: 1
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
# Test on unicode.
text = u'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
Reported by Pylint.
Line: 35
Column: 1
self.assertGreaterEqual(np.min(encoded), 0)
# Test on unicode.
text = u'The cat sat on the mat.'
encoded = preprocessing_text.one_hot(text, 5)
self.assertEqual(len(encoded), 6)
self.assertLessEqual(np.max(encoded), 4)
self.assertGreaterEqual(np.min(encoded), 0)
Reported by Pylint.
keras/distribute/saved_model_save_load_test.py
91 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for saving and loading using tf's saved_model APIs with DS."""
import tensorflow.compat.v2 as tf
import os
from keras import testing_utils
from keras.distribute import model_combinations
from keras.distribute import saved_model_test_base as test_base
Reported by Pylint.
Line: 79
Column: 41
saved_dir = self.run_test_save_strategy(model_and_input, distribution,
save_in_scope)
func = tf.saved_model.load(saved_dir)
concrete_function = func.signatures[test_base._DEFAULT_FUNCTION_KEY]
for f in concrete_function.graph.as_graph_def().library.function:
for n in f.node_def:
if n.op == 'ReadVariableOp':
self.assertEmpty(n.device)
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
import os
from keras import testing_utils
from keras.distribute import model_combinations
from keras.distribute import saved_model_test_base as test_base
Reported by Pylint.
Line: 27
Column: 1
@testing_utils.run_all_without_tensor_float_32(
'Uses Dense layers, which call matmul')
class SavedModelKerasModelTest(test_base.TestSavedModelBase):
def setUp(self):
self._root_dir = 'saved_model_save_load'
super(SavedModelKerasModelTest, self).setUp()
Reported by Pylint.
Line: 29
Column: 1
'Uses Dense layers, which call matmul')
class SavedModelKerasModelTest(test_base.TestSavedModelBase):
def setUp(self):
self._root_dir = 'saved_model_save_load'
super(SavedModelKerasModelTest, self).setUp()
def _save_model(self, model, saved_dir):
tf.saved_model.save(model, saved_dir)
Reported by Pylint.
Line: 30
Column: 1
class SavedModelKerasModelTest(test_base.TestSavedModelBase):
def setUp(self):
self._root_dir = 'saved_model_save_load'
super(SavedModelKerasModelTest, self).setUp()
def _save_model(self, model, saved_dir):
tf.saved_model.save(model, saved_dir)
Reported by Pylint.
Line: 31
Column: 5
def setUp(self):
self._root_dir = 'saved_model_save_load'
super(SavedModelKerasModelTest, self).setUp()
def _save_model(self, model, saved_dir):
tf.saved_model.save(model, saved_dir)
def _load_and_run_model(self,
Reported by Pylint.
Line: 31
Column: 1
def setUp(self):
self._root_dir = 'saved_model_save_load'
super(SavedModelKerasModelTest, self).setUp()
def _save_model(self, model, saved_dir):
tf.saved_model.save(model, saved_dir)
def _load_and_run_model(self,
Reported by Pylint.
Line: 33
Column: 1
self._root_dir = 'saved_model_save_load'
super(SavedModelKerasModelTest, self).setUp()
def _save_model(self, model, saved_dir):
tf.saved_model.save(model, saved_dir)
def _load_and_run_model(self,
distribution,
saved_dir,
Reported by Pylint.
Line: 34
Column: 1
super(SavedModelKerasModelTest, self).setUp()
def _save_model(self, model, saved_dir):
tf.saved_model.save(model, saved_dir)
def _load_and_run_model(self,
distribution,
saved_dir,
predict_dataset,
Reported by Pylint.
keras/layers/preprocessing/benchmarks/image_preproc_benchmark.py
91 issues
Line: 17
Column: 1
# ==============================================================================
"""Benchmark for Keras image preprocessing layer."""
import tensorflow as tf
import functools
import time
import numpy as np
Reported by Pylint.
Line: 24
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import image_preprocessing
tf.compat.v1.enable_v2_behavior()
LOWER = .2
Reported by Pylint.
Line: 25
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import image_preprocessing
tf.compat.v1.enable_v2_behavior()
LOWER = .2
UPPER = .4
Reported by Pylint.
Line: 19
Column: 1
import tensorflow as tf
import functools
import time
import numpy as np
import keras
Reported by Pylint.
Line: 20
Column: 1
import tensorflow as tf
import functools
import time
import numpy as np
import keras
from keras.layers.preprocessing import image_preprocessing
Reported by Pylint.
Line: 35
Column: 1
def rotate(inputs):
"""rotate image."""
inputs_shape = tf.shape(inputs)
batch_size = inputs_shape[0]
img_hd = tf.cast(inputs_shape[1], tf.float32)
img_wd = tf.cast(inputs_shape[2], tf.float32)
min_angle = LOWER * 2. * np.pi
Reported by Pylint.
Line: 36
Column: 1
def rotate(inputs):
"""rotate image."""
inputs_shape = tf.shape(inputs)
batch_size = inputs_shape[0]
img_hd = tf.cast(inputs_shape[1], tf.float32)
img_wd = tf.cast(inputs_shape[2], tf.float32)
min_angle = LOWER * 2. * np.pi
max_angle = UPPER * 2. * np.pi
Reported by Pylint.
Line: 37
Column: 1
def rotate(inputs):
"""rotate image."""
inputs_shape = tf.shape(inputs)
batch_size = inputs_shape[0]
img_hd = tf.cast(inputs_shape[1], tf.float32)
img_wd = tf.cast(inputs_shape[2], tf.float32)
min_angle = LOWER * 2. * np.pi
max_angle = UPPER * 2. * np.pi
angles = tf.random.uniform(
Reported by Pylint.
Line: 38
Column: 1
"""rotate image."""
inputs_shape = tf.shape(inputs)
batch_size = inputs_shape[0]
img_hd = tf.cast(inputs_shape[1], tf.float32)
img_wd = tf.cast(inputs_shape[2], tf.float32)
min_angle = LOWER * 2. * np.pi
max_angle = UPPER * 2. * np.pi
angles = tf.random.uniform(
shape=[batch_size], minval=min_angle, maxval=max_angle)
Reported by Pylint.
Line: 39
Column: 1
inputs_shape = tf.shape(inputs)
batch_size = inputs_shape[0]
img_hd = tf.cast(inputs_shape[1], tf.float32)
img_wd = tf.cast(inputs_shape[2], tf.float32)
min_angle = LOWER * 2. * np.pi
max_angle = UPPER * 2. * np.pi
angles = tf.random.uniform(
shape=[batch_size], minval=min_angle, maxval=max_angle)
return image_preprocessing.transform(
Reported by Pylint.