detrium.nn.decoders.dfine_utils

Copyright (c) 2024 The D-FINE Authors. All Rights Reserved.

weighting_function(reg_max, up, reg_scale, deploy=False)

Generates the non-uniform Weighting Function W(n) for bounding box regression. Args: reg_max (int): Max number of the discrete bins. up (Tensor): Controls upper bounds of the sequence, where maximum offset is ±up * H / W. reg_scale (float): Controls the curvature of the Weighting Function. Larger values result in flatter weights near the central axis W(reg_max/2)=0 and steeper weights at both ends. deploy (bool): If True, uses deployment mode settings. Returns: Tensor: Sequence of Weighting Function.

名称类型默认值
reg_max——
up——
reg_scale——
deploy—False
translate_gt(gt, reg_max, reg_scale, up)

Decodes bounding box ground truth (GT) values into distribution-based GT representations. This function maps continuous GT values into discrete distribution bins, which can be used for regression tasks in object detection models. It calculates the indices of the closest bins to each GT value and assigns interpolation weights to these bins based on their proximity to the GT value. Args: gt (Tensor): Ground truth bounding box values, shape (N, ). reg_max (int): Maximum number of discrete bins for the distribution. reg_scale (float): Controls the curvature of the Weighting Function. up (Tensor): Controls the upper bounds of the Weighting Function. Returns: Tuple[Tensor, Tensor, Tensor]: - indices (Tensor): Index of the left bin closest to each GT value, shape (N, ). - weight_right (Tensor): Weight assigned to the right bin, shape (N, ). - weight_left (Tensor): Weight assigned to the left bin, shape (N, ).

名称类型默认值
gt——
reg_max——
reg_scale——
up——
distance2bbox(points, distance, reg_scale)

Decodes edge-distances into bounding box coordinates [cx, cy, w, h].

名称类型默认值
points——
distance——
reg_scale——
bbox2distance(points, bbox, reg_max, reg_scale, up, eps=0.1)

Converts bounding box coordinates to distances from a reference point. Args: points (Tensor): (n, 4) [x, y, w, h], where (x, y) is the center. bbox (Tensor): (n, 4) bounding boxes in "xyxy" format. reg_max (float): Maximum bin value. reg_scale (float): Controling curvarture of W(n). up (Tensor): Controling upper bounds of W(n). eps (float): Small value to ensure target < reg_max. Returns: Tensor: Decoded distances.

名称类型默认值
points——
bbox——
reg_max——
reg_scale——
up——
eps—0.1