Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

#869 Add DagsHub Logger to Super Gradients

Merged
Ghost merged 1 commits into Deci-AI:master from timho102003:dagshub_logger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  1. from typing import Optional
  2. import torch
  3. from torch import Tensor
  4. __all__ = ["batch_distance2bbox"]
  5. def batch_distance2bbox(points: Tensor, distance: Tensor, max_shapes: Optional[Tensor] = None) -> Tensor:
  6. """Decode distance prediction to bounding box for batch.
  7. :param points: [B, ..., 2], "xy" format
  8. :param distance: [B, ..., 4], "ltrb" format
  9. :param max_shapes: [B, 2], "h,w" format, Shape of the image.
  10. :return: Tensor: Decoded bboxes, "x1y1x2y2" format.
  11. """
  12. lt, rb = torch.split(distance, 2, dim=-1)
  13. # while tensor add parameters, parameters should be better placed on the second place
  14. x1y1 = -lt + points
  15. x2y2 = rb + points
  16. out_bbox = torch.cat([x1y1, x2y2], dim=-1)
  17. if max_shapes is not None:
  18. max_shapes = max_shapes.flip(-1).tile([1, 2])
  19. delta_dim = out_bbox.ndim - max_shapes.ndim
  20. for _ in range(delta_dim):
  21. max_shapes.unsqueeze_(1)
  22. out_bbox = torch.where(out_bbox < max_shapes, out_bbox, max_shapes)
  23. out_bbox = torch.where(out_bbox > 0, out_bbox, torch.zeros_like(out_bbox))
  24. return out_bbox
Discard
Tip!

Press p or to see the previous file or, n or to see the next file