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

post_prediction_callback_test.py 1.9 KB

You have to be logged in to leave a comment. Sign In
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
  1. import unittest
  2. import torch
  3. from super_gradients.training import models
  4. from super_gradients.training.models.detection_models.yolo_base import YoloPostPredictionCallback
  5. class TestPostPredictionCallback(unittest.TestCase):
  6. def _default_yolo_post_prediction_callback(self):
  7. """
  8. Use low confidence to force a non-empty nms result.
  9. """
  10. return YoloPostPredictionCallback(conf=1e-6)
  11. def _default_mock_decoded_output(self):
  12. """
  13. mock output tensor after a final decode module, i.e DetectX, with shapes [B, Num anchors, 5 + num_classes]
  14. """
  15. return torch.cat([torch.randn(1, 500, 4), torch.sigmoid(torch.randn(1, 500, 81))], dim=2) # localization # classification scores
  16. def test_yolo_post_prediction_callback_single_input(self):
  17. callback = self._default_yolo_post_prediction_callback()
  18. mock_single_model_output = self._default_mock_decoded_output()
  19. _ = callback(mock_single_model_output)
  20. def test_yolo_post_prediction_callback_multiple_input(self):
  21. callback = self._default_yolo_post_prediction_callback()
  22. mock_multiple_model_outputs = [self._default_mock_decoded_output(), [torch.randn(1, 1, 10, 10, 85), torch.randn(1, 1, 20, 20, 85)]] # mock logits
  23. # sanity check multiple input as list
  24. _ = callback(mock_multiple_model_outputs)
  25. # sanity check multiple input as tuple
  26. _ = callback(tuple(mock_multiple_model_outputs))
  27. def test_yolo_post_prediction_callback_yolox_output(self):
  28. """
  29. Sanity check for yolox usage with YoloPostPredictionCallback.
  30. """
  31. callback = self._default_yolo_post_prediction_callback()
  32. model = models.get(model_name="yolox_s", num_classes=80).eval()
  33. x = torch.randn(1, 3, 320, 320)
  34. output = model(x)
  35. _ = callback(output)
  36. if __name__ == "__main__":
  37. unittest.main()
Tip!

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

Comments

Loading...