Skip to content

Commit 8f46dcd

Browse files
committed
A few more simple updates.
1 parent 0fb012a commit 8f46dcd

File tree

7 files changed

+23122
-77
lines changed

7 files changed

+23122
-77
lines changed

efficientdet/README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Arxiv link: https://arxiv.org/abs/1911.09070
1010

1111
Updates:
1212

13+
- Jul19/2021: Added Nvidia TensorRT script/instruction [link](https://github.com/NVIDIA/TensorRT/tree/master/samples/python/efficientdet)
1314
- May10/2021: Added EfficientDet-lite checkpoints (by Yuqi and TFLite team)
1415
- Mar25/2021: Added [Det-AdvProp](https://arxiv.org/abs/2103.13886) model checkpoints ([see this page](./Det-AdvProp.md)).
1516
- Jul20/2020: Added keras/TF2 and new SOTA D7x: 55.1mAP with 153ms.
@@ -77,6 +78,26 @@ We have provided a list of EfficientDet checkpoints and results as follows:
7778

7879
For more accurate and robust EfficientDet, please see [this page](./Det-AdvProp.md), which contains a list of models trained with Det-AdvProp + AutoAugment (AA) described in [this paper](https://arxiv.org/abs/2103.13886). The obatined model is not only more accurate on clean images, but also much more robust against various corruptions and domain shift.
7980

81+
On single Tesla V100 without using TensorRT, our end-to-end
82+
latency and throughput are:
83+
84+
85+
| Model | mAP | batch1 latency | batch1 throughput | batch8 throughput |
86+
| ------ | ------ | ------ | ------ | ------ |
87+
| EfficientDet-D0 | 34.6 | 10.2ms | 97 fps | 209 fps |
88+
| EfficientDet-D1 | 40.5 | 13.5ms | 74 fps | 140 fps |
89+
| EfficientDet-D2 | 43.0 | 17.7ms | 57 fps | 97 fps |
90+
| EfficientDet-D3 | 47.5 | 28.0ms | 36 fps | 58 fps |
91+
| EfficientDet-D4 | 49.7 | 42.8ms | 23 fps | 35 fps |
92+
| EfficientDet-D5 | 51.5 | 72.5ms | 14 fps | 18 fps |
93+
| EfficientDet-D6 | 52.6 | 92.8ms | 11 fps | - fps |
94+
| EfficientDet-D7 | 53.7 | 122ms | 8.2 fps | - fps |
95+
| EfficientDet-D7x | 55.1 | 153ms | 6.5 fps | - fps |
96+
97+
** FPS means frames per second (or images/second).
98+
99+
** EfficientDet can be significantly sped up with TensorRT: [link](https://github.com/NVIDIA/TensorRT/tree/master/samples/python/efficientdet)
100+
80101
In addition, the following table includes a list of models trained with fixed 640x640 image sizes (see appendix of [this paper](https://arxiv.org/abs/1911.09070)):
81102

82103

@@ -152,24 +173,6 @@ use the following command:
152173
--model_name=efficientdet-d0 --input_image=testdata/img1.jpg \
153174
--output_image_dir=/tmp/
154175

155-
On single Tesla V100 without using TensorRT, our end-to-end
156-
latency and throughput are:
157-
158-
159-
| Model | mAP | batch1 latency | batch1 throughput | batch8 throughput |
160-
| ------ | ------ | ------ | ------ | ------ |
161-
| EfficientDet-D0 | 34.6 | 10.2ms | 97 fps | 209 fps |
162-
| EfficientDet-D1 | 40.5 | 13.5ms | 74 fps | 140 fps |
163-
| EfficientDet-D2 | 43.0 | 17.7ms | 57 fps | 97 fps |
164-
| EfficientDet-D3 | 47.5 | 28.0ms | 36 fps | 58 fps |
165-
| EfficientDet-D4 | 49.7 | 42.8ms | 23 fps | 35 fps |
166-
| EfficientDet-D5 | 51.5 | 72.5ms | 14 fps | 18 fps |
167-
| EfficientDet-D6 | 52.6 | 92.8ms | 11 fps | - fps |
168-
| EfficientDet-D7 | 53.7 | 122ms | 8.2 fps | - fps |
169-
| EfficientDet-D7x | 55.1 | 153ms | 6.5 fps | - fps |
170-
171-
** FPS means frames per second (or images/second).
172-
173176
## 5. Inference for images.
174177

175178
# Step0: download model and testing image.

efficientnetv2/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
[TF-hub![TF-Hub In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.sandbox.google.com/github/google/automl/blob/master/efficientnetv2/tfhub.ipynb)
66

77

8+
- Jul19/2021: A list of updates
9+
* Added TF2 script [here](https://github.com/google/automl/blob/master/efficientnetv2/main_tf2.py).
10+
* Updated ImageNet21k sigmoid-loss checkpoints, for multi-class pseudo labeling.
11+
* Add EfficientNetV2-XL 21k and 1k checkpoint and hub modules.
12+
* Added Nvidia TensorRT script [here](https://github.com/NVIDIA/TensorRT/tree/master/samples/python/efficientnet).
813
- May13/2021: Initial code release for [EfficientNetV2 models](https://arxiv.org/abs/2104.00298): accepted to ICML'21.
914

1015
## 1. About EfficientNetV2 Models
@@ -28,7 +33,7 @@ We have provided a list of results and checkpoints as follows:
2833
| EffNetV2-M | 85.2% | 54.1M | 24.7B | [V100/A100](g3doc/effnetv2-m-gpu.png) | [ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-m.tgz), [tensorboard](https://tensorboard.dev/experiment/syoaqB2gTP6Vr0KRlrezmg)
2934
| EffNetV2-L | 85.7% | 119.5M | 56.3B | [V100/A100](g3doc/effnetv2-l-gpu.png) | [ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-l.tgz), [tensorboard](https://tensorboard.dev/experiment/qgnTQ5JZQ92nSex6ZlWBbQ)
3035

31-
** Thanks NVIDIA for providing the inference latency (benchmark scripts coming soon)
36+
** Thanks NVIDIA for providing the inference latency: full TensorRT scripts and instructions are available here: [link](https://github.com/NVIDIA/TensorRT/tree/master/samples/python/efficientnet)
3237

3338

3439
Here are a list of ImageNet21K pretrained and finetuned models:
@@ -39,6 +44,7 @@ Here are a list of ImageNet21K pretrained and finetuned models:
3944
| EffNetV2-S | [pretrain ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-s-21k.tgz) | top1=84.9%, [ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-s-21k-ft1k.tgz), [tensorboard](https://tensorboard.dev/experiment/7sga2olqTBeH4ioydel0hg/) |
4045
| EffNetV2-M | [pretrain ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-m-21k.tgz) | top1=86.2%, [ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-m-21k-ft1k.tgz), [tensorboard](https://tensorboard.dev/experiment/HkV6ANZSQ6WI5GhlZa48xQ/) |
4146
| EffNetV2-L | [pretrain ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-l-21k.tgz) | top1=86.9%, [ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-l-21k-ft1k.tgz), [tensorboard](https://tensorboard.dev/experiment/m9ZHx1L6SQu5iBYhXO5jOw/) |
47+
| EffNetV2-XL | [pretrain ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-xl-21k.tgz) | top1=87.2%, [ckpt](https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/efficientnetv2-xl-21k-ft1k.tgz), [tensorboard]()|
4248

4349
For comparison with EfficientNetV1, we have also provided a few smaller V2 models using the same scaling and preprocessing as V1:
4450

efficientnetv2/effnetv2_model.py

Lines changed: 110 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@
2525
import copy
2626
import itertools
2727
import math
28+
import os
2829

2930
from absl import logging
3031
import numpy as np
31-
import six
32-
from six.moves import xrange
3332
import tensorflow as tf
3433

3534
import effnetv2_configs
@@ -560,7 +559,7 @@ def _build(self):
560559
block_args.input_filters = block_args.output_filters
561560
block_args.strides = 1
562561
# pylint: enable=protected-access
563-
for _ in xrange(block_args.num_repeat - 1):
562+
for _ in range(block_args.num_repeat - 1):
564563
self._blocks.append(
565564
conv_block(block_args, self._mconfig, name=block_name()))
566565

@@ -624,7 +623,7 @@ def call(self, inputs, training, with_endpoints=False):
624623
if is_reduction:
625624
self.endpoints['reduction_%s' % reduction_idx] = outputs
626625
if block.endpoints:
627-
for k, v in six.iteritems(block.endpoints):
626+
for k, v in block.endpoints.items():
628627
self.endpoints['block_%s/%s' % (idx, k)] = v
629628
if is_reduction:
630629
self.endpoints['reduction_%s/%s' % (reduction_idx, k)] = v
@@ -655,7 +654,7 @@ def call(self, inputs, training, with_endpoints=False):
655654
def get_model(model_name,
656655
model_config=None,
657656
include_top=True,
658-
pretrained=True,
657+
weights='imagenet',
659658
training=True,
660659
with_endpoints=False,
661660
**kwargs):
@@ -667,7 +666,12 @@ def get_model(model_name,
667666
model_name: a string such as 'efficientnetv2-s' or 'efficientnet-b0'.
668667
model_config: A dict of model configurations or a string of hparams.
669668
include_top: whether to include the final dense layer for classification.
670-
pretrained: if true, download the checkpoint. If string, load the ckpt.
669+
weights: One of None (random initialization),
670+
'imagenet' (pretrained on ImageNet),
671+
'imagenet21k' (pretrained on Imagenet21k),
672+
'imagenet21k-ft1k' (pretrained on 21k and finetuned on 1k),
673+
'jft' (trained with non-labelled JFT-300),
674+
or the path to the weights file to be loaded. Defaults to 'imagenet'.
671675
training: If true, all model variables are trainable.
672676
with_endpoints: whether to return all intermedia endpoints.
673677
**kwargs: additional parameters for keras model, such as name=xx.
@@ -679,27 +683,106 @@ def get_model(model_name,
679683
net(tf.keras.Input(shape=(None, None, 3)),
680684
training=training,
681685
with_endpoints=with_endpoints)
682-
if pretrained is True: # pylint: disable=g-bool-id-comparison
683-
# pylint: disable=line-too-long
684-
# download checkpoint and set pretrained path. Supported models include:
685-
# efficientnetv2-s, efficientnetv2-m, efficientnetv2-l,
686-
# efficientnetv2-b0, efficientnetv2-b1, efficientnetv2-b2, efficientnetv2-b3,
687-
# efficientnet-b0, efficientnet-b1, efficientnet-b2, efficientnet-b3,
688-
# efficientnet-b4, efficientnet-b5, efficientnet-b6, efficientnet-b7,
689-
# efficientnet-l2
690-
# v2: https://github.com/google/automl/tree/master/efficientnetv2
691-
# v1: https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet
692-
# pylint: enable=line-too-long
693-
694-
url = ('https://storage.googleapis.com/cloud-tpu-checkpoints/'
695-
f'efficientnet/v2/{model_name}.tgz')
696-
pretrained_ckpt = tf.keras.utils.get_file(model_name, url, untar=True)
697-
else:
698-
pretrained_ckpt = pretrained
699686

700-
if pretrained_ckpt:
701-
if tf.io.gfile.isdir(pretrained_ckpt):
702-
pretrained_ckpt = tf.train.latest_checkpoint(pretrained_ckpt)
703-
net.load_weights(pretrained_ckpt)
687+
if not weights: # pylint: disable=g-bool-id-comparison
688+
return net
689+
690+
v2url = 'https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/v2/'
691+
v1url = 'https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/advprop/'
692+
v1jfturl = 'https://storage.googleapis.com/cloud-tpu-checkpoints/efficientnet/noisystudent/'
693+
pretrained_ckpts = {
694+
# EfficientNet V2.
695+
'efficientnetv2-s': {
696+
'imagenet': v2url + 'efficientnetv2-s.tgz',
697+
'imagenet21k': v2url + 'efficientnetv2-s-21k.tgz',
698+
'imagenet21k-ft1k': v2url + 'efficientnetv2-s-21k-ft1k.tgz',
699+
},
700+
'efficientnetv2-m': {
701+
'imagenet': v2url + 'efficientnetv2-m.tgz',
702+
'imagenet21k': v2url + 'efficientnetv2-m-21k.tgz',
703+
'imagenet21k-ft1k': v2url + 'efficientnetv2-m-21k-ft1k.tgz',
704+
},
705+
'efficientnetv2-l': {
706+
'imagenet': v2url + 'efficientnetv2-l.tgz',
707+
'imagenet21k': v2url + 'efficientnetv2-l-21k.tgz',
708+
'imagenet21k-ft1k': v2url + 'efficientnetv2-l-21k-ft1k.tgz',
709+
},
710+
'efficientnetv2-xl': {
711+
# no imagenet ckpt.
712+
'imagenet21k': v2url + 'efficientnetv2-xl-21k.tgz',
713+
'imagenet21k-ft1k': v2url + 'efficientnetv2-xl-21k-ft1k.tgz',
714+
},
715+
716+
'efficientnetv2-b0': {
717+
'imagenet': v2url + 'efficientnetv2-b0.tgz',
718+
'imagenet21k': v2url + 'efficientnetv2-b0-21k.tgz',
719+
'imagenet21k-ft1k': v2url + 'efficientnetv2-b0-21k-ft1k.tgz',
720+
},
721+
'efficientnetv2-b1': {
722+
'imagenet': v2url + 'efficientnetv2-b1.tgz',
723+
'imagenet21k': v2url + 'efficientnetv2-b1-21k.tgz',
724+
'imagenet21k-ft1k': v2url + 'efficientnetv2-b1-21k-ft1k.tgz',
725+
},
726+
'efficientnetv2-b2': {
727+
'imagenet': v2url + 'efficientnetv2-b2.tgz',
728+
'imagenet21k': v2url + 'efficientnetv2-b2-21k.tgz',
729+
'imagenet21k-ft1k': v2url + 'efficientnetv2-b2-21k-ft1k.tgz',
730+
},
731+
'efficientnetv2-b3': {
732+
'imagenet': v2url + 'efficientnetv2-b3.tgz',
733+
'imagenet21k': v2url + 'efficientnetv2-b3-21k.tgz',
734+
'imagenet21k-ft1k': v2url + 'efficientnetv2-b3-21k-ft1k.tgz',
735+
},
736+
737+
# EfficientNet V1.
738+
'efficientnet-b0': {
739+
'imagenet': v1url + 'efficientnet-b0.tar.gz',
740+
'jft': v1jfturl + 'noisy_student_efficientnet-b0.tar.gz',
741+
},
742+
'efficientnet-b1': {
743+
'imagenet': v1url + 'efficientnet-b1.tar.gz',
744+
'jft': v1jfturl + 'noisy_student_efficientnet-b1.tar.gz',
745+
},
746+
'efficientnet-b2': {
747+
'imagenet': v1url + 'efficientnet-b2.tar.gz',
748+
'jft': v1jfturl + 'noisy_student_efficientnet-b2.tar.gz',
749+
},
750+
'efficientnet-b3': {
751+
'imagenet': v1url + 'efficientnet-b3.tar.gz',
752+
'jft': v1jfturl + 'noisy_student_efficientnet-b3.tar.gz',
753+
},
754+
'efficientnet-b4': {
755+
'imagenet': v1url + 'efficientnet-b4.tar.gz',
756+
'jft': v1jfturl + 'noisy_student_efficientnet-b4.tar.gz',
757+
},
758+
'efficientnet-b5': {
759+
'imagenet': v1url + 'efficientnet-b5.tar.gz',
760+
'jft': v1jfturl + 'noisy_student_efficientnet-b5.tar.gz',
761+
},
762+
'efficientnet-b6': {
763+
'imagenet': v1url + 'efficientnet-b6.tar.gz',
764+
'jft': v1jfturl + 'noisy_student_efficientnet-b6.tar.gz',
765+
},
766+
'efficientnet-b7': {
767+
'imagenet': v1url + 'efficientnet-b7.tar.gz',
768+
'jft': v1jfturl + 'noisy_student_efficientnet-b7.tar.gz',
769+
},
770+
'efficientnet-b8': {
771+
'imagenet': v1url + 'efficientnet-b8.tar.gz',
772+
},
773+
'efficientnet-l2': {
774+
'jft': v1jfturl + 'noisy_student_efficientnet-l2_475.tar.gz',
775+
},
776+
}
777+
778+
if model_name in pretrained_ckpts and weights in pretrained_ckpts[model_name]:
779+
url = pretrained_ckpts[model_name][weights]
780+
fname = os.path.splitext(os.path.basename(url))[0]
781+
pretrained_ckpt= tf.keras.utils.get_file(fname, url , untar=True)
782+
else:
783+
pretrained_ckpt = weights
704784

785+
if tf.io.gfile.isdir(pretrained_ckpt):
786+
pretrained_ckpt = tf.train.latest_checkpoint(pretrained_ckpt)
787+
net.load_weights(pretrained_ckpt)
705788
return net

efficientnetv2/effnetv2_model.pyc

23 KB
Binary file not shown.

0 commit comments

Comments
 (0)