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

yolox_unit_test.py 2.8 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  1. import unittest
  2. import torch
  3. from super_gradients.training.losses import YoloXDetectionLoss, YoloXFastDetectionLoss
  4. from super_gradients.training.models.detection_models.yolox import YoloX_N, YoloX_T, YoloX_S, YoloX_M, YoloX_L, YoloX_X
  5. from super_gradients.training.utils.detection_utils import DetectionCollateFN
  6. from super_gradients.training.utils.utils import HpmStruct
  7. class TestYOLOX(unittest.TestCase):
  8. def setUp(self) -> None:
  9. self.arch_params = HpmStruct(num_classes=10)
  10. self.yolo_classes = [YoloX_N, YoloX_T, YoloX_S, YoloX_M, YoloX_L, YoloX_X]
  11. def test_yolox_creation(self):
  12. """
  13. test_yolox_creation - Tests the creation of the models
  14. :return:
  15. """
  16. dummy_input = torch.randn(1, 3, 320, 320)
  17. with torch.no_grad():
  18. for yolo_cls in self.yolo_classes:
  19. yolo_model = yolo_cls(self.arch_params)
  20. # THIS SHOULD RUN THE FORWARD ONCE
  21. yolo_model.eval()
  22. output_standard = yolo_model(dummy_input)
  23. self.assertIsNotNone(output_standard)
  24. # THIS SHOULD RUN A TRAINING FORWARD
  25. yolo_model.train()
  26. output_train = yolo_model(dummy_input)
  27. self.assertIsNotNone(output_train)
  28. # THIS SHOULD RUN THE FORWARD AUGMENT
  29. yolo_model.eval()
  30. yolo_model.augmented_inference = True
  31. output_augment = yolo_model(dummy_input)
  32. self.assertIsNotNone(output_augment)
  33. def test_yolox_loss(self):
  34. samples = [
  35. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  36. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  37. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  38. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  39. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  40. ]
  41. collate = DetectionCollateFN()
  42. _, targets = collate(samples)
  43. predictions = [
  44. torch.randn((5, 1, 256 // 8, 256 // 8, 4 + 1 + 10)),
  45. torch.randn((5, 1, 256 // 16, 256 // 16, 4 + 1 + 10)),
  46. torch.randn((5, 1, 256 // 32, 256 // 32, 4 + 1 + 10)),
  47. ]
  48. for loss in [
  49. YoloXDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=True, iou_type="giou"),
  50. YoloXDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=True, iou_type="iou"),
  51. YoloXDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=False),
  52. YoloXFastDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=True),
  53. YoloXFastDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=False),
  54. ]:
  55. result = loss(predictions, targets)
  56. print(result)
  57. if __name__ == "__main__":
  58. unittest.main()
Tip!

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

Comments

Loading...