ImageElement.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. class ImageElement:
  2. def __init__(
  3. self,
  4. path_image_initial: str,
  5. path_label_initial: str,
  6. img_width: int,
  7. img_height: int,
  8. image_id: int,
  9. type_data: str,
  10. path_label_final: str,
  11. path_image_final: str,
  12. classes_names: list,
  13. classes_ids: list,
  14. point_list: list,
  15. ) -> None:
  16. self.path_image_initial = path_image_initial # path to the original image
  17. self.path_label_initial = path_label_initial # path to the original COCO json with its data
  18. self.img_width = img_width
  19. self.img_height = img_height
  20. self.image_id = image_id # image id according to COCO
  21. self.type_data = type_data # type of data (train, test, valid)
  22. self.path_label_final = path_label_final # path to the final YOLO label
  23. self.path_image_final = path_image_final # path to the final YOLO image format
  24. # List of class names ex: [car, car, car, dog] - 3 objects of class car and 1 object of class dog:
  25. self.classes_names = classes_names
  26. # List of class numbers from 0 to N-1 ex: [0, 0, 0, 1] - 3 objects of class 0 and 1 object of class 1:
  27. self.classes_ids = classes_ids
  28. # List of lists of points ex [[x, y, x, y, x, y], [x, y, x, y, x, y]] length equals the number of objects in the photo:
  29. self.point_list = point_list
  30. def __str__(self):
  31. # Converting each segmentation to the number of points
  32. segmentations_lengths = [len(segmentation) // 2 for segmentation in self.point_list]
  33. return (
  34. f"ImageElement info:\n"
  35. f" - path_image_initial: {self.path_image_initial}\n"
  36. f" - path_label_initial: {self.path_label_initial}\n"
  37. f" - img_width: {self.img_width}\n"
  38. f" - img_height: {self.img_height}\n"
  39. f" - image_id: {self.image_id}\n"
  40. f" - type_data: {self.type_data}\n"
  41. f" - path_label_final: {self.path_label_final}\n"
  42. f" - path_image_final: {self.path_image_final}\n"
  43. f" - classes_names: {self.classes_names}\n"
  44. f" - classes_ids: {self.classes_ids}\n"
  45. f" - points_amount: {segmentations_lengths}\n"
  46. )