1
1
# Image Classification
2
2
3
- ** Warning:** the features in the ` image_classification/ ` folder have been fully
4
- integrated into vision/beta. Please use the [ new code base] ( ../../ vision/beta/README.md ) .
3
+ ** Warning:** the features in the ` image_classification/ ` directory have been
4
+ fully integrated into the [ new code base] ( https://github.com/tensorflow/models/tree/benchmark/official/ vision/modeling/backbones ) .
5
5
6
- This folder contains TF 2.0 model examples for image classification:
6
+ This folder contains TF 2 model examples for image classification:
7
7
8
8
* [ MNIST] ( #mnist )
9
9
* [ Classifier Trainer] ( #classifier-trainer ) , a framework that uses the Keras
@@ -17,8 +17,7 @@ For more information about other types of models, please refer to this
17
17
18
18
## Before you begin
19
19
Please make sure that you have the latest version of TensorFlow
20
- installed and
21
- [ add the models folder to your Python path] ( /official/#running-the-models ) .
20
+ installed and add the models folder to your Python path.
22
21
23
22
### ImageNet preparation
24
23
@@ -70,6 +69,7 @@ available GPUs at each host.
70
69
To download the data and run the MNIST sample model locally for the first time,
71
70
run one of the following command:
72
71
72
+ <details >
73
73
``` bash
74
74
python3 mnist_main.py \
75
75
--model_dir=$MODEL_DIR \
@@ -79,9 +79,11 @@ python3 mnist_main.py \
79
79
--num_gpus=$NUM_GPUS \
80
80
--download
81
81
```
82
+ </details >
82
83
83
84
To train the model on a Cloud TPU, run the following command:
84
85
86
+ <details >
85
87
``` bash
86
88
python3 mnist_main.py \
87
89
--tpu=$TPU_NAME \
@@ -91,10 +93,10 @@ python3 mnist_main.py \
91
93
--distribution_strategy=tpu \
92
94
--download
93
95
```
96
+ </details >
94
97
95
98
Note: the ` --download ` flag is only required the first time you run the model.
96
99
97
-
98
100
## Classifier Trainer
99
101
The classifier trainer is a unified framework for running image classification
100
102
models using Keras's compile/fit methods. Experiments should be provided in the
@@ -111,6 +113,8 @@ be 64 * 8 = 512, and for a v3-32, the global batch size is 64 * 32 = 2048.
111
113
### ResNet50
112
114
113
115
#### On GPU:
116
+
117
+ <details >
114
118
``` bash
115
119
python3 classifier_trainer.py \
116
120
--mode=train_and_eval \
@@ -121,12 +125,15 @@ python3 classifier_trainer.py \
121
125
--config_file=configs/examples/resnet/imagenet/gpu.yaml \
122
126
--params_override=' runtime.num_gpus=$NUM_GPUS'
123
127
```
128
+ </details >
124
129
125
130
To train on multiple hosts, each with GPUs attached using
126
131
[ MultiWorkerMirroredStrategy] ( https://www.tensorflow.org/api_docs/python/tf/distribute/experimental/MultiWorkerMirroredStrategy )
127
132
please update ` runtime ` section in gpu.yaml
128
133
(or override using ` --params_override ` ) with:
129
134
135
+ <details >
136
+
130
137
``` YAML
131
138
# gpu.yaml
132
139
runtime :
@@ -135,12 +142,16 @@ runtime:
135
142
num_gpus : $NUM_GPUS
136
143
task_index : 0
137
144
` ` `
145
+ </details>
146
+
138
147
By having ` task_index: 0` on the first host and `task_index: 1` on the second
139
148
and so on. `$HOST1` and `$HOST2` are the IP addresses of the hosts, and `port`
140
149
can be chosen any free port on the hosts. Only the first host will write
141
150
TensorBoard Summaries and save checkpoints.
142
151
143
152
# ### On TPU:
153
+
154
+ <details>
144
155
` ` ` bash
145
156
python3 classifier_trainer.py \
146
157
--mode=train_and_eval \
@@ -152,9 +163,13 @@ python3 classifier_trainer.py \
152
163
--config_file=configs/examples/resnet/imagenet/tpu.yaml
153
164
` ` `
154
165
166
+ </details>
167
+
155
168
# ## VGG-16
156
169
157
170
# ### On GPU:
171
+
172
+ <details>
158
173
` ` ` bash
159
174
python3 classifier_trainer.py \
160
175
--mode=train_and_eval \
@@ -166,9 +181,13 @@ python3 classifier_trainer.py \
166
181
--params_override='runtime.num_gpus=$NUM_GPUS'
167
182
` ` `
168
183
184
+ </details>
185
+
169
186
# ## EfficientNet
170
187
**Note: EfficientNet development is a work in progress.**
171
188
# ### On GPU:
189
+
190
+ <details>
172
191
` ` ` bash
173
192
python3 classifier_trainer.py \
174
193
--mode=train_and_eval \
@@ -180,8 +199,11 @@ python3 classifier_trainer.py \
180
199
--params_override='runtime.num_gpus=$NUM_GPUS'
181
200
` ` `
182
201
202
+ </details>
183
203
184
204
# ### On TPU:
205
+
206
+ <details>
185
207
` ` ` bash
186
208
python3 classifier_trainer.py \
187
209
--mode=train_and_eval \
@@ -192,6 +214,7 @@ python3 classifier_trainer.py \
192
214
--data_dir=$DATA_DIR \
193
215
--config_file=configs/examples/efficientnet/imagenet/efficientnet-b0-tpu.yaml
194
216
` ` `
217
+ </details>
195
218
196
219
Note that the number of GPU devices can be overridden in the command line using
197
220
` --params_overrides` . The TPU does not need this override as the device is fixed
0 commit comments