Skip to content
This repository was archived by the owner on Jul 7, 2023. It is now read-only.

Commit 05c972a

Browse files
lgeigerafrozenator
authored andcommitted
Replace deprecated np.random.random_integers with np.random.randint (#1346)
1 parent 01d76fa commit 05c972a

21 files changed

+58
-58
lines changed

tensor2tensor/layers/common_layers_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ def testSaturatingSigmoid(self):
4848

4949
@tf.contrib.eager.run_test_in_graph_and_eager_modes()
5050
def testFlatten4D3D(self):
51-
x = np.random.random_integers(1, high=8, size=(3, 5, 2))
51+
x = np.random.randint(1, high=9, size=(3, 5, 2))
5252
y = common_layers.flatten4d3d(common_layers.embedding(x, 10, 7))
5353
self.evaluate(tf.global_variables_initializer())
5454
res = self.evaluate(y)
5555
self.assertEqual(res.shape, (3, 5 * 2, 7))
5656

5757
@tf.contrib.eager.run_test_in_graph_and_eager_modes()
5858
def testEmbedding(self):
59-
x = np.random.random_integers(1, high=8, size=(3, 5))
59+
x = np.random.randint(1, high=9, size=(3, 5))
6060
y = common_layers.embedding(x, 10, 16)
6161
self.evaluate(tf.global_variables_initializer())
6262
res = self.evaluate(y)

tensor2tensor/layers/modalities_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def testSymbolModalityInputs(self):
3939
model_hparams = common_hparams.basic_params1()
4040
model_hparams.hidden_size = hidden_size
4141
model_hparams.mode = tf.estimator.ModeKeys.TRAIN
42-
x = -1 + np.random.random_integers(
42+
x = np.random.randint(
4343
vocab_size, size=(batch_size, length, 1, 1))
4444
m = modalities.SymbolModality(model_hparams, vocab_size)
4545
data_parallelism = expert_utils.Parallelism(
@@ -62,9 +62,9 @@ def testSymbolModalityTargets(self):
6262
model_hparams = common_hparams.basic_params1()
6363
model_hparams.hidden_size = hidden_size
6464
model_hparams.mode = tf.estimator.ModeKeys.TRAIN
65-
body_output = -1 + np.random.random_integers(
65+
body_output = np.random.randint(
6666
100, size=(batch_size, length, height, hidden_size))
67-
targets = -1 + np.random.random_integers(
67+
targets = np.random.randint(
6868
vocab_size, size=(batch_size, length, height, 1))
6969
m = modalities.SymbolModality(model_hparams, vocab_size)
7070
data_parallelism = expert_utils.Parallelism(
@@ -92,9 +92,9 @@ def testSymbolModalityTargetsFactored(self):
9292
model_hparams.factored_logits = True
9393
model_hparams.hidden_size = hidden_size
9494
model_hparams.mode = tf.estimator.ModeKeys.TRAIN
95-
body_output = -1 + np.random.random_integers(
95+
body_output = np.random.randint(
9696
100, size=(batch_size, length, height, hidden_size))
97-
targets = -1 + np.random.random_integers(
97+
targets = np.random.randint(
9898
vocab_size, size=(batch_size, length, height, 1))
9999
m = modalities.SymbolModality(model_hparams, vocab_size)
100100
data_parallelism = expert_utils.Parallelism(

tensor2tensor/models/basic_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
class BasicTest(tf.test.TestCase):
3131

3232
def testBasicFcRelu(self):
33-
x = np.random.random_integers(0, high=255, size=(1, 28, 28, 1))
34-
y = np.random.random_integers(0, high=9, size=(1, 1))
33+
x = np.random.randint(256, size=(1, 28, 28, 1))
34+
y = np.random.randint(10, size=(1, 1))
3535
hparams = trainer_lib.create_hparams(
3636
"basic_fc_small", problem_name="image_mnist", data_dir=".")
3737
with self.test_session() as session:

tensor2tensor/models/bytenet_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class ByteNetTest(tf.test.TestCase):
3030

3131
def testByteNet(self):
3232
vocab_size = 9
33-
x = np.random.random_integers(1, high=vocab_size - 1, size=(3, 5, 1, 1))
34-
y = np.random.random_integers(1, high=vocab_size - 1, size=(3, 6, 1, 1))
33+
x = np.random.randint(1, high=vocab_size, size=(3, 5, 1, 1))
34+
y = np.random.randint(1, high=vocab_size, size=(3, 6, 1, 1))
3535
hparams = bytenet.bytenet_base()
3636
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
3737
vocab_size,

tensor2tensor/models/image_transformer_2d_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def _test_img2img_transformer(self, net):
3535
hparams = image_transformer_2d.img2img_transformer2d_tiny()
3636
hparams.data_dir = ""
3737
p_hparams = registry.problem("image_celeba").get_hparams(hparams)
38-
inputs = np.random.random_integers(0, high=255, size=(3, 4, 4, 3))
39-
targets = np.random.random_integers(0, high=255, size=(3, 8, 8, 3))
38+
inputs = np.random.randint(256, size=(3, 4, 4, 3))
39+
targets = np.random.randint(256, size=(3, 8, 8, 3))
4040
with self.test_session() as session:
4141
features = {
4242
"inputs": tf.constant(inputs, dtype=tf.int32),
@@ -63,9 +63,9 @@ def _test_imagetransformer_2d(self, net):
6363
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
6464
vocab_size,
6565
hparams)
66-
inputs = -1 + np.random.random_integers(
66+
inputs = np.random.randint(
6767
vocab_size, size=(batch_size, 1, 1, 1))
68-
targets = -1 + np.random.random_integers(
68+
targets = np.random.randint(
6969
vocab_size, size=(batch_size, size, size, 3))
7070
with self.test_session() as session:
7171
features = {

tensor2tensor/models/image_transformer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def testImagetransformer(self, net, hparams):
4646
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
4747
vocab_size,
4848
hparams)
49-
inputs = -1 + np.random.random_integers(
49+
inputs = np.random.randint(
5050
vocab_size, size=(batch_size, 1, 1, 1))
51-
targets = -1 + np.random.random_integers(
51+
targets = np.random.randint(
5252
vocab_size, size=(batch_size, size, size, 3))
5353
with self.test_session() as session:
5454
features = {

tensor2tensor/models/lstm_test.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ class LSTMTest(tf.test.TestCase):
3030

3131
def testLSTMSeq2Seq(self):
3232
vocab_size = 9
33-
x = np.random.random_integers(1, high=vocab_size - 1, size=(3, 5, 1, 1))
34-
y = np.random.random_integers(1, high=vocab_size - 1, size=(3, 6, 1, 1))
33+
x = np.random.randint(1, high=vocab_size, size=(3, 5, 1, 1))
34+
y = np.random.randint(1, high=vocab_size, size=(3, 6, 1, 1))
3535
hparams = lstm.lstm_seq2seq()
3636
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
3737
vocab_size,
@@ -50,8 +50,8 @@ def testLSTMSeq2Seq(self):
5050

5151
def testLSTMSeq2SeqAttention(self):
5252
vocab_size = 9
53-
x = np.random.random_integers(1, high=vocab_size - 1, size=(3, 5, 1, 1))
54-
y = np.random.random_integers(1, high=vocab_size - 1, size=(3, 6, 1, 1))
53+
x = np.random.randint(1, high=vocab_size, size=(3, 5, 1, 1))
54+
y = np.random.randint(1, high=vocab_size, size=(3, 6, 1, 1))
5555
hparams = lstm.lstm_attention()
5656

5757
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
@@ -74,8 +74,8 @@ def testLSTMSeq2SeqAttention(self):
7474

7575
def testLSTMSeq2seqBidirectionalEncoder(self):
7676
vocab_size = 9
77-
x = np.random.random_integers(1, high=vocab_size - 1, size=(3, 5, 1, 1))
78-
y = np.random.random_integers(1, high=vocab_size - 1, size=(3, 6, 1, 1))
77+
x = np.random.randint(1, high=vocab_size, size=(3, 5, 1, 1))
78+
y = np.random.randint(1, high=vocab_size, size=(3, 6, 1, 1))
7979
hparams = lstm.lstm_seq2seq()
8080
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
8181
vocab_size,
@@ -94,8 +94,8 @@ def testLSTMSeq2seqBidirectionalEncoder(self):
9494

9595
def testLSTMSeq2seqAttentionBidirectionalEncoder(self):
9696
vocab_size = 9
97-
x = np.random.random_integers(1, high=vocab_size - 1, size=(3, 5, 1, 1))
98-
y = np.random.random_integers(1, high=vocab_size - 1, size=(3, 6, 1, 1))
97+
x = np.random.randint(1, high=vocab_size, size=(3, 5, 1, 1))
98+
y = np.random.randint(1, high=vocab_size, size=(3, 6, 1, 1))
9999
hparams = lstm.lstm_attention()
100100

101101
p_hparams = problem_hparams.test_problem_hparams(vocab_size, vocab_size)

tensor2tensor/models/mtf_image_transformer_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_model(hparams=None,
4949
del p_hparams.modality["inputs"]
5050
hparams.problem_hparams = p_hparams
5151

52-
targets = -1 + np.random.random_integers(
52+
targets = np.random.randint(
5353
VOCAB_SIZE, size=(BATCH_SIZE, IMG_LENGTH, IMG_LENGTH, 1, 1))
5454
features = {
5555
"targets": tf.constant(targets, dtype=tf.int32, name="targets"),

tensor2tensor/models/mtf_transformer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def get_model(hparams=None, mode=tf.estimator.ModeKeys.TRAIN,
4848
del p_hparams.modality["inputs"]
4949
hparams.problem_hparams = p_hparams
5050

51-
inputs = -1 + np.random.random_integers(
51+
inputs = np.random.randint(
5252
VOCAB_SIZE, size=(BATCH_SIZE, INPUT_LENGTH, 1, 1))
53-
targets = -1 + np.random.random_integers(
53+
targets = np.random.randint(
5454
VOCAB_SIZE, size=(BATCH_SIZE, TARGET_LENGTH, 1, 1))
5555
features = {
5656
"targets": tf.constant(targets, dtype=tf.int32, name="targets"),

tensor2tensor/models/neural_gpu_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ def testNeuralGPU(self):
3939
p_hparams = problem_hparams.test_problem_hparams(input_vocab_size,
4040
target_vocab_size,
4141
hparams)
42-
inputs = -1 + np.random.random_integers(
42+
inputs = np.random.randint(
4343
input_vocab_size, size=(batch_size, input_length, 1, 1))
44-
targets = -1 + np.random.random_integers(
44+
targets = np.random.randint(
4545
target_vocab_size, size=(batch_size, target_length, 1, 1))
4646
with self.test_session() as session:
4747
features = {

tensor2tensor/models/research/autoencoders_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class AutoencoderTest(tf.test.TestCase):
3333
def get_mnist_random_output(self, model_name, hparams_set=None,
3434
mode=tf.estimator.ModeKeys.TRAIN):
3535
hparams_set = hparams_set or model_name
36-
x = np.random.random_integers(0, high=255, size=(1, 28, 28, 1))
37-
y = np.random.random_integers(0, high=9, size=(1, 1))
36+
x = np.random.randint(256, size=(1, 28, 28, 1))
37+
y = np.random.randint(10, size=(1, 1))
3838
features = {
3939
"targets": tf.constant(x, dtype=tf.int32),
4040
"inputs": tf.constant(y, dtype=tf.int32),

tensor2tensor/models/research/gene_expression_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def _test_model(self, hparams, model_cls):
4242
input_length = target_length * 128 // 4 # chunk_size=4
4343
input_vocab_size = 5
4444

45-
inputs = np.random.random_integers(
46-
input_vocab_size, size=(batch_size, input_length, 1, 1))
45+
inputs = np.random.randint(
46+
1, input_vocab_size + 1, size=(batch_size, input_length, 1, 1))
4747
targets = np.random.random_sample((batch_size, target_length, 1,
4848
target_out))
4949

tensor2tensor/models/research/transformer_aux_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ def test_transformer_aux_body(self):
9090
vocab_size,
9191
hparams)
9292
hparams.problem_hparams = p_hparams
93-
inputs = -1 + np.random.random_integers(
93+
inputs = np.random.randint(
9494
vocab_size, size=(batch_size, input_length, 1, 1))
95-
targets = -1 + np.random.random_integers(
95+
targets = np.random.randint(
9696
vocab_size, size=(batch_size, target_length, 1, 1))
9797
features = {
9898
"inputs": tf.constant(inputs, dtype=tf.int32),

tensor2tensor/models/research/transformer_revnet_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ def testTransformer(self):
4747
vocab_size,
4848
hparams)
4949
hparams.problem_hparams = p_hparams
50-
inputs = -1 + np.random.random_integers(
50+
inputs = np.random.randint(
5151
vocab_size, size=(batch_size, input_length, 1, 1))
52-
targets = -1 + np.random.random_integers(
52+
targets = np.random.randint(
5353
vocab_size, size=(batch_size, target_length, 1, 1))
5454
features = {
5555
"inputs": tf.constant(inputs, dtype=tf.int32),

tensor2tensor/models/research/transformer_vae_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def testTransformerAEOnDVQ(self):
3737
vocab_size,
3838
hparams)
3939
hparams.problem_hparams = p_hparams
40-
inputs = -1 + np.random.random_integers(
40+
inputs = np.random.randint(
4141
vocab_size, size=(batch_size, input_length, 1, 1))
42-
targets = -1 + np.random.random_integers(
42+
targets = np.random.randint(
4343
vocab_size, size=(batch_size, target_length, 1, 1))
4444
features = {
4545
"inputs": tf.constant(inputs, dtype=tf.int32),

tensor2tensor/models/research/universal_transformer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def get_model(self,
4848
del p_hparams.modality["inputs"]
4949
hparams.problems = [p_hparams]
5050

51-
inputs = -1 + np.random.random_integers(
51+
inputs = np.random.randint(
5252
VOCAB_SIZE, size=(BATCH_SIZE, INPUT_LENGTH, 1, 1))
53-
targets = -1 + np.random.random_integers(
53+
targets = np.random.randint(
5454
VOCAB_SIZE, size=(BATCH_SIZE, TARGET_LENGTH, 1, 1))
5555
features = {
5656
"targets": tf.constant(targets, dtype=tf.int32, name="targets"),

tensor2tensor/models/research/vqa_attention_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ def testVqaAttentionBaseline(self):
3939
question_length = 5
4040
answer_length = 10
4141
x = 2 * np.random.rand(batch_size, image_size, image_size, 3) - 1
42-
q = np.random.random_integers(
43-
1, high=vocab_size - 1, size=(batch_size, question_length, 1, 1))
44-
a = np.random.random_integers(
45-
0, high=num_classes, size=(batch_size, answer_length, 1, 1))
42+
q = np.random.randint(
43+
1, high=vocab_size, size=(batch_size, question_length, 1, 1))
44+
a = np.random.randint(
45+
num_classes + 1, size=(batch_size, answer_length, 1, 1))
4646
hparams = vqa_attention.vqa_attention_base()
4747
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
4848
vocab_size,

tensor2tensor/models/resnet_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ class ResnetTest(tf.test.TestCase):
4040
def _test_resnet(self, img_size, output_size):
4141
vocab_size = 9
4242
batch_size = 2
43-
x = np.random.random_integers(
44-
0, high=255, size=(batch_size, img_size, img_size, 3))
45-
y = np.random.random_integers(
46-
1, high=vocab_size - 1, size=(batch_size, 1, 1, 1))
43+
x = np.random.randint(
44+
256, size=(batch_size, img_size, img_size, 3))
45+
y = np.random.randint(
46+
1, high=vocab_size, size=(batch_size, 1, 1, 1))
4747
hparams = resnet_tiny_cpu()
4848
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
4949
vocab_size,

tensor2tensor/models/slicenet_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
class SliceNetTest(tf.test.TestCase):
3232

3333
def testSliceNet(self):
34-
x = np.random.random_integers(0, high=255, size=(3, 5, 5, 3))
35-
y = np.random.random_integers(0, high=9, size=(3, 5, 1, 1))
34+
x = np.random.randint(256, size=(3, 5, 5, 3))
35+
y = np.random.randint(10, size=(3, 5, 1, 1))
3636
hparams = slicenet.slicenet_params1_tiny()
3737
hparams.add_hparam("data_dir", "")
3838
problem = registry.problem("image_cifar10")

tensor2tensor/models/transformer_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def get_model(hparams=None, mode=tf.estimator.ModeKeys.TRAIN,
4848
del p_hparams.modality["inputs"]
4949
hparams.problem_hparams = p_hparams
5050

51-
inputs = -1 + np.random.random_integers(
51+
inputs = np.random.randint(
5252
VOCAB_SIZE, size=(BATCH_SIZE, INPUT_LENGTH, 1, 1))
53-
targets = -1 + np.random.random_integers(
53+
targets = np.random.randint(
5454
VOCAB_SIZE, size=(BATCH_SIZE, TARGET_LENGTH, 1, 1))
5555
features = {
5656
"targets": tf.constant(targets, dtype=tf.int32, name="targets"),

tensor2tensor/models/xception_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class XceptionTest(tf.test.TestCase):
3333
def _test_xception(self, img_size):
3434
vocab_size = 9
3535
batch_size = 3
36-
x = np.random.random_integers(
37-
0, high=255, size=(batch_size, img_size, img_size, 3))
38-
y = np.random.random_integers(
39-
1, high=vocab_size - 1, size=(batch_size, 1, 1, 1))
36+
x = np.random.randint(
37+
256, size=(batch_size, img_size, img_size, 3))
38+
y = np.random.randint(
39+
1, high=vocab_size, size=(batch_size, 1, 1, 1))
4040
hparams = xception.xception_tiny()
4141
p_hparams = problem_hparams.test_problem_hparams(vocab_size,
4242
vocab_size,

0 commit comments

Comments
 (0)