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

Commit 8107e53

Browse files
committed
Changes needed for T2T's problems to be imported on TF 2.0 -- this doesn't mean we are using these problems.
This is only so that we can `import trax` on these environments. PiperOrigin-RevId: 282108974
1 parent 313fdfc commit 8107e53

22 files changed

+67
-69
lines changed

setup.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='tensor2tensor',
8-
version='1.15.1',
8+
version='1.15.2',
99
description='Tensor2Tensor',
1010
long_description=(
1111
'Tensor2Tensor, or T2T for short, is a library of '
@@ -66,7 +66,6 @@
6666
'tensorflow-datasets',
6767
'tensorflow-gan',
6868
'tensorflow-probability==0.7.0',
69-
'tf_slim',
7069
'tqdm',
7170
],
7271
extras_require={

tensor2tensor/data_generators/allen_brain.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
from tensor2tensor.utils import registry
4545

4646
import tensorflow as tf
47-
import tf_slim as slim
4847

4948
_BASE_EXAMPLE_IMAGE_SIZE = 64
5049

@@ -351,7 +350,7 @@ def example_reading_spec(self):
351350

352351
data_items_to_decoders = {
353352
"targets":
354-
slim.tfexample_decoder.Image(
353+
tf.contrib.slim.tfexample_decoder.Image(
355354
image_key="image/encoded",
356355
format_key="image/format",
357356
channels=self.num_channels),

tensor2tensor/data_generators/bair_robot_pushing.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from tensor2tensor.utils import registry
3737

3838
import tensorflow as tf
39-
import tf_slim as slim
4039

4140
DATA_URL = (
4241
"http://rail.eecs.berkeley.edu/datasets/bair_robot_pushing_dataset_v0.tar")
@@ -103,7 +102,7 @@ def extra_reading_spec(self):
103102
"frame_number": tf.FixedLenFeature([1], tf.int64),
104103
}
105104
decoders = {
106-
"frame_number": slim.tfexample_decoder.Tensor(
105+
"frame_number": tf.contrib.slim.tfexample_decoder.Tensor(
107106
tensor_key="frame_number"),
108107
}
109108
return data_fields, decoders
@@ -188,9 +187,9 @@ def extra_reading_spec(self):
188187
"action": tf.FixedLenFeature([4], tf.float32),
189188
}
190189
decoders = {
191-
"frame_number": slim.tfexample_decoder.Tensor(
190+
"frame_number": tf.contrib.slim.tfexample_decoder.Tensor(
192191
tensor_key="frame_number"),
193-
"action": slim.tfexample_decoder.Tensor(tensor_key="action"),
192+
"action": tf.contrib.slim.tfexample_decoder.Tensor(tensor_key="action"),
194193
}
195194
return data_fields, decoders
196195

tensor2tensor/data_generators/fsns.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from tensor2tensor.utils import registry
2929

3030
import tensorflow as tf
31-
import tf_slim as slim
3231

3332

3433
@registry.register_problem
@@ -77,5 +76,5 @@ def example_reading_spec(self):
7776
super(ImageFSNS, self).example_reading_spec())
7877
data_fields[label_key] = tf.VarLenFeature(tf.int64)
7978
data_items_to_decoders[
80-
"targets"] = slim.tfexample_decoder.Tensor(label_key)
79+
"targets"] = tf.contrib.slim.tfexample_decoder.Tensor(label_key)
8180
return data_fields, data_items_to_decoders

tensor2tensor/data_generators/gym_env.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
from tensor2tensor.utils import registry
3737

3838
import tensorflow as tf
39-
import tf_slim as slim
4039

4140

4241
Frame = collections.namedtuple(
@@ -378,7 +377,7 @@ def extra_reading_spec(self):
378377
name: tf.FixedLenFeature([1], tf.int64) for name in field_names
379378
}
380379
decoders = {
381-
name: slim.tfexample_decoder.Tensor(tensor_key=name)
380+
name: tf.contrib.slim.tfexample_decoder.Tensor(tensor_key=name)
382381
for name in field_names
383382
}
384383
return (data_fields, decoders)

tensor2tensor/data_generators/image_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from tensor2tensor.utils import metrics
3232

3333
import tensorflow as tf
34-
import tf_slim as slim
3534

3635

3736
def matplotlib_pyplot():
@@ -173,7 +172,7 @@ def example_reading_spec(self):
173172

174173
data_items_to_decoders = {
175174
"inputs":
176-
slim.tfexample_decoder.Image(
175+
tf.contrib.slim.tfexample_decoder.Image(
177176
image_key="image/encoded",
178177
format_key="image/format",
179178
channels=self.num_channels),
@@ -240,7 +239,7 @@ def example_reading_spec(self):
240239
data_fields[label_key] = tf.FixedLenFeature((1,), tf.int64)
241240

242241
data_items_to_decoders[
243-
"targets"] = slim.tfexample_decoder.Tensor(label_key)
242+
"targets"] = tf.contrib.slim.tfexample_decoder.Tensor(label_key)
244243
return data_fields, data_items_to_decoders
245244

246245
def hparams(self, defaults, unused_model_hparams):
@@ -344,7 +343,7 @@ def example_reading_spec(self):
344343
super(Image2TextProblem, self).example_reading_spec())
345344
data_fields[label_key] = tf.VarLenFeature(tf.int64)
346345
data_items_to_decoders[
347-
"targets"] = slim.tfexample_decoder.Tensor(label_key)
346+
"targets"] = tf.contrib.slim.tfexample_decoder.Tensor(label_key)
348347
return data_fields, data_items_to_decoders
349348

350349
def feature_encoders(self, data_dir):

tensor2tensor/data_generators/moving_mnist.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import tensorflow as tf
3838
import tensorflow_datasets as tfds
3939
from tensorflow_datasets.video import moving_sequence
40-
import tf_slim as slim
4140

4241

4342
DATA_URL = (
@@ -95,7 +94,7 @@ def extra_reading_spec(self):
9594
"frame_number": tf.FixedLenFeature([1], tf.int64),
9695
}
9796
decoders = {
98-
"frame_number": slim.tfexample_decoder.Tensor(
97+
"frame_number": tf.contrib.slim.tfexample_decoder.Tensor(
9998
tensor_key="frame_number"),
10099
}
101100
return data_fields, decoders

tensor2tensor/data_generators/problem.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@
3232
from tensor2tensor.utils import mlperf_log
3333

3434
import tensorflow as tf
35-
import tf_slim as slim
36-
from tensorflow.contrib.tpu.python.tpu import tpu_config
35+
# pylint: disable=g-import-not-at-top
36+
try:
37+
from tensorflow.contrib.tpu.python.tpu import tpu_config
38+
except ImportError:
39+
# TF 2.0 doesn't ship with contrib.
40+
tpu_config = None
41+
# pylint: enable=g-import-not-at-top
3742

3843

3944

@@ -199,7 +204,7 @@ class Problem(object):
199204
- Mutate defaults as needed
200205
* example_reading_spec
201206
- Specify the names and types of the features on disk.
202-
- Specify slim.tfexample_decoder
207+
- Specify tf.contrib.slim.tfexample_decoder
203208
* preprocess_example(example, mode, hparams)
204209
- Preprocess the example feature dict from feature name to Tensor or
205210
SparseTensor.
@@ -643,7 +648,7 @@ def dataset(self,
643648

644649
data_filepattern = self.filepattern(data_dir, dataset_split, shard=shard)
645650
tf.logging.info("Reading data files from %s", data_filepattern)
646-
data_files = sorted(slim.parallel_reader.get_data_files(
651+
data_files = sorted(tf.contrib.slim.parallel_reader.get_data_files(
647652
data_filepattern))
648653

649654
# Functions used in dataset transforms below. `filenames` can be either a
@@ -706,12 +711,12 @@ def decode_example(self, serialized_example):
706711
data_fields["batch_prediction_key"] = tf.FixedLenFeature([1], tf.int64, 0)
707712
if data_items_to_decoders is None:
708713
data_items_to_decoders = {
709-
field: slim.tfexample_decoder.Tensor(field)
714+
field: tf.contrib.slim.tfexample_decoder.Tensor(field)
710715
for field in data_fields
711716
}
712717

713-
decoder = slim.tfexample_decoder.TFExampleDecoder(data_fields,
714-
data_items_to_decoders)
718+
decoder = tf.contrib.slim.tfexample_decoder.TFExampleDecoder(
719+
data_fields, data_items_to_decoders)
715720

716721
decode_items = list(sorted(data_items_to_decoders))
717722
decoded = decoder.decode(serialized_example, items=decode_items)

tensor2tensor/data_generators/style_transfer.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,12 @@
3232
from tensor2tensor.data_generators import text_problems
3333
from tensor2tensor.utils import registry
3434

35-
import tensorflow as tf
3635

37-
logger = tf.logging
36+
# Modern-Shakespeare corpus is consisted of:
37+
# - 18,395 parallel sentences for training (train set),
38+
# - 1,218 parallel sentences for evaluation (dev set),
39+
# - 1,462 parallel sentence for testing (test set).
3840

39-
"""
40-
Modern-Shakespeare corpus is consisted of:
41-
- 18,395 parallel sentences for training (train set),
42-
- 1,218 parallel sentences for evaluation (dev set),
43-
- 1,462 parallel sentence for testing (test set).
44-
"""
4541

4642
_SHAKESPEARE_MODERN_TRAIN_DATASET = [[
4743
"https://github.com/tlatkowski/st/raw/master/shakespeare.train.tgz",

tensor2tensor/data_generators/translate.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
from tensor2tensor.utils import mlperf_log
3333

3434
import tensorflow as tf
35-
import tf_slim as slim
3635

3736

3837
class TranslateProblem(text_problems.Text2TextProblem):
@@ -277,8 +276,8 @@ def example_reading_spec(self):
277276

278277
# hack: ignoring true targets and putting dist_targets in targets
279278
data_items_to_decoders = {
280-
"inputs": slim.tfexample_decoder.Tensor("inputs"),
281-
"targets": slim.tfexample_decoder.Tensor("dist_targets"),
279+
"inputs": tf.contrib.slim.tfexample_decoder.Tensor("inputs"),
280+
"targets": tf.contrib.slim.tfexample_decoder.Tensor("dist_targets"),
282281
}
283282

284283
return (data_fields, data_items_to_decoders)

tensor2tensor/data_generators/video_generated.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from tensor2tensor.utils import registry
2929

3030
import tensorflow as tf
31-
import tf_slim as slim
3231

3332
try:
3433
import matplotlib # pylint: disable=g-import-not-at-top
@@ -86,7 +85,7 @@ def extra_reading_spec(self):
8685
"frame_number": tf.FixedLenFeature([1], tf.int64),
8786
}
8887
decoders = {
89-
"frame_number": slim.tfexample_decoder.Tensor(
88+
"frame_number": tf.contrib.slim.tfexample_decoder.Tensor(
9089
tensor_key="frame_number"),
9190
}
9291
return data_fields, decoders

tensor2tensor/data_generators/video_utils.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from tensor2tensor.utils import metrics
3636
from tensor2tensor.utils import video_metrics
3737
import tensorflow as tf
38-
import tf_slim as slim
3938

4039

4140
FLAGS = flags.FLAGS
@@ -385,7 +384,7 @@ def example_reading_spec(self):
385384

386385
data_items_to_decoders = {
387386
"frame":
388-
slim.tfexample_decoder.Image(
387+
tf.contrib.slim.tfexample_decoder.Image(
389388
image_key="image/encoded",
390389
format_key="image/format",
391390
shape=[self.frame_height, self.frame_width, self.num_channels],
@@ -677,7 +676,7 @@ def example_reading_spec(self):
677676

678677
data_items_to_decoders = {
679678
"inputs":
680-
slim.tfexample_decoder.Image(
679+
tf.contrib.slim.tfexample_decoder.Image(
681680
image_key="image/encoded",
682681
format_key="image/format",
683682
channels=self.num_channels),
@@ -767,7 +766,7 @@ def example_reading_spec(self):
767766
super(Video2ClassProblem, self).example_reading_spec())
768767
data_fields[label_key] = tf.FixedLenFeature((1,), tf.int64)
769768
data_items_to_decoders[
770-
"targets"] = slim.tfexample_decoder.Tensor(label_key)
769+
"targets"] = tf.contrib.slim.tfexample_decoder.Tensor(label_key)
771770
return data_fields, data_items_to_decoders
772771

773772
def hparams(self, defaults, unused_model_hparams):

tensor2tensor/data_generators/vqa.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from tensor2tensor.utils import registry
4040

4141
import tensorflow as tf
42-
import tf_slim as slim
4342

4443

4544
def _get_vqa_v2_annotations(directory,
@@ -218,10 +217,10 @@ def example_reading_spec(self):
218217
(), tf.int64, allow_missing=True)
219218

220219
data_items_to_decoders[
221-
"question"] = slim.tfexample_decoder.Tensor(
220+
"question"] = tf.contrib.slim.tfexample_decoder.Tensor(
222221
"image/question")
223222
data_items_to_decoders[
224-
"targets"] = slim.tfexample_decoder.Tensor(
223+
"targets"] = tf.contrib.slim.tfexample_decoder.Tensor(
225224
"image/answer")
226225
return data_fields, data_items_to_decoders
227226

@@ -339,23 +338,23 @@ def example_reading_spec(self):
339338
(), tf.int64, allow_missing=True)
340339

341340
data_items_to_decoders[
342-
"inputs"] = slim.tfexample_decoder.Tensor(
341+
"inputs"] = tf.contrib.slim.tfexample_decoder.Tensor(
343342
"image/feature")
344343
data_items_to_decoders[
345-
"question_id"] = slim.tfexample_decoder.Tensor(
344+
"question_id"] = tf.contrib.slim.tfexample_decoder.Tensor(
346345
"image/question_id")
347346
data_items_to_decoders[
348-
"image_id"] = slim.tfexample_decoder.Tensor(
347+
"image_id"] = tf.contrib.slim.tfexample_decoder.Tensor(
349348
"image/image_id")
350349

351350
data_items_to_decoders[
352-
"spatial_feature"] = slim.tfexample_decoder.Tensor(
351+
"spatial_feature"] = tf.contrib.slim.tfexample_decoder.Tensor(
353352
"image/spatial_feature")
354353
data_items_to_decoders[
355-
"question"] = slim.tfexample_decoder.Tensor(
354+
"question"] = tf.contrib.slim.tfexample_decoder.Tensor(
356355
"image/question")
357356
data_items_to_decoders[
358-
"targets"] = slim.tfexample_decoder.Tensor(
357+
"targets"] = tf.contrib.slim.tfexample_decoder.Tensor(
359358
"image/answer")
360359

361360
return data_fields, data_items_to_decoders

tensor2tensor/envs/env_problem.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
from tensor2tensor.envs import trajectory
3434
from tensor2tensor.layers import modalities
3535
import tensorflow as tf
36-
import tf_slim as slim
3736

3837
# Names for data fields in stored tf.Examples.
3938
TIMESTEP_FIELD = "timestep"
@@ -477,7 +476,7 @@ def example_reading_spec(self):
477476
}
478477

479478
data_items_to_decoders = {
480-
field: slim.tfexample_decoder.Tensor(field)
479+
field: tf.contrib.slim.tfexample_decoder.Tensor(field)
481480
for field in data_fields
482481
}
483482

tensor2tensor/envs/rendered_env_problem.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from tensor2tensor.envs import env_problem
2626
from tensor2tensor.envs import gym_env_problem
2727
import tensorflow as tf
28-
import tf_slim as slim
2928

3029
_IMAGE_ENCODED_FIELD = "image/encoded"
3130
_IMAGE_FORMAT_FIELD = "image/format"
@@ -81,7 +80,7 @@ def example_reading_spec(self):
8180
# Add frame number spec and decoder.
8281
env_fields[_FRAME_NUMBER_FIELD] = tf.FixedLenFeature((1,), tf.int64)
8382
env_decoders[
84-
_FRAME_NUMBER_FIELD] = slim.tfexample_decoder.Tensor(
83+
_FRAME_NUMBER_FIELD] = tf.contrib.slim.tfexample_decoder.Tensor(
8584
_FRAME_NUMBER_FIELD)
8685

8786
# Add video fields and decoders

0 commit comments

Comments
 (0)