MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / OKSLoss

Class OKSLoss

models/aios/utils.py:270–356  ·  view source on GitHub ↗

IoULoss. Computing the oks loss between a set of predicted poses and target poses. Args: linear (bool): If True, use linear scale of loss instead of log scale. Default: False. eps (float): Eps to avoid log(0). reduction (str): Options are "none", "mean" a

Source from the content-addressed store, hash-verified

268
269
270class OKSLoss(nn.Module):
271 """IoULoss.
272
273 Computing the oks loss between a set of predicted poses and target poses.
274 Args:
275 linear (bool): If True, use linear scale of loss instead of log scale.
276 Default: False.
277 eps (float): Eps to avoid log(0).
278 reduction (str): Options are "none", "mean" and "sum".
279 loss_weight (float): Weight of loss.
280 """
281 def __init__(self,
282 linear=False,
283 num_keypoints=17,
284 eps=1e-6,
285 reduction='mean',
286 loss_weight=1.0):
287 super(OKSLoss, self).__init__()
288 self.linear = linear
289 self.eps = eps
290 self.reduction = reduction
291 self.loss_weight = loss_weight
292 if num_keypoints == 17:
293 self.sigmas = np.array([
294 .26, .25, .25, .35, .35, .79, .79, .72, .72, .62, .62, 1.07,
295 1.07, .87, .87, .89, .89
296 ],
297 dtype=np.float32) / 10.0
298 elif num_keypoints == 14:
299 self.sigmas = np.array([
300 .79, .79, .72, .72, .62, .62, 1.07, 1.07, .87, .87, .89, .89,
301 .79, .79
302 ]) / 10.0
303 elif num_keypoints == 6:
304 self.sigmas = np.array(
305 [
306 .25,.25,.25,.25,.25,.25
307 ], dtype=np.float32
308 )/ 10.0
309 else:
310 raise ValueError(f'Unsupported keypoints number {num_keypoints}')
311
312 def forward(self,
313 pred,
314 target,
315 valid,
316 area,
317 weight=None,
318 avg_factor=None,
319 reduction_override=None):
320 """Forward function.
321
322 Args:
323 pred (torch.Tensor): The prediction.
324 target (torch.Tensor): The learning target of the prediction.
325 valid (torch.Tensor): The visible flag of the target pose.
326 area (torch.Tensor): The area of the target pose.
327 weight (torch.Tensor, optional): The weight of loss for each

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected