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

#344 Feature/sg 255 add class for supported strings

Merged
Ghost merged 1 commits into Deci-AI:master from deci-ai:feature/SG-255-add_class_for_supported_strings
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 csv
  2. import os
  3. from super_gradients.training.datasets.segmentation_datasets.segmentation_dataset import SegmentationDataSet
  4. class SuperviselyPersonsDataset(SegmentationDataSet):
  5. """
  6. SuperviselyPersonsDataset - Segmentation Data Set Class for Supervisely Persons Segmentation Data Set,
  7. main resolution of dataset: (600 x 800).
  8. This dataset is a subset of the original dataset (see below) and contains filtered samples
  9. For more details about the ORIGINAL dataset see: https://app.supervise.ly/ecosystem/projects/persons
  10. For more details about the FILTERED dataset see:
  11. https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.3/contrib/PP-HumanSeg
  12. """
  13. CLASS_LABELS = {0: "background", 1: "person"}
  14. def __init__(self, root_dir: str, list_file: str, **kwargs):
  15. """
  16. :param root_dir: root directory to dataset.
  17. :param list_file: list file that contains names of images to load, line format: <image_path>,<mask_path>
  18. :param kwargs: Any hyper params required for the dataset, i.e img_size, crop_size, etc...
  19. """
  20. super().__init__(root=root_dir, list_file=list_file, **kwargs)
  21. self.classes = ['person']
  22. def _generate_samples_and_targets(self):
  23. with open(os.path.join(self.root, self.list_file_path), 'r', encoding="utf-8") as file:
  24. reader = csv.reader(file)
  25. for row in reader:
  26. sample_path = os.path.join(self.root, row[0])
  27. target_path = os.path.join(self.root, row[1])
  28. if self._validate_file(sample_path) \
  29. and self._validate_file(target_path) \
  30. and os.path.exists(sample_path) \
  31. and os.path.exists(target_path):
  32. self.samples_targets_tuples_list.append((sample_path, target_path))
  33. else:
  34. raise AssertionError(f"Sample and/or target file(s) not found or in illegal format "
  35. f"(sample path: {sample_path}, target path: {target_path})")
  36. super(SuperviselyPersonsDataset, self)._generate_samples_and_targets()
Discard
Tip!

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