MCPcopy Create free account
hub / github.com/InternRobotics/EmbodiedScan / BBoxCDLoss

Class BBoxCDLoss

embodiedscan/models/losses/chamfer_distance.py:207–285  ·  view source on GitHub ↗

Calculate Chamfer Distance of the corners for two bbox sets. Args: mode (str): Criterion mode to calculate distance. The valid modes are 'smooth_l1', 'l1' or 'l2'. Defaults to 'l2'. group (str): How corners are grouped. The valid groups are 'g8' or 'g4',

Source from the content-addressed store, hash-verified

205
206@MODELS.register_module()
207class BBoxCDLoss(nn.Module):
208 """Calculate Chamfer Distance of the corners for two bbox sets.
209
210 Args:
211 mode (str): Criterion mode to calculate distance.
212 The valid modes are 'smooth_l1', 'l1' or 'l2'. Defaults to 'l2'.
213 group (str): How corners are grouped.
214 The valid groups are 'g8' or 'g4',
215 meaning either all 8 corners are in a single group
216 or the corners are divided into two groups, each containing 4.
217 reduction (str): Method to reduce losses.
218 The valid reduction method are 'none', 'sum' or 'mean'.
219 Defaults to 'mean'.
220 loss_weight (float): Weight of loss. Defaults to l.0.
221 """
222
223 def __init__(
224 self,
225 mode: str = 'l2',
226 group: str = 'g8',
227 reduction: str = 'mean',
228 loss_weight: float = 1.0,
229 ) -> None:
230 super(BBoxCDLoss, self).__init__()
231
232 assert mode in ['smooth_l1', 'l1', 'l2']
233 assert group in ['g4', 'g8']
234 assert reduction in ['none', 'sum', 'mean']
235 self.mode = mode
236 self.group = group
237 self.reduction = reduction
238 self.loss_weight = loss_weight
239
240 def forward(self,
241 source: Tensor,
242 target: Tensor,
243 loss_weight: Union[Tensor, float] = 1.0,
244 reduction_override: Optional[str] = None,
245 **kwargs) -> Tensor:
246 """Forward function of loss calculation.
247
248 Args:
249 source (Tensor): Source bbox set with shape [N, bbox_dim] to
250 calculate Chamfer Distance.
251 target (Tensor): Destination bbox set with shape [M, bbox_dim] to
252 calculate Chamfer Distance.
253 loss_weight (Tensor | float):
254 Weight of loss. Defaults to 1.0.
255 reduction_override (str, optional): Method to reduce losses.
256 The valid reduction method are 'none', 'sum' or 'mean'.
257 Defaults to None.
258
259 Returns:
260 Tensor: return ``loss_source``.
261 """
262 assert reduction_override in (None, 'none', 'mean', 'sum')
263 reduction = (reduction_override
264 if reduction_override else self.reduction)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected