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

#367 fix: Request correct hydra-core

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:hotfix/ALG-000_hydra-req
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  1. import numpy as np
  2. import unittest
  3. from super_gradients.training.transforms.transforms import DetectionTargetsFormatTransform
  4. from super_gradients.training.utils.detection_utils import DetectionTargetsFormat
  5. class DetectionTargetsTransformTest(unittest.TestCase):
  6. def setUp(self) -> None:
  7. self.image = np.zeros((3, 100, 200))
  8. def test_label_first_2_label_last(self):
  9. input = np.array([[10, 20, 30, 40, 50]], dtype=np.float32)
  10. output = np.array([[50, 10, 20, 30, 40]], dtype=np.float32)
  11. transform = DetectionTargetsFormatTransform(max_targets=1,
  12. input_format=DetectionTargetsFormat.XYXY_LABEL,
  13. output_format=DetectionTargetsFormat.LABEL_XYXY)
  14. sample = {"image": self.image, "target": input}
  15. self.assertTrue(np.array_equal(transform(sample)["target"], output))
  16. def test_xyxy_2_normalized_xyxy(self):
  17. input = np.array([[10, 20, 30, 40, 50]], dtype=np.float32)
  18. _, h, w = self.image.shape
  19. output = np.array([[10, 20 / w, 30 / h, 40 / w, 50 / h]], dtype=np.float32)
  20. transform = DetectionTargetsFormatTransform(max_targets=1,
  21. input_format=DetectionTargetsFormat.LABEL_XYXY,
  22. output_format=DetectionTargetsFormat.LABEL_NORMALIZED_XYXY)
  23. sample = {"image": self.image, "target": input}
  24. t_output = transform(sample)["target"]
  25. self.assertTrue(np.array_equal(output, t_output))
  26. def test_xyxy_2_cxcywh(self):
  27. input = np.array([[10, 20, 30, 40, 50]], dtype=np.float32)
  28. _, h, w = self.image.shape
  29. output = np.array([[10, 30, 40, 20, 20]], dtype=np.float32)
  30. transform = DetectionTargetsFormatTransform(max_targets=1,
  31. input_format=DetectionTargetsFormat.LABEL_XYXY,
  32. output_format=DetectionTargetsFormat.LABEL_CXCYWH)
  33. sample = {"image": self.image, "target": input}
  34. t_output = transform(sample)["target"]
  35. self.assertTrue(np.array_equal(output, t_output))
  36. def test_xyxy_2_normalized_cxcywh(self):
  37. input = np.array([[10, 20, 30, 40, 50]], dtype=np.float32)
  38. _, h, w = self.image.shape
  39. output = np.array([[10, 30 / w, 40 / h, 20 / w, 20 / h]], dtype=np.float32)
  40. transform = DetectionTargetsFormatTransform(max_targets=1,
  41. input_format=DetectionTargetsFormat.LABEL_XYXY,
  42. output_format=DetectionTargetsFormat.LABEL_NORMALIZED_CXCYWH)
  43. sample = {"image": self.image, "target": input}
  44. t_output = transform(sample)["target"]
  45. self.assertTrue(np.array_equal(output, t_output))
  46. def test_normalized_xyxy_2_cxcywh(self):
  47. _, h, w = self.image.shape
  48. input = np.array([[10, 20 / w, 30 / h, 40 / w, 50 / h]], dtype=np.float32)
  49. output = np.array([[10, 30, 40, 20, 20]], dtype=np.float32)
  50. transform = DetectionTargetsFormatTransform(max_targets=1,
  51. input_format=DetectionTargetsFormat.LABEL_NORMALIZED_XYXY,
  52. output_format=DetectionTargetsFormat.LABEL_CXCYWH)
  53. sample = {"image": self.image, "target": input}
  54. t_output = transform(sample)["target"]
  55. self.assertTrue(np.allclose(output, t_output))
  56. def test_normalized_xyxy_2_normalized_cxcywh(self):
  57. _, h, w = self.image.shape
  58. input = np.array([[10, 20 / w, 30 / h, 40 / w, 50 / h]], dtype=np.float32)
  59. output = np.array([[10, 30 / w, 40 / h, 20 / w, 20 / h]], dtype=np.float32)
  60. transform = DetectionTargetsFormatTransform(max_targets=1,
  61. input_format=DetectionTargetsFormat.LABEL_NORMALIZED_XYXY,
  62. output_format=DetectionTargetsFormat.LABEL_NORMALIZED_CXCYWH)
  63. sample = {"image": self.image, "target": input}
  64. t_output = transform(sample)["target"]
  65. self.assertTrue(np.allclose(output, t_output))
  66. def test_cxcywh_2_xyxy(self):
  67. output = np.array([[10, 20, 30, 40, 50]], dtype=np.float32)
  68. input = np.array([[10, 30, 40, 20, 20]], dtype=np.float32)
  69. transform = DetectionTargetsFormatTransform(max_targets=1,
  70. input_format=DetectionTargetsFormat.LABEL_CXCYWH,
  71. output_format=DetectionTargetsFormat.LABEL_XYXY)
  72. sample = {"image": self.image, "target": input}
  73. t_output = transform(sample)["target"]
  74. self.assertTrue(np.array_equal(output, t_output))
  75. def test_cxcywh_2_normalized_xyxy(self):
  76. _, h, w = self.image.shape
  77. output = np.array([[10, 20 / w, 30 / h, 40 / w, 50 / h]], dtype=np.float32)
  78. input = np.array([[10, 30, 40, 20, 20]], dtype=np.float32)
  79. transform = DetectionTargetsFormatTransform(max_targets=1,
  80. input_format=DetectionTargetsFormat.LABEL_CXCYWH,
  81. output_format=DetectionTargetsFormat.LABEL_NORMALIZED_XYXY)
  82. sample = {"image": self.image, "target": input}
  83. t_output = transform(sample)["target"]
  84. self.assertTrue(np.array_equal(output, t_output))
  85. def test_normalized_cxcywh_2_xyxy(self):
  86. _, h, w = self.image.shape
  87. input = np.array([[10, 30 / w, 40 / h, 20 / w, 20 / h]], dtype=np.float32)
  88. output = np.array([[10, 20, 30, 40, 50]], dtype=np.float32)
  89. transform = DetectionTargetsFormatTransform(max_targets=1,
  90. input_format=DetectionTargetsFormat.LABEL_NORMALIZED_CXCYWH,
  91. output_format=DetectionTargetsFormat.LABEL_XYXY)
  92. sample = {"image": self.image, "target": input}
  93. t_output = transform(sample)["target"]
  94. self.assertTrue(np.allclose(output, t_output))
  95. def test_normalized_cxcywh_2_normalized_xyxy(self):
  96. _, h, w = self.image.shape
  97. output = np.array([[10, 20 / w, 30 / h, 40 / w, 50 / h]], dtype=np.float32)
  98. input = np.array([[10, 30 / w, 40 / h, 20 / w, 20 / h]], dtype=np.float32)
  99. transform = DetectionTargetsFormatTransform(max_targets=1,
  100. input_format=DetectionTargetsFormat.LABEL_NORMALIZED_CXCYWH,
  101. output_format=DetectionTargetsFormat.LABEL_NORMALIZED_XYXY)
  102. sample = {"image": self.image, "target": input}
  103. t_output = transform(sample)["target"]
  104. self.assertTrue(np.allclose(output, t_output))
  105. if __name__ == '__main__':
  106. unittest.main()
Discard
Tip!

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