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 3.1 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
74
  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. self.devices = ["cpu", "cuda"] if torch.cuda.is_available() else ["cpu"]
  12. def test_yolox_creation(self):
  13. """
  14. test_yolox_creation - Tests the creation of the models
  15. :return:
  16. """
  17. for device in self.devices:
  18. dummy_input = torch.randn(1, 3, 320, 320).to(device)
  19. with torch.no_grad():
  20. for yolo_cls in self.yolo_classes:
  21. yolo_model = yolo_cls(self.arch_params).to(device)
  22. # THIS SHOULD RUN THE FORWARD ONCE
  23. yolo_model.eval()
  24. output_standard = yolo_model(dummy_input)
  25. self.assertIsNotNone(output_standard)
  26. # THIS SHOULD RUN A TRAINING FORWARD
  27. yolo_model.train()
  28. output_train = yolo_model(dummy_input)
  29. self.assertIsNotNone(output_train)
  30. # THIS SHOULD RUN THE FORWARD AUGMENT
  31. yolo_model.eval()
  32. yolo_model.augmented_inference = True
  33. output_augment = yolo_model(dummy_input)
  34. self.assertIsNotNone(output_augment)
  35. def test_yolox_loss(self):
  36. samples = [
  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. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  41. (torch.zeros((3, 256, 256)), torch.zeros((100, 5))),
  42. ]
  43. collate = DetectionCollateFN()
  44. _, targets = collate(samples)
  45. for device in self.devices:
  46. predictions = [
  47. torch.randn((5, 1, 256 // 8, 256 // 8, 4 + 1 + 10)).to(device),
  48. torch.randn((5, 1, 256 // 16, 256 // 16, 4 + 1 + 10)).to(device),
  49. torch.randn((5, 1, 256 // 32, 256 // 32, 4 + 1 + 10)).to(device),
  50. ]
  51. for loss in [
  52. YoloXDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=True, iou_type="giou"),
  53. YoloXDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=True, iou_type="iou"),
  54. YoloXDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=False),
  55. YoloXFastDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=True),
  56. YoloXFastDetectionLoss(strides=[8, 16, 32], num_classes=10, use_l1=False),
  57. ]:
  58. result = loss(predictions, targets.to(device))
  59. print(result)
  60. if __name__ == "__main__":
  61. unittest.main()
Tip!

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

Comments

Loading...