EfficientDet For TensorFlow2

EfficientDet For TensorFlow2

Logo for EfficientDet For TensorFlow2
A convolution-based neural network for the task of object detection.
NVIDIA Deep Learning Examples
Latest Version
November 4, 2022
Compressed Size
31.5 KB

This resource is using open-source code maintained in github (see the quick-start-guide section) and available for download from NGC

EfficientDet is a family of convolution-based neural networks for object detection. Specifically, this repository covers model D0. This model is based on EfficientDet: Scalable and Efficient Object Detection. NVIDIA's implementation of EfficientDet-D0 is an optimized version of TensorFlow Automl implementation, leveraging mixed precision arithmetic on NVIDIA Volta, NVIDIA Turing, and the NVIDIA Ampere GPU architectures for faster training times while maintaining target accuracy.

The EfficientDet model covered in this repository is tested against each NGC monthly released container to ensure consistent accuracy and performance over time.

The major differences between the official implementation of the paper and our version of EfficientDet are as follows:

These techniques/optimizations improve model performance and reduce training time, allowing you to perform more efficient object detection with no additional effort.

Other publicly available implementations of EfficientDet include:

Model architecture

EfficientDet is a one-stage detector with the following architecture components:

  • ImageNet-pretrained EfficientNet backbone
  • Weighted bi-directional feature pyramid network (BiFPN)
  • Bounding and classification box head
  • A compound scaling method that uniformly scales the resolution, depth, and width for all backbone, feature network, and box/class prediction networks at the same time

Feature support matrix

The model supports the following features.

Feature EfficientDet
Horovod Multi-GPU training (NCCL) Yes
Multi-GPU training Yes
Multi-node training Yes
AMP (Automatic Mixed Precision) Yes


Horovod is used to implement efficient multi-GPU training with NCCL. It is also used for multi-node training. For details, refer to example sources in this repository or refer to the TensorFlow tutorial.

AMP or Automatic Mixed Precision modifies computation graphs during runtime to support mixed precision training. A detailed explanation of mixed precision can be found below.

Automatic Mixed Precision

Mixed precision is the combined use of different numerical precisions in a computational method. Mixed precision training offers significant computational speedup by performing operations in half-precision format while storing minimal information in single-precision to retain as much information as possible in critical parts of the network. Since the introduction of Tensor Cores in NVIDIA Volta, and following with both the NVIDIA Turing and NVIDIA Ampere Architectures, significant training speedups are experienced by switching to mixed precision -- up to 3x overall speedup on the most arithmetically intense model architectures. Using mixed precision training previously required two steps:

  1. Porting the model to use the FP16 data type where appropriate.
  2. Adding loss scaling to preserve small gradient values.

This can now be achieved using Automatic Mixed Precision (AMP) for TensorFlow to enable the full mixed precision methodology in your existing TensorFlow model code. AMP enables mixed precision training on NVIDIA Volta, NVIDIA Turing, and NVIDIA Ampere GPU architectures automatically. The TensorFlow framework code makes all necessary model changes internally.

In TF-AMP, the computational graph is optimized to use as few casts as necessary and maximize the use of FP16. The loss scaling is automatically applied inside of supported optimizers. AMP can be configured to work with the existing tf.contrib loss scaling manager by disabling the AMP scaling with a single environment variable to perform only the automatic mixed-precision optimization. It accomplishes this by automatically rewriting all computation graphs with the necessary operations to enable mixed precision training and automatic loss scaling.

For information about:

Enabling AMP

Mixed precision is enabled in TensorFlow by using the Automatic Mixed Precision (TF-AMP) extension which casts variables to half-precision upon retrieval while storing variables in single-precision format. Furthermore, to preserve small gradient magnitudes in backpropagation, a loss scaling step must be included when applying gradients.

In TensorFlow, loss scaling can be applied statically by using simple multiplication of loss by a constant value or automatically, by TF-AMP. Automatic mixed precision makes all the adjustments internally in TensorFlow, providing two benefits over manual operations. First, programmers need not modify network model code, reducing development and maintenance effort. Second, using AMP maintains forward and backward compatibility with all the APIs for defining and running TensorFlow models.

To enable mixed precision, you can simply add --amp=True to the training command. This will enable the following code:

policy = tf.keras.mixed_precision.experimental.Policy('mixed_float16', loss_scale='dynamic')

TensorFloat-32 (TF32) Compute Mode

TensorFloat-32 (TF32) is the new math mode in NVIDIA A100 GPUs for handling the matrix math, also called tensor operations. TF32 running on Tensor Cores in A100 GPUs can provide up to 10x speedups compared to single-precision floating-point math (FP32) on Volta GPUs.

TF32 Tensor Cores can speed up networks using FP32, typically with no loss of accuracy. It is more robust than FP16 for models which require a high dynamic range for weights or activations.

For more information, refer to the TensorFloat-32 in the A100 GPU Accelerates AI Training, HPC up to 20x blog post.

TF32 is supported in the NVIDIA Ampere GPU architecture and is enabled by default.