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 Preprocessor

From Leeroopedia
Revision as of 15:54, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/NVIDIA_DALI_EfficientDet_Preprocessor.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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

Overview

Provides image and bounding box preprocessing functions for EfficientDet detection training, including random horizontal flipping, keypoint manipulation, and multi-scale resizing.

Description

This module implements preprocessing operations for object detection that are applied to images, bounding boxes, instance masks, and keypoints. It distinguishes between operations applied universally (both training and evaluation) and augmentation operations applied only during training.

The core augmentation function is `random_horizontal_flip()`, which randomly mirrors images and their associated annotations with 50% probability. It correctly transforms bounding box coordinates by flipping x-coordinates around the image center, mirrors instance masks along the width axis, and permutes keypoints according to a provided flip permutation (e.g., swapping left_eye and right_eye). All coordinate transformations preserve the normalized [0, 1] coordinate space.

Additional utility functions include `_flip_boxes_left_right()` for deterministic box flipping, `_flip_masks_left_right()` for mask flipping, and `keypoint_flip_horizontal()` for keypoint flipping with permutation. The module also provides `resize_to_range()` for resizing images (and optionally masks) such that the smallest dimension meets a minimum size constraint while the largest dimension does not exceed a maximum, with support for both static and dynamic shape computation. Helper functions `_compute_new_static_size()` and `_compute_new_dynamic_size()` handle the two cases respectively.

The module also includes `box_list_scale()` for scaling box coordinates and various box list utility functions used during the detection preprocessing pipeline. All operations use TensorFlow 1.x compatibility APIs (`tf.compat.v1`).

Usage

Use these functions within the EfficientDet data loading pipeline to apply training augmentations to images and annotations. The functions are called by `DetectionInputProcessor` in the dataloader module during dataset construction.

Code Reference

Source Location

Signature

def random_horizontal_flip(
    image,
    boxes=None,
    masks=None,
    keypoints=None,
    keypoint_flip_permutation=None,
    seed=None,
) -> tuple:
    ...

def _flip_boxes_left_right(boxes) -> tf.Tensor:
    ...

def _flip_masks_left_right(masks) -> tf.Tensor:
    ...

def keypoint_flip_horizontal(keypoints, flip_point, flip_permutation, scope=None) -> tf.Tensor:
    ...

def resize_to_range(
    image,
    masks=None,
    min_dimension=None,
    max_dimension=None,
    method=tf.image.ResizeMethod.BILINEAR,
    align_corners=False,
    pad_to_max_dimension=False,
) -> tuple:
    ...

def _compute_new_static_size(image, min_dimension, max_dimension) -> tf.Tensor:
    ...

def _compute_new_dynamic_size(image, min_dimension, max_dimension) -> tf.Tensor:
    ...

Import

from pipeline.tf import preprocessor

# Apply random horizontal flip
image, boxes = preprocessor.random_horizontal_flip(image, boxes=boxes)

I/O Contract

Inputs

Name Type Required Description
image tf.Tensor Yes Rank 3 float32 tensor [height, width, channels]
boxes tf.Tensor No Rank 2 float32 tensor [N, 4] with normalized [ymin, xmin, ymax, xmax] coordinates
masks tf.Tensor No Rank 3 float32 tensor [num_instances, height, width] instance masks
keypoints tf.Tensor No Rank 3 float32 tensor [num_instances, num_keypoints, 2] in y-x normalized coordinates
keypoint_flip_permutation tf.Tensor No Rank 1 int32 tensor specifying keypoint index remapping after flip
seed int No Random seed for reproducibility
min_dimension int No Minimum dimension for resize_to_range
max_dimension int No Maximum dimension for resize_to_range

Outputs

Name Type Description
image tf.Tensor Preprocessed image tensor (same rank as input)
boxes tf.Tensor Transformed bounding boxes (if provided)
masks tf.Tensor Transformed instance masks (if provided)
keypoints tf.Tensor Transformed keypoints (if provided)

Usage Examples

Apply Training Augmentations

from pipeline.tf import preprocessor

# Random horizontal flip with boxes
image, boxes = preprocessor.random_horizontal_flip(
    image, boxes=boxes, seed=42
)

# Resize to range while preserving aspect ratio
image, masks = preprocessor.resize_to_range(
    image,
    masks=masks,
    min_dimension=640,
    max_dimension=1024,
)

Related Pages

Page Connections

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