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

detection_utils_test.py 1.6 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
  1. import os
  2. import unittest
  3. from super_gradients.training import Trainer, utils as core_utils, models
  4. from super_gradients.training.dataloaders.dataloaders import coco2017_val
  5. from super_gradients.training.datasets.datasets_conf import COCO_DETECTION_CLASSES_LIST
  6. from super_gradients.training.models.detection_models.yolo_base import YoloPostPredictionCallback
  7. from super_gradients.training.utils.detection_utils import DetectionVisualization
  8. class TestDetectionUtils(unittest.TestCase):
  9. def test_visualization(self):
  10. # Create Yolo model
  11. trainer = Trainer("visualization_test")
  12. model = models.get("yolox_n", pretrained_weights="coco")
  13. post_prediction_callback = YoloPostPredictionCallback()
  14. # Simulate one iteration of validation subset
  15. valid_loader = coco2017_val()
  16. batch_i, (imgs, targets) = 0, next(iter(valid_loader))
  17. imgs = core_utils.tensor_container_to_device(imgs, trainer.device)
  18. targets = core_utils.tensor_container_to_device(targets, trainer.device)
  19. output = model(imgs)
  20. output = post_prediction_callback(output)
  21. # Visualize the batch
  22. DetectionVisualization.visualize_batch(imgs, output, targets, batch_i, COCO_DETECTION_CLASSES_LIST, trainer.checkpoints_dir_path)
  23. # Assert images ware created and delete them
  24. img_name = "{}/{}_{}.jpg"
  25. for i in range(4):
  26. img_path = img_name.format(trainer.checkpoints_dir_path, batch_i, i)
  27. self.assertTrue(os.path.exists(img_path))
  28. os.remove(img_path)
  29. if __name__ == "__main__":
  30. unittest.main()
Tip!

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

Comments

Loading...