The following issues were found
keras/layers/embeddings.py
75 issues
Line: 17
Column: 1
# ==============================================================================
"""Embedding layer."""
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
from keras import backend
from keras import constraints
from keras import initializers
Reported by Pylint.
Line: 18
Column: 1
"""Embedding layer."""
import tensorflow.compat.v2 as tf
# pylint: disable=g-classes-have-attributes
from keras import backend
from keras import constraints
from keras import initializers
from keras import regularizers
Reported by Pylint.
Line: 27
Column: 1
from keras.engine import base_layer_utils
from keras.engine.base_layer import Layer
from keras.utils import tf_utils
from tensorflow.python.util.tf_export import keras_export
@keras_export('keras.layers.Embedding')
class Embedding(Layer):
"""Turns positive integers (indexes) into dense vectors of fixed size.
Reported by Pylint.
Line: 149
Column: 5
@tf_utils.shape_type_conversion
def build(self, input_shape=None):
self.embeddings = self.add_weight(
shape=(self.input_dim, self.output_dim),
initializer=self.embeddings_initializer,
name='embeddings',
regularizer=self.embeddings_regularizer,
constraint=self.embeddings_constraint,
Reported by Pylint.
Line: 187
Column: 3
in_lens[i] = s2
return (input_shape[0],) + tuple(in_lens) + (self.output_dim,)
def call(self, inputs):
dtype = backend.dtype(inputs)
if dtype != 'int32' and dtype != 'int64':
inputs = tf.cast(inputs, 'int32')
out = tf.nn.embedding_lookup(self.embeddings, inputs)
if self._dtype_policy.compute_dtype != self._dtype_policy.variable_dtype:
Reported by Pylint.
Line: 31
Column: 1
@keras_export('keras.layers.Embedding')
class Embedding(Layer):
"""Turns positive integers (indexes) into dense vectors of fixed size.
e.g. `[[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]`
This layer can only be used as the first layer in a model.
Reported by Pylint.
Line: 32
Column: 1
@keras_export('keras.layers.Embedding')
class Embedding(Layer):
"""Turns positive integers (indexes) into dense vectors of fixed size.
e.g. `[[4], [20]] -> [[0.25, 0.1], [0.6, -0.2]]`
This layer can only be used as the first layer in a model.
Reported by Pylint.
Line: 106
Column: 3
(e.g. `x = embedding_layer(x)`), or used in a subclassed model.
"""
def __init__(self,
input_dim,
output_dim,
embeddings_initializer='uniform',
embeddings_regularizer=None,
activity_regularizer=None,
Reported by Pylint.
Line: 106
Column: 1
(e.g. `x = embedding_layer(x)`), or used in a subclassed model.
"""
def __init__(self,
input_dim,
output_dim,
embeddings_initializer='uniform',
embeddings_regularizer=None,
activity_regularizer=None,
Reported by Pylint.
Line: 116
Column: 1
mask_zero=False,
input_length=None,
**kwargs):
if 'input_shape' not in kwargs:
if input_length:
kwargs['input_shape'] = (input_length,)
else:
kwargs['input_shape'] = (None,)
if input_dim <= 0 or output_dim <= 0:
Reported by Pylint.
keras/initializers/__init__.py
73 issues
Line: 17
Column: 1
# ==============================================================================
"""Keras initializer serialization / deserialization."""
import tensorflow.compat.v2 as tf
import threading
from tensorflow.python import tf2
from keras.initializers import initializers_v1
Reported by Pylint.
Line: 21
Column: 1
import threading
from tensorflow.python import tf2
from keras.initializers import initializers_v1
from keras.initializers import initializers_v2
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
Reported by Pylint.
Line: 26
Column: 1
from keras.initializers import initializers_v2
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
from tensorflow.python.util.tf_export import keras_export
# LOCAL.ALL_OBJECTS is meant to be a global mutable. Hence we need to make it
# thread-local to avoid concurrent mutations.
Reported by Pylint.
Line: 27
Column: 1
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
from tensorflow.python.util.tf_export import keras_export
# LOCAL.ALL_OBJECTS is meant to be a global mutable. Hence we need to make it
# thread-local to avoid concurrent mutations.
LOCAL = threading.local()
Reported by Pylint.
Line: 38
Column: 3
def populate_deserializable_objects():
"""Populates dict ALL_OBJECTS with every built-in initializer.
"""
global LOCAL
if not hasattr(LOCAL, 'ALL_OBJECTS'):
LOCAL.ALL_OBJECTS = {}
LOCAL.GENERATED_WITH_V2 = None
if LOCAL.ALL_OBJECTS and LOCAL.GENERATED_WITH_V2 == tf.__internal__.tf2.enabled():
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
import threading
from tensorflow.python import tf2
from keras.initializers import initializers_v1
from keras.initializers import initializers_v2
from keras.utils import generic_utils
Reported by Pylint.
Line: 26
Column: 1
from keras.initializers import initializers_v2
from keras.utils import generic_utils
from keras.utils import tf_inspect as inspect
from tensorflow.python.ops import init_ops
from tensorflow.python.util.tf_export import keras_export
# LOCAL.ALL_OBJECTS is meant to be a global mutable. Hence we need to make it
# thread-local to avoid concurrent mutations.
Reported by Pylint.
Line: 36
Column: 1
def populate_deserializable_objects():
"""Populates dict ALL_OBJECTS with every built-in initializer.
"""
global LOCAL
if not hasattr(LOCAL, 'ALL_OBJECTS'):
LOCAL.ALL_OBJECTS = {}
LOCAL.GENERATED_WITH_V2 = None
Reported by Pylint.
Line: 38
Column: 1
def populate_deserializable_objects():
"""Populates dict ALL_OBJECTS with every built-in initializer.
"""
global LOCAL
if not hasattr(LOCAL, 'ALL_OBJECTS'):
LOCAL.ALL_OBJECTS = {}
LOCAL.GENERATED_WITH_V2 = None
if LOCAL.ALL_OBJECTS and LOCAL.GENERATED_WITH_V2 == tf.__internal__.tf2.enabled():
Reported by Pylint.
Line: 39
Column: 1
"""Populates dict ALL_OBJECTS with every built-in initializer.
"""
global LOCAL
if not hasattr(LOCAL, 'ALL_OBJECTS'):
LOCAL.ALL_OBJECTS = {}
LOCAL.GENERATED_WITH_V2 = None
if LOCAL.ALL_OBJECTS and LOCAL.GENERATED_WITH_V2 == tf.__internal__.tf2.enabled():
# Objects dict is already generated for the proper TF version:
Reported by Pylint.
keras/layers/separable_convolutional_test.py
73 issues
Line: 17
Column: 1
# ==============================================================================
"""Tests for separable convolutional layers."""
import tensorflow.compat.v2 as tf
from absl.testing import parameterized
import numpy as np
import keras
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
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: 116
Column: 3
('padding_same_dilation_2', {'padding': 'same', 'dilation_rate': 2}),
('strides', {'strides': 2}),
# Only runs on GPU with CUDA, channels_first is not supported on CPU.
# TODO(b/62340061): Support channels_first on CPU.
('data_format', {'data_format': 'channels_first'}),
('dilation_rate', {'dilation_rate': 2}),
('depth_multiplier', {'depth_multiplier': 2}),
)
def test_separable_conv2d(self, kwargs):
Reported by Pylint.
Line: 28
Column: 1
@keras_parameterized.run_all_keras_modes
class SeparableConv1DTest(keras_parameterized.TestCase):
def _run_test(self, kwargs):
num_samples = 2
stack_size = 3
length = 7
Reported by Pylint.
Line: 30
Column: 1
@keras_parameterized.run_all_keras_modes
class SeparableConv1DTest(keras_parameterized.TestCase):
def _run_test(self, kwargs):
num_samples = 2
stack_size = 3
length = 7
with self.cached_session():
Reported by Pylint.
Line: 31
Column: 1
class SeparableConv1DTest(keras_parameterized.TestCase):
def _run_test(self, kwargs):
num_samples = 2
stack_size = 3
length = 7
with self.cached_session():
testing_utils.layer_test(
Reported by Pylint.
Line: 32
Column: 1
def _run_test(self, kwargs):
num_samples = 2
stack_size = 3
length = 7
with self.cached_session():
testing_utils.layer_test(
keras.layers.SeparableConv1D,
Reported by Pylint.
Line: 33
Column: 1
def _run_test(self, kwargs):
num_samples = 2
stack_size = 3
length = 7
with self.cached_session():
testing_utils.layer_test(
keras.layers.SeparableConv1D,
kwargs=kwargs,
Reported by Pylint.
Line: 35
Column: 1
stack_size = 3
length = 7
with self.cached_session():
testing_utils.layer_test(
keras.layers.SeparableConv1D,
kwargs=kwargs,
input_shape=(num_samples, length, stack_size))
Reported by Pylint.
Line: 36
Column: 1
length = 7
with self.cached_session():
testing_utils.layer_test(
keras.layers.SeparableConv1D,
kwargs=kwargs,
input_shape=(num_samples, length, stack_size))
@parameterized.named_parameters(
Reported by Pylint.
keras/layers/preprocessing/benchmarks/normalization_adapt_benchmark.py
72 issues
Line: 17
Column: 1
# ==============================================================================
"""Benchmark for Keras text vectorization preprocessing layer's adapt method."""
import tensorflow as tf
import time
import numpy as np
Reported by Pylint.
Line: 23
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import normalization
tf.compat.v1.enable_v2_behavior()
Reported by Pylint.
Line: 24
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import normalization
tf.compat.v1.enable_v2_behavior()
def reduce_fn(state, values):
Reported by Pylint.
Line: 19
Column: 1
import tensorflow as tf
import time
import numpy as np
import keras
from keras.layers.preprocessing import normalization
Reported by Pylint.
Line: 30
Column: 1
def reduce_fn(state, values):
"""tf.data.Dataset-friendly implementation of mean and variance."""
k, n, ex, ex2 = state
# If this is the first iteration, we pick the first value to be 'k',
# which helps with precision - we assume that k is close to an average
# value and calculate mean and variance with respect to that.
k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)
Reported by Pylint.
Line: 31
Column: 1
def reduce_fn(state, values):
"""tf.data.Dataset-friendly implementation of mean and variance."""
k, n, ex, ex2 = state
# If this is the first iteration, we pick the first value to be 'k',
# which helps with precision - we assume that k is close to an average
# value and calculate mean and variance with respect to that.
k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)
Reported by Pylint.
Line: 31
Column: 6
def reduce_fn(state, values):
"""tf.data.Dataset-friendly implementation of mean and variance."""
k, n, ex, ex2 = state
# If this is the first iteration, we pick the first value to be 'k',
# which helps with precision - we assume that k is close to an average
# value and calculate mean and variance with respect to that.
k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)
Reported by Pylint.
Line: 35
Column: 1
# If this is the first iteration, we pick the first value to be 'k',
# which helps with precision - we assume that k is close to an average
# value and calculate mean and variance with respect to that.
k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)
sum_v = tf.reduce_sum(values, axis=0)
sum_v2 = tf.reduce_sum(tf.square(values), axis=0)
ones = tf.ones_like(values, dtype=tf.int32)
batch_size = tf.reduce_sum(ones, axis=0)
Reported by Pylint.
Line: 37
Column: 1
# value and calculate mean and variance with respect to that.
k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)
sum_v = tf.reduce_sum(values, axis=0)
sum_v2 = tf.reduce_sum(tf.square(values), axis=0)
ones = tf.ones_like(values, dtype=tf.int32)
batch_size = tf.reduce_sum(ones, axis=0)
batch_size_f = tf.cast(batch_size, tf.float32)
Reported by Pylint.
Line: 38
Column: 1
k = tf.cond(tf.equal(n, 0), lambda: values[0], lambda: k)
sum_v = tf.reduce_sum(values, axis=0)
sum_v2 = tf.reduce_sum(tf.square(values), axis=0)
ones = tf.ones_like(values, dtype=tf.int32)
batch_size = tf.reduce_sum(ones, axis=0)
batch_size_f = tf.cast(batch_size, tf.float32)
ex = 0 + sum_v - tf.multiply(batch_size_f, k)
Reported by Pylint.
keras/layers/recurrent_v2_test.py
72 issues
Line: 20
Column: 1
See also: lstm_v2_test.py, gru_v2_test.py.
"""
import tensorflow.compat.v2 as tf
import os
from absl.testing import parameterized
import numpy as np
Reported by Pylint.
Line: 23
Column: 1
import tensorflow.compat.v2 as tf
import os
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: 116
Column: 9
def test_ragged(self, layer):
vocab_size = 100
inputs = tf.ragged.constant(
np.random.RandomState(0).randint(0, vocab_size, [128, 25]))
embedder = embeddings.Embedding(input_dim=vocab_size, output_dim=16)
embedded_inputs = embedder(inputs)
lstm = layer(32)
lstm(embedded_inputs)
Reported by Pylint.
Line: 22
Column: 1
import tensorflow.compat.v2 as tf
import os
from absl.testing import parameterized
import numpy as np
import keras
from keras import keras_parameterized
Reported by Pylint.
Line: 34
Column: 1
@keras_parameterized.run_all_keras_modes
class RNNV2Test(keras_parameterized.TestCase):
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
def test_device_placement(self, layer):
if not tf.test.is_gpu_available():
self.skipTest('Need GPU for testing.')
Reported by Pylint.
Line: 36
Column: 1
@keras_parameterized.run_all_keras_modes
class RNNV2Test(keras_parameterized.TestCase):
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
def test_device_placement(self, layer):
if not tf.test.is_gpu_available():
self.skipTest('Need GPU for testing.')
vocab_size = 20
embedding_dim = 10
Reported by Pylint.
Line: 37
Column: 1
class RNNV2Test(keras_parameterized.TestCase):
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
def test_device_placement(self, layer):
if not tf.test.is_gpu_available():
self.skipTest('Need GPU for testing.')
vocab_size = 20
embedding_dim = 10
batch_size = 8
Reported by Pylint.
Line: 37
Column: 3
class RNNV2Test(keras_parameterized.TestCase):
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
def test_device_placement(self, layer):
if not tf.test.is_gpu_available():
self.skipTest('Need GPU for testing.')
vocab_size = 20
embedding_dim = 10
batch_size = 8
Reported by Pylint.
Line: 38
Column: 1
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
def test_device_placement(self, layer):
if not tf.test.is_gpu_available():
self.skipTest('Need GPU for testing.')
vocab_size = 20
embedding_dim = 10
batch_size = 8
timestep = 12
Reported by Pylint.
Line: 39
Column: 1
@parameterized.parameters([rnn_v2.LSTM, rnn_v2.GRU])
def test_device_placement(self, layer):
if not tf.test.is_gpu_available():
self.skipTest('Need GPU for testing.')
vocab_size = 20
embedding_dim = 10
batch_size = 8
timestep = 12
units = 5
Reported by Pylint.
keras/distribute/simple_models.py
72 issues
Line: 17
Column: 1
# ==============================================================================
"""A simple functional keras model with one layer."""
import tensorflow.compat.v2 as tf
import numpy as np
import keras
from keras.distribute import model_collection_base
Reported by Pylint.
Line: 40
Column: 1
class SimpleFunctionalModel(model_collection_base.ModelAndInput):
"""A simple functional model and its inputs."""
def get_model(self, **kwargs):
output_name = 'output_1'
x = keras.layers.Input(shape=(3,), dtype=tf.float32)
y = keras.layers.Dense(5, dtype=tf.float32, name=output_name)(x)
Reported by Pylint.
Line: 65
Column: 1
class SimpleSequentialModel(model_collection_base.ModelAndInput):
"""A simple sequential model and its inputs."""
def get_model(self, **kwargs):
output_name = 'output_1'
model = keras.Sequential()
y = keras.layers.Dense(
5, dtype=tf.float32, name=output_name, input_dim=3)
Reported by Pylint.
Line: 87
Column: 1
return _BATCH_SIZE
class _SimpleModel(keras.Model):
def __init__(self):
super(_SimpleModel, self).__init__()
self._dense_layer = keras.layers.Dense(5, dtype=tf.float32)
Reported by Pylint.
Line: 93
Column: 3
super(_SimpleModel, self).__init__()
self._dense_layer = keras.layers.Dense(5, dtype=tf.float32)
def call(self, inputs):
return self._dense_layer(inputs)
class SimpleSubclassModel(model_collection_base.ModelAndInput):
"""A simple subclass model and its data."""
Reported by Pylint.
Line: 100
Column: 1
class SimpleSubclassModel(model_collection_base.ModelAndInput):
"""A simple subclass model and its data."""
def get_model(self, **kwargs):
model = _SimpleModel()
optimizer = gradient_descent.SGD(learning_rate=0.001)
model.compile(
loss='mse',
metrics=['mae'],
Reported by Pylint.
Line: 131
Column: 1
class SimpleTFModuleModel(model_collection_base.ModelAndInput):
"""A simple model based on tf.Module and its data."""
def get_model(self, **kwargs):
model = _SimpleModule()
return model
def get_data(self):
return _get_data_for_simple_models()
Reported by Pylint.
Line: 29
Column: 1
def _get_data_for_simple_models():
x_train = tf.constant(np.random.rand(1000, 3), dtype=tf.float32)
y_train = tf.constant(np.random.rand(1000, 5), dtype=tf.float32)
x_predict = tf.constant(
np.random.rand(1000, 3), dtype=tf.float32)
return x_train, y_train, x_predict
Reported by Pylint.
Line: 30
Column: 1
def _get_data_for_simple_models():
x_train = tf.constant(np.random.rand(1000, 3), dtype=tf.float32)
y_train = tf.constant(np.random.rand(1000, 5), dtype=tf.float32)
x_predict = tf.constant(
np.random.rand(1000, 3), dtype=tf.float32)
return x_train, y_train, x_predict
Reported by Pylint.
Line: 31
Column: 1
def _get_data_for_simple_models():
x_train = tf.constant(np.random.rand(1000, 3), dtype=tf.float32)
y_train = tf.constant(np.random.rand(1000, 5), dtype=tf.float32)
x_predict = tf.constant(
np.random.rand(1000, 3), dtype=tf.float32)
return x_train, y_train, x_predict
Reported by Pylint.
keras/layers/preprocessing/benchmarks/index_lookup_adapt_benchmark.py
71 issues
Line: 17
Column: 1
# ==============================================================================
"""Benchmark for Keras text vectorization preprocessing layer's adapt method."""
import tensorflow as tf
import collections
import itertools
import random
import string
Reported by Pylint.
Line: 27
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import index_lookup
tf.compat.v1.enable_v2_behavior()
Reported by Pylint.
Line: 28
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import index_lookup
tf.compat.v1.enable_v2_behavior()
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
Reported by Pylint.
Line: 19
Column: 1
import tensorflow as tf
import collections
import itertools
import random
import string
import time
Reported by Pylint.
Line: 20
Column: 1
import tensorflow as tf
import collections
import itertools
import random
import string
import time
import numpy as np
Reported by Pylint.
Line: 21
Column: 1
import collections
import itertools
import random
import string
import time
import numpy as np
Reported by Pylint.
Line: 22
Column: 1
import collections
import itertools
import random
import string
import time
import numpy as np
import keras
Reported by Pylint.
Line: 23
Column: 1
import itertools
import random
import string
import time
import numpy as np
import keras
from keras.layers.preprocessing import index_lookup
Reported by Pylint.
Line: 35
Column: 1
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
for _ in itertools.count(1):
yield "".join(random.choice(string.ascii_letters) for i in range(2))
def get_top_k(dataset, k):
Reported by Pylint.
Line: 36
Column: 1
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
for _ in itertools.count(1):
yield "".join(random.choice(string.ascii_letters) for i in range(2))
def get_top_k(dataset, k):
"""Python implementation of vocabulary building using a defaultdict."""
Reported by Pylint.
keras/utils/kpl_test_utils.py
71 issues
Line: 17
Column: 1
# ==============================================================================
"""Test related utilities for KPL + tf.distribute."""
import tensorflow.compat.v2 as tf
import random
import tempfile
import keras
Reported by Pylint.
Line: 104
Column: 1
"label": tf.TensorSpec([1], tf.string)
}).shuffle(100).batch(32)
train_dataset = raw_dataset.map(lambda x: ( # pylint: disable=g-long-lambda
{
"features": feature_mapper(x["features"])
}, label_mapper(x["label"])))
return train_dataset
Reported by Pylint.
Line: 19
Column: 1
import tensorflow.compat.v2 as tf
import random
import tempfile
import keras
from keras.layers.preprocessing import string_lookup
Reported by Pylint.
Line: 20
Column: 1
import tensorflow.compat.v2 as tf
import random
import tempfile
import keras
from keras.layers.preprocessing import string_lookup
Reported by Pylint.
Line: 27
Column: 1
class DistributeKplTestUtils(tf.test.TestCase):
"""Utils for test of tf.distribute + KPL."""
FEATURE_VOCAB = [
"avenger", "ironman", "batman", "hulk", "spiderman", "kingkong",
"wonder_woman"
]
LABEL_VOCAB = ["yes", "no"]
Reported by Pylint.
Line: 28
Column: 1
class DistributeKplTestUtils(tf.test.TestCase):
"""Utils for test of tf.distribute + KPL."""
FEATURE_VOCAB = [
"avenger", "ironman", "batman", "hulk", "spiderman", "kingkong",
"wonder_woman"
]
LABEL_VOCAB = ["yes", "no"]
Reported by Pylint.
Line: 32
Column: 1
"avenger", "ironman", "batman", "hulk", "spiderman", "kingkong",
"wonder_woman"
]
LABEL_VOCAB = ["yes", "no"]
def define_kpls_for_training(self, use_adapt):
"""Function that defines KPL used for unit tests of tf.distribute.
Args:
Reported by Pylint.
Line: 34
Column: 1
]
LABEL_VOCAB = ["yes", "no"]
def define_kpls_for_training(self, use_adapt):
"""Function that defines KPL used for unit tests of tf.distribute.
Args:
use_adapt: if adapt will be called. False means there will be precomputed
statistics.
Reported by Pylint.
Line: 35
Column: 1
LABEL_VOCAB = ["yes", "no"]
def define_kpls_for_training(self, use_adapt):
"""Function that defines KPL used for unit tests of tf.distribute.
Args:
use_adapt: if adapt will be called. False means there will be precomputed
statistics.
Reported by Pylint.
Line: 47
Column: 1
label_mapper: similar to feature_mapper, but maps label to index.
"""
if use_adapt:
feature_lookup_layer = (
string_lookup.StringLookup(
num_oov_indices=1))
feature_lookup_layer.adapt(self.FEATURE_VOCAB)
label_lookup_layer = (
Reported by Pylint.
keras/layers/preprocessing/benchmarks/hashing_benchmark.py
70 issues
Line: 17
Column: 1
# ==============================================================================
"""Benchmark for Keras hashing preprocessing layer."""
import tensorflow as tf
import itertools
import random
import string
import time
Reported by Pylint.
Line: 26
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import hashing
tf.compat.v1.enable_v2_behavior()
Reported by Pylint.
Line: 27
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import hashing
tf.compat.v1.enable_v2_behavior()
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
Reported by Pylint.
Line: 19
Column: 1
import tensorflow as tf
import itertools
import random
import string
import time
import numpy as np
Reported by Pylint.
Line: 20
Column: 1
import tensorflow as tf
import itertools
import random
import string
import time
import numpy as np
Reported by Pylint.
Line: 21
Column: 1
import itertools
import random
import string
import time
import numpy as np
import keras
Reported by Pylint.
Line: 22
Column: 1
import itertools
import random
import string
import time
import numpy as np
import keras
from keras.layers.preprocessing import hashing
Reported by Pylint.
Line: 34
Column: 1
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
for _ in itertools.count(1):
yield "".join(random.choice(string.ascii_letters) for i in range(2))
class BenchmarkLayer(tf.test.Benchmark):
Reported by Pylint.
Line: 35
Column: 1
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def word_gen():
for _ in itertools.count(1):
yield "".join(random.choice(string.ascii_letters) for i in range(2))
class BenchmarkLayer(tf.test.Benchmark):
"""Benchmark the layer forward pass."""
Reported by Pylint.
Line: 36
Column: 1
# The number of unique strings is ~2,700.
def word_gen():
for _ in itertools.count(1):
yield "".join(random.choice(string.ascii_letters) for i in range(2))
class BenchmarkLayer(tf.test.Benchmark):
"""Benchmark the layer forward pass."""
Reported by Pylint.
keras/layers/preprocessing/benchmarks/category_crossing_benchmark.py
69 issues
Line: 17
Column: 1
# ==============================================================================
"""Benchmark for Keras categorical_encoding preprocessing layer."""
import tensorflow as tf
import itertools
import time
import numpy as np
Reported by Pylint.
Line: 24
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import category_crossing
tf.compat.v1.enable_v2_behavior()
Reported by Pylint.
Line: 25
Column: 1
import numpy as np
import keras
from keras.layers.preprocessing import category_crossing
tf.compat.v1.enable_v2_behavior()
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
Reported by Pylint.
Line: 19
Column: 1
import tensorflow as tf
import itertools
import time
import numpy as np
import keras
Reported by Pylint.
Line: 20
Column: 1
import tensorflow as tf
import itertools
import time
import numpy as np
import keras
from keras.layers.preprocessing import category_crossing
Reported by Pylint.
Line: 32
Column: 1
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def int_gen():
for _ in itertools.count(1):
yield (np.random.randint(0, 5, (1,)), np.random.randint(0, 7, (1,)))
class BenchmarkLayer(tf.test.Benchmark):
Reported by Pylint.
Line: 33
Column: 1
# word_gen creates random sequences of ASCII letters (both lowercase and upper).
# The number of unique strings is ~2,700.
def int_gen():
for _ in itertools.count(1):
yield (np.random.randint(0, 5, (1,)), np.random.randint(0, 7, (1,)))
class BenchmarkLayer(tf.test.Benchmark):
"""Benchmark the layer forward pass."""
Reported by Pylint.
Line: 34
Column: 1
# The number of unique strings is ~2,700.
def int_gen():
for _ in itertools.count(1):
yield (np.random.randint(0, 5, (1,)), np.random.randint(0, 7, (1,)))
class BenchmarkLayer(tf.test.Benchmark):
"""Benchmark the layer forward pass."""
Reported by Pylint.
Line: 38
Column: 1
class BenchmarkLayer(tf.test.Benchmark):
"""Benchmark the layer forward pass."""
def run_dataset_implementation(self, batch_size):
num_repeats = 5
starts = []
ends = []
Reported by Pylint.
Line: 40
Column: 3
class BenchmarkLayer(tf.test.Benchmark):
"""Benchmark the layer forward pass."""
def run_dataset_implementation(self, batch_size):
num_repeats = 5
starts = []
ends = []
for _ in range(num_repeats):
ds = tf.data.Dataset.from_generator(
Reported by Pylint.