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
  1. import unittest
  2. import numpy as np
  3. import torch
  4. from super_gradients.training.datasets import DetectionDataset
  5. from super_gradients.training.utils.detection_utils import DetectionTargetsFormat
  6. class DummyDetectionDataset(DetectionDataset):
  7. def __init__(self, dataset_size, input_dim, *args, **kwargs):
  8. """Dummy Dataset testing subsampling."""
  9. self.dataset_size = dataset_size
  10. self.image_size = input_dim
  11. kwargs['all_classes_list'] = ["class_0", "class_1", "class_2"]
  12. kwargs['original_target_format'] = DetectionTargetsFormat.XYXY_LABEL
  13. super().__init__(data_dir='', input_dim=input_dim, *args, **kwargs)
  14. def _setup_data_source(self):
  15. return self.dataset_size
  16. def _load_annotation(self, sample_id: int) -> dict:
  17. """Load dummy annotation"""
  18. return {"img_path": "", "resized_img_shape": None, "target": torch.zeros(10, 6)}
  19. # DetectionDatasetV2 will call _load_image but since we don't have any image we patch this method with
  20. # tensor of image shape
  21. def _load_image(self, index: int) -> np.ndarray:
  22. return np.random.random(self.image_size)
  23. class TestDetectionDatasetSubsampling(unittest.TestCase):
  24. def test_subsampling(self):
  25. """Check that subsampling works"""
  26. for max_num_samples in [1, 1_000, 1_000_000]:
  27. test_dataset = DummyDetectionDataset(dataset_size=100_000, input_dim=(640, 512), max_num_samples=max_num_samples)
  28. self.assertEqual(len(test_dataset), min(max_num_samples, 100_000))
  29. if __name__ == '__main__':
  30. unittest.main()
Discard
Tip!

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