Skip to content

Commit 1bfe1df

Browse files
marksandler2sguada
authored andcommitted
PNasNet (#3736)
* PiperOrigin-RevId: 189857068 * PiperOrigin-RevId: 190089200 * Merge pull request #3702 from cclauss/from-six.moves-import-xrange-yet-again from six.moves import xrange (en masse) YET AGAIN PiperOrigin-RevId: 190255581 * I Fixes bunch of model tests that were using python2 functions. II Updates mobilenet code: 1) Mobilenet usage example 2) Links to all checkpoints and updated README 3) Performance graphs PiperOrigin-RevId: 190300379 * PiperOrigin-RevId: 190306214 * Updates notebook to reflect canonical repository location and fixes few variable names.
1 parent 932364b commit 1bfe1df

18 files changed

+411
-39
lines changed

research/slim/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ Model | TF-Slim File | Checkpoint | Top-1 Accuracy| Top-5 Accuracy |
259259
[MobileNet_v1_1.0_224](https://arxiv.org/pdf/1704.04861.pdf)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.py)|[mobilenet_v1_1.0_224.tgz](http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz)|70.9|89.9|
260260
[MobileNet_v1_0.50_160](https://arxiv.org/pdf/1704.04861.pdf)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.py)|[mobilenet_v1_0.50_160.tgz](http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_0.5_160.tgz)|59.1|81.9|
261261
[MobileNet_v1_0.25_128](https://arxiv.org/pdf/1704.04861.pdf)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet_v1.py)|[mobilenet_v1_0.25_128.tgz](http://download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_0.25_128.tgz)|41.5|66.3|
262-
[MobileNet_v2_1.0_224^*](https://arxiv.org/abs/1801.04381)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet_v2.py)|[Checkpoint TBA]()|72.2|91.0|
262+
[MobileNet_v2_1.4_224^*](https://arxiv.org/abs/1801.04381)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet_v2.py)| [mobilenet_v2_1.4_224.tgz](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.4_224.tgz) | 74.9 | 92.5|
263+
[MobileNet_v2_1.0_224^*](https://arxiv.org/abs/1801.04381)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet_v2.py)| [mobilenet_v2_1.0_224.tgz](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_224.tgz) | 71.9 | 91.0
263264
[NASNet-A_Mobile_224](https://arxiv.org/abs/1707.07012)#|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/nasnet/nasnet.py)|[nasnet-a_mobile_04_10_2017.tar.gz](https://storage.googleapis.com/download.tensorflow.org/models/nasnet-a_mobile_04_10_2017.tar.gz)|74.0|91.6|
264265
[NASNet-A_Large_331](https://arxiv.org/abs/1707.07012)#|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/nasnet/nasnet.py)|[nasnet-a_large_04_10_2017.tar.gz](https://storage.googleapis.com/download.tensorflow.org/models/nasnet-a_large_04_10_2017.tar.gz)|82.7|96.2|
265266
[PNASNet-5_Large_331](https://arxiv.org/abs/1712.00559)|[Code](https://github.com/tensorflow/models/blob/master/research/slim/nets/nasnet/pnasnet.py)|[pnasnet-5_large_2017_12_13.tar.gz](https://storage.googleapis.com/download.tensorflow.org/models/pnasnet-5_large_2017_12_13.tar.gz)|82.9|96.2|
@@ -275,7 +276,7 @@ All 16 float MobileNet V1 models reported in the [MobileNet Paper](https://arxiv
275276
16 quantized [TensorFlow Lite](https://www.tensorflow.org/mobile/tflite/) compatible MobileNet V1 models can be found
276277
[here](https://github.com/tensorflow/models/tree/master/research/slim/nets/mobilenet_v1.md).
277278

278-
(^#) More details on Mobilenet V2 models can be found [here](nets/mobilenet/README.md).
279+
(^#) More details on MobileNetV2 models can be found [here](nets/mobilenet/README.md).
279280

280281
(\*): Results quoted from the [paper](https://arxiv.org/abs/1603.05027).
281282

research/slim/datasets/build_imagenet_data.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,8 @@
9393
import threading
9494

9595
import numpy as np
96-
from six.moves import xrange
96+
from six.moves import xrange # pylint: disable=redefined-builtin
9797
import tensorflow as tf
98-
from six.moves import xrange
9998

10099

101100
tf.app.flags.DEFINE_string('train_directory', '/tmp/',

research/slim/datasets/preprocess_imagenet_validation_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
# ==============================================================================
16-
"""Process the ImageNet Challenge bounding boxes for TensorFlow model training.
16+
r"""Process the ImageNet Challenge bounding boxes for TensorFlow model training.
1717
1818
Associate the ImageNet 2012 Challenge validation data set with labels.
1919
@@ -51,7 +51,7 @@
5151
import os
5252
import sys
5353

54-
from six.moves import xrange
54+
from six.moves import xrange # pylint: disable=redefined-builtin
5555

5656

5757
if __name__ == '__main__':

research/slim/datasets/process_bounding_boxes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@
8585
import os.path
8686
import sys
8787
import xml.etree.ElementTree as ET
88-
from six.moves import xrange
89-
90-
from six.moves import xrange
88+
from six.moves import xrange # pylint: disable=redefined-builtin
9189

9290

9391
class BoundingBox(object):

research/slim/deployment/model_deploy.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,11 @@ def _gather_clone_loss(clone, num_clones, regularization_losses):
230230
sum_loss = tf.add_n(all_losses)
231231
# Add the summaries out of the clone device block.
232232
if clone_loss is not None:
233-
tf.summary.scalar(clone.scope + '/clone_loss', clone_loss, family='Losses')
233+
tf.summary.scalar('/'.join(filter(None,
234+
['Losses', clone.scope, 'clone_loss'])),
235+
clone_loss)
234236
if regularization_loss is not None:
235-
tf.summary.scalar('regularization_loss', regularization_loss,
236-
family='Losses')
237+
tf.summary.scalar('Losses/regularization_loss', regularization_loss)
237238
return sum_loss
238239

239240

research/slim/nets/cyclegan.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
from __future__ import print_function
1919

2020
import numpy as np
21-
from six.moves import xrange
21+
from six.moves import xrange # pylint: disable=redefined-builtin
2222
import tensorflow as tf
23-
from six.moves import xrange
2423

2524
layers = tf.contrib.layers
2625

research/slim/nets/dcgan.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
from math import log
2121

22-
from six.moves import xrange
23-
22+
from six.moves import xrange # pylint: disable=redefined-builtin
2423
import tensorflow as tf
25-
from six.moves import xrange
24+
2625
slim = tf.contrib.slim
2726

2827

research/slim/nets/dcgan_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
from __future__ import division
1919
from __future__ import print_function
2020

21-
from six.moves import xrange
21+
from six.moves import xrange # pylint: disable=redefined-builtin
2222
import tensorflow as tf
23-
from six.moves import xrange
23+
2424
from nets import dcgan
2525

2626

research/slim/nets/inception_v4_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def testBuildBaseNetwork(self):
127127
'Mixed_6e', 'Mixed_6f', 'Mixed_6g', 'Mixed_6h', 'Mixed_7a',
128128
'Mixed_7b', 'Mixed_7c', 'Mixed_7d']
129129
self.assertItemsEqual(end_points.keys(), expected_endpoints)
130-
for name, op in end_points.iteritems():
130+
for name, op in end_points.items():
131131
self.assertTrue(op.name.startswith('InceptionV4/' + name))
132132

133133
def testBuildOnlyUpToFinalEndpoint(self):
Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,53 @@
1-
# Mobilenet V2
2-
This folder contains building code for Mobilenet V2, based on
3-
[Inverted Residuals and Linear Bottlenecks: Mobile Networks for Classification, Detection and Segmentation]
4-
(https://arxiv.org/abs/1801.04381)
1+
# MobileNetV2
2+
This folder contains building code for MobileNetV2, based on
3+
[MobileNetV2: Inverted Residuals and Linear Bottlenecks](https://arxiv.org/abs/1801.04381)
54

6-
# Pretrained model
7-
TODO
5+
# Performance
6+
## Latency
7+
This is the timing of [MobileNetV1](../mobilenet_v1.md) vs MobileNetV2 using
8+
TF-Lite on the large core of Pixel 1 phone.
9+
10+
![mnet_v1_vs_v2_pixel1_latency.png](mnet_v1_vs_v2_pixel1_latency.png)
11+
12+
## MACs
13+
MACs, also sometimes known as MADDs - the number of multiply-accumulates needed
14+
to compute an inference on a single image is a common metric to measure the efficiency of the model.
15+
16+
Below is the graph comparing V2 vs a few selected networks. The size
17+
of each blob represents the number of parameters. Note for [ShuffleNet](https://arxiv.org/abs/1707.01083) there
18+
are no published size numbers. We estimate it to be comparable to MobileNetV2 numbers.
19+
20+
![madds_top1_accuracy](madds_top1_accuracy.png)
21+
22+
# Pretrained models
23+
## Imagenet Checkpoints
24+
25+
Classification Checkpoint | MACs (M)| Parameters (M)| Top 1 Accuracy| Top 5 Accuracy | Mobile CPU (ms) Pixel 1
26+
---------------------------|---------|---------------|---------|----|-------------
27+
| [mobilenet_v2_1.4_224](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.4_224.tgz) | 582 | 6.06 | 75.0 | 92.5 | 138.0
28+
| [mobilenet_v2_1.3_224](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.3_224.tgz) | 509 | 5.34 | 74.4 | 92.1 | 123.0
29+
| [mobilenet_v2_1.0_224](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_224.tgz) | 300 | 3.47 | 71.8 | 91.0 | 73.8
30+
| [mobilenet_v2_1.0_192](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_192.tgz) | 221 | 3.47 | 70.7 | 90.1 | 55.1
31+
| [mobilenet_v2_1.0_160](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_160.tgz) | 154 | 3.47 | 68.8 | 89.0 | 40.2
32+
| [mobilenet_v2_1.0_128](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_128.tgz) | 99 | 3.47 | 65.3 | 86.9 | 27.6
33+
| [mobilenet_v2_1.0_96](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_1.0_96.tgz) | 56 | 3.47 | 60.3 | 83.2 | 17.6
34+
| [mobilenet_v2_0.75_224](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.75_224.tgz) | 209 | 2.61 | 69.8 | 89.6 | 55.8
35+
| [mobilenet_v2_0.75_192](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.75_192.tgz) | 153 | 2.61 | 68.7 | 88.9 | 41.6
36+
| [mobilenet_v2_0.75_160](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.75_160.tgz) | 107 | 2.61 | 66.4 | 87.3 | 30.4
37+
| [mobilenet_v2_0.75_128](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.75_128.tgz) | 69 | 2.61 | 63.2 | 85.3 | 21.9
38+
| [mobilenet_v2_0.75_96](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.75_96.tgz) | 39 | 2.61 | 58.8 | 81.6 | 14.2
39+
| [mobilenet_v2_0.5_224](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.5_224.tgz) | 97 | 1.95 | 65.4 | 86.4 | 28.7
40+
| [mobilenet_v2_0.5_192](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.5_192.tgz) | 71 | 1.95 | 63.9 | 85.4 | 21.1
41+
| [mobilenet_v2_0.5_160](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.5_160.tgz) | 50 | 1.95 | 61.0 | 83.2 | 14.9
42+
| [mobilenet_v2_0.5_128](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.5_128.tgz) | 32 | 1.95 | 57.7 | 80.8 | 9.9
43+
| [mobilenet_v2_0.5_96](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.5_96.tgz) | 18 | 1.95 | 51.2 | 75.8 | 6.4
44+
| [mobilenet_v2_0.35_224](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.35_224.tgz) | 59 | 1.66 | 60.3 | 82.9 | 19.7
45+
| [mobilenet_v2_0.35_192](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.35_192.tgz) | 43 | 1.66 | 58.2 | 81.2 | 14.6
46+
| [mobilenet_v2_0.35_160](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.35_160.tgz) | 30 | 1.66 | 55.7 | 79.1 | 10.5
47+
| [mobilenet_v2_0.35_128](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.35_128.tgz) | 20 | 1.66 | 50.8 | 75.0 | 6.9
48+
| [mobilenet_v2_0.35_96](https://storage.googleapis.com/mobilenet_v2/checkpoints/mobilenet_v2_0.35_96.tgz) | 11 | 1.66 | 45.5 | 70.4 | 4.5
849

950
# Example
10-
TODO
1151

52+
See this [ipython notebook](mobilenet_example.ipynb) or open and run the network directly in [Colaboratory](https://colab.research.google.com/github/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet_example.ipynb).
1253

0 commit comments

Comments
 (0)