Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:NVIDIA DALI EfficientDet Layers

From Leeroopedia


Knowledge Sources
Domains Object_Detection, TensorFlow
Last Updated 2026-02-08 16:00 GMT

Overview

Implements custom Keras layers for the EfficientDet architecture, including BiFPN feature fusion nodes, feature resampling, and classification/box prediction networks.

Description

This module provides the building-block Keras layers that compose the EfficientDet feature pyramid and prediction heads. The `FNode` layer implements a single BiFPN (Bi-directional Feature Pyramid Network) node that fuses features from multiple resolution levels using configurable weighting methods: standard attention ('attn'), fast attention ('fastattn'), channel-wise attention ('channel_attn'), channel-wise fast attention ('channel_fastattn'), or unweighted sum ('sum'). Each FNode resamples its input features to a common resolution and applies weighted fusion followed by a convolution-batchnorm-activation pattern.

The `OpAfterCombine` layer applies post-fusion operations (activation, convolution, batch normalization) with support for separable convolutions. The `ResampleFeatureMap` layer handles spatial resolution changes between feature levels through pooling (max or average) for downsampling and nearest-neighbor or bilinear interpolation for upsampling, with optional 1x1 convolution for channel alignment and batch normalization.

The `ClassNet` and `BoxNet` layers implement the classification and box regression prediction heads respectively. Both use repeated separable (or standard) convolution layers with shared weights across feature levels, followed by level-specific batch normalization. ClassNet outputs class predictions for each anchor, while BoxNet outputs 4-coordinate box regression values per anchor. Both support drop connect for regularization and gradient checkpointing for memory efficiency. The `FPNCells` layer stacks multiple FPN repeats to form the complete feature pyramid.

Usage

These layers are used internally by the `EfficientDetNet` model class. They are not typically instantiated directly by users but are composed within the model constructor to build the complete detection architecture.

Code Reference

Source Location

Signature

class FNode(tf.keras.layers.Layer):
    def __init__(self, feat_level, inputs_offsets, fpn_num_filters,
                 apply_bn_for_resampling, conv_after_downsample,
                 conv_bn_act_pattern, separable_conv, act_type,
                 weight_method, data_format, name="fnode"): ...
    def fuse_features(self, nodes) -> tf.Tensor: ...
    def call(self, feats, training) -> list: ...

class OpAfterCombine(tf.keras.layers.Layer):
    def __init__(self, conv_bn_act_pattern, separable_conv, fpn_num_filters,
                 act_type, data_format, name="op_after_combine"): ...
    def call(self, new_node, training) -> tf.Tensor: ...

class ResampleFeatureMap(tf.keras.layers.Layer):
    def __init__(self, feat_level, target_num_channels, apply_bn=False,
                 conv_after_downsample=False, data_format=None,
                 pooling_type=None, upsampling_type=None, name="resample_p0"): ...
    def call(self, feat, training, all_feats) -> tf.Tensor: ...

class ClassNet(tf.keras.layers.Layer):
    def __init__(self, num_classes=90, num_anchors=9, num_filters=32,
                 min_level=3, max_level=7, act_type="swish", repeats=4,
                 separable_conv=True, survival_prob=None,
                 data_format="channels_last", grad_checkpoint=False,
                 name="class_net", **kwargs): ...
    def call(self, inputs, training, **kwargs) -> list: ...

class BoxNet(tf.keras.layers.Layer):
    def __init__(self, num_anchors=9, num_filters=32, min_level=3,
                 max_level=7, act_type="swish", repeats=4,
                 separable_conv=True, survival_prob=None,
                 data_format="channels_last", grad_checkpoint=False,
                 name="box_net", **kwargs): ...
    def call(self, inputs, training) -> list: ...

class FPNCells(tf.keras.layers.Layer):
    def __init__(self, config, name="fpn_cells"): ...
    def call(self, feats, training) -> list: ...

Import

from model.utils import layers

# Used internally by EfficientDetNet:
class_net = layers.ClassNet(num_classes=91, num_anchors=9, num_filters=88)
box_net = layers.BoxNet(num_anchors=9, num_filters=88)

I/O Contract

Inputs

Name Type Required Description
feats list[tf.Tensor] Yes List of feature tensors at different FPN levels
training bool Yes Whether the model is in training mode
inputs (ClassNet/BoxNet) list[tf.Tensor] Yes Multi-level feature maps from FPN
num_classes int No Number of object classes (default: 90)
num_anchors int No Number of anchors per spatial location (default: 9)
weight_method str No Feature fusion weighting: 'attn', 'fastattn', 'sum', etc.

Outputs

Name Type Description
fused_feats list[tf.Tensor] Fused multi-scale features from FPN
class_outputs list[tf.Tensor] Per-level classification predictions [batch, H, W, num_anchors * num_classes]
box_outputs list[tf.Tensor] Per-level box regression predictions [batch, H, W, num_anchors * 4]

Usage Examples

Build BiFPN Feature Fusion

from model.utils import layers

# Create FPN cells from config
fpn = layers.FPNCells(config)

# Run feature fusion
fused_features = fpn(backbone_features, training=True)

# Run prediction heads
class_outputs = class_net(fused_features, training=True)
box_outputs = box_net(fused_features, training=True)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment