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

#581 Bug/sg 512 shuffle bugfix in recipe datalaoders

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:bug/SG-512_shuffle_bugfix_in_recipe_datalaoders
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  1. from typing import Tuple
  2. import numpy as np
  3. import torch
  4. from super_gradients.training.utils.bbox_formats.bbox_format import BoundingBoxFormat
  5. __all__ = ["YXYXCoordinateFormat", "xyxy_to_yxyx", "xyxy_to_yxyx_inplace"]
  6. def xyxy_to_yxyx(bboxes, image_shape: Tuple[int, int]):
  7. if torch.jit.is_scripting():
  8. bboxes = torch.moveaxis(bboxes, -1, 0)
  9. bboxes = bboxes[torch.tensor([1, 0, 3, 2], dtype=torch.long, device=bboxes.device)]
  10. bboxes = torch.moveaxis(bboxes, 0, 1)
  11. return bboxes
  12. else:
  13. if torch.is_tensor(bboxes):
  14. return bboxes[..., torch.tensor([1, 0, 3, 2], dtype=torch.long, device=bboxes.device)]
  15. elif isinstance(bboxes, np.ndarray):
  16. return bboxes[..., np.array([1, 0, 3, 2], dtype=int)]
  17. else:
  18. raise RuntimeError(f"Only Torch tensor or Numpy array is supported. Received bboxes of type {str(type(bboxes))}")
  19. def xyxy_to_yxyx_inplace(bboxes, image_shape: Tuple[int, int]):
  20. x1x2 = bboxes[..., 0:3:2]
  21. y1y2 = bboxes[..., 1:4:2]
  22. sum = x1x2 + y1y2 # Swap via sum
  23. bboxes[..., 0:3:2] = sum - x1x2
  24. bboxes[..., 1:4:2] = sum - y1y2
  25. return bboxes
  26. class YXYXCoordinateFormat(BoundingBoxFormat):
  27. """
  28. Bounding boxes format Y1, X1, Y2, X1
  29. """
  30. def __init__(self):
  31. super().__init__()
  32. self.format = "yxyx"
  33. self.normalized = False
  34. def get_to_xyxy(self, inplace: bool):
  35. if inplace:
  36. return xyxy_to_yxyx_inplace
  37. else:
  38. return xyxy_to_yxyx
  39. def get_from_xyxy(self, inplace: bool):
  40. # XYXY <-> YXYX is interchangable operation, so we may reuse same routine here
  41. if inplace:
  42. return xyxy_to_yxyx_inplace
  43. else:
  44. return xyxy_to_yxyx
Discard
Tip!

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