Skip to content

Commit b749823

Browse files
author
Allen Wang
committed
Add in instructions for TFDS for classifier_trainer.
PiperOrigin-RevId: 303828114
1 parent bcfba28 commit b749823

File tree

7 files changed

+26
-27
lines changed

7 files changed

+26
-27
lines changed

official/vision/image_classification/README.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,25 @@ installed and
1919

2020
### ImageNet preparation
2121

22+
#### Using TFDS
23+
`classifier_trainer.py` supports ImageNet with
24+
[TensorFlow Datasets (TFDS)](https://www.tensorflow.org/datasets/overview).
25+
26+
Please see the following [example snippet](https://github.com/tensorflow/datasets/blob/master/tensorflow_datasets/scripts/download_and_prepare.py)
27+
for more information on how to use TFDS to download and prepare datasets, and
28+
specifically the [TFDS ImageNet readme](https://github.com/tensorflow/datasets/blob/master/docs/catalog/imagenet2012.md)
29+
for manual download instructions.
30+
31+
#### Legacy TFRecords
2232
Download the ImageNet dataset and convert it to TFRecord format.
2333
The following [script](https://github.com/tensorflow/tpu/blob/master/tools/datasets/imagenet_to_gcs.py)
2434
and [README](https://github.com/tensorflow/tpu/tree/master/tools/datasets#imagenet_to_gcspy)
2535
provide a few options.
2636

37+
Note that the legacy ResNet runners, e.g. [resnet/resnet_ctl_imagenet_main.py](resnet/resnet_ctl_imagenet_main.py)
38+
require TFRecords whereas `classifier_trainer.py` can use both by setting the
39+
builder to 'records' or 'tfds' in the configurations.
40+
2741
### Running on Cloud TPUs
2842

2943
Note: These models will **not** work with TPUs on Colab.
@@ -114,7 +128,7 @@ python3 classifier_trainer.py \
114128
--tpu=$TPU_NAME \
115129
--model_dir=$MODEL_DIR \
116130
--data_dir=$DATA_DIR \
117-
--config_file=config/examples/resnet/imagenet/tpu.yaml
131+
--config_file=configs/examples/resnet/imagenet/tpu.yaml
118132
```
119133

120134
### EfficientNet
@@ -141,7 +155,7 @@ python3 classifier_trainer.py \
141155
--tpu=$TPU_NAME \
142156
--model_dir=$MODEL_DIR \
143157
--data_dir=$DATA_DIR \
144-
--config_file=config/examples/efficientnet/imagenet/efficientnet-b0-tpu.yaml
158+
--config_file=configs/examples/efficientnet/imagenet/efficientnet-b0-tpu.yaml
145159
```
146160

147161
Note that the number of GPU devices can be overridden in the command line using

official/vision/image_classification/classifier_trainer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _get_dataset_builders(params: base_configs.ExperimentConfig,
113113
image_size = get_image_size_from_model(params)
114114

115115
dataset_configs = [
116-
params.train_dataset, params.validation_dataset, params.test_dataset
116+
params.train_dataset, params.validation_dataset
117117
]
118118
builders = []
119119

@@ -320,8 +320,8 @@ def train_and_eval(
320320
datasets = [builder.build() if builder else None for builder in builders]
321321

322322
# Unpack datasets and builders based on train/val/test splits
323-
train_builder, validation_builder, test_builder = builders # pylint: disable=unbalanced-tuple-unpacking
324-
train_dataset, validation_dataset, test_dataset = datasets
323+
train_builder, validation_builder = builders # pylint: disable=unbalanced-tuple-unpacking
324+
train_dataset, validation_dataset = datasets
325325

326326
train_epochs = params.train.epochs
327327
train_steps = params.train.steps or train_builder.num_steps

official/vision/image_classification/classifier_trainer_test.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ def basic_params_override() -> MutableMapping[str, Any]:
8282
'use_per_replica_batch_size': True,
8383
'image_size': 224,
8484
},
85-
'test_dataset': {
86-
'builder': 'synthetic',
87-
'batch_size': 1,
88-
'use_per_replica_batch_size': True,
89-
'image_size': 224,
90-
},
9185
'train': {
9286
'steps': 1,
9387
'epochs': 1,

official/vision/image_classification/configs/base_configs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ class ExperimentConfig(base_config.Config):
230230
runtime: RuntimeConfig = None
231231
train_dataset: Any = None
232232
validation_dataset: Any = None
233-
test_dataset: Any = None
234233
train: TrainConfig = None
235234
evaluation: EvalConfig = None
236235
model: ModelConfig = None

official/vision/image_classification/configs/configs.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class EfficientNetImageNetConfig(base_configs.ExperimentConfig):
4545
dataset_factory.ImageNetConfig(split='train')
4646
validation_dataset: dataset_factory.DatasetConfig = \
4747
dataset_factory.ImageNetConfig(split='validation')
48-
test_dataset: dataset_factory.DatasetConfig = \
49-
dataset_factory.ImageNetConfig(split='validation')
5048
train: base_configs.TrainConfig = base_configs.TrainConfig(
5149
resume_checkpoint=True,
5250
epochs=500,
@@ -79,11 +77,6 @@ class ResNetImagenetConfig(base_configs.ExperimentConfig):
7977
one_hot=False,
8078
mean_subtract=True,
8179
standardize=True)
82-
test_dataset: dataset_factory.DatasetConfig = \
83-
dataset_factory.ImageNetConfig(split='validation',
84-
one_hot=False,
85-
mean_subtract=True,
86-
standardize=True)
8780
train: base_configs.TrainConfig = base_configs.TrainConfig(
8881
resume_checkpoint=True,
8982
epochs=90,

official/vision/image_classification/configs/examples/resnet/imagenet/gpu.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Training configuration for ResNet trained on ImageNet on GPUs.
2-
# Takes ~3 minutes, 15 seconds per epoch for 8 V100s.
3-
# Reaches ~76.1% within 90 epochs.
2+
# Reaches > 76.1% within 90 epochs.
43
# Note: This configuration uses a scaled per-replica batch size based on the number of devices.
54
runtime:
65
model_dir: null
@@ -10,7 +9,7 @@ runtime:
109
train_dataset:
1110
name: 'imagenet2012'
1211
data_dir: null
13-
builder: 'records'
12+
builder: 'tfds'
1413
split: 'train'
1514
image_size: 224
1615
num_classes: 1000
@@ -23,7 +22,7 @@ train_dataset:
2322
validation_dataset:
2423
name: 'imagenet2012'
2524
data_dir: null
26-
builder: 'records'
25+
builder: 'tfds'
2726
split: 'validation'
2827
image_size: 224
2928
num_classes: 1000

official/vision/image_classification/configs/examples/resnet/imagenet/tpu.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Training configuration for ResNet trained on ImageNet on TPUs.
2-
# Takes ~2 minutes, 43 seconds per epoch for a v3-32.
3-
# Reaches ~76.1% within 90 epochs.
2+
# Takes ~4 minutes, 30 seconds seconds per epoch for a v3-32.
3+
# Reaches > 76.1% within 90 epochs.
44
# Note: This configuration uses a scaled per-replica batch size based on the number of devices.
55
runtime:
66
model_dir: null
@@ -9,7 +9,7 @@ runtime:
99
train_dataset:
1010
name: 'imagenet2012'
1111
data_dir: null
12-
builder: 'records'
12+
builder: 'tfds'
1313
split: 'train'
1414
one_hot: False
1515
image_size: 224
@@ -23,7 +23,7 @@ train_dataset:
2323
validation_dataset:
2424
name: 'imagenet2012'
2525
data_dir: null
26-
builder: 'records'
26+
builder: 'tfds'
2727
split: 'validation'
2828
one_hot: False
2929
image_size: 224

0 commit comments

Comments
 (0)