- label_dir : Path to label include annotation of images - img_dir : Path to folder contain images Return : List of images path and labels
(label_dir: str, img_dir: str)
| 43 | |
| 44 | |
| 45 | def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]: |
| 46 | """ |
| 47 | - label_dir <type: str>: Path to label include annotation of images |
| 48 | - img_dir <type: str>: Path to folder contain images |
| 49 | Return <type: list>: List of images path and labels |
| 50 | """ |
| 51 | img_paths = [] |
| 52 | labels = [] |
| 53 | for label_file in glob.glob(os.path.join(label_dir, "*.txt")): |
| 54 | label_name = label_file.split(os.sep)[-1].rsplit(".", 1)[0] |
| 55 | with open(label_file) as in_file: |
| 56 | obj_lists = in_file.readlines() |
| 57 | img_path = os.path.join(img_dir, f"{label_name}.jpg") |
| 58 | |
| 59 | boxes = [] |
| 60 | for obj_list in obj_lists: |
| 61 | obj = obj_list.rstrip("\n").split(" ") |
| 62 | boxes.append( |
| 63 | [ |
| 64 | int(obj[0]), |
| 65 | float(obj[1]), |
| 66 | float(obj[2]), |
| 67 | float(obj[3]), |
| 68 | float(obj[4]), |
| 69 | ] |
| 70 | ) |
| 71 | if not boxes: |
| 72 | continue |
| 73 | img_paths.append(img_path) |
| 74 | labels.append(boxes) |
| 75 | return img_paths, labels |
| 76 | |
| 77 | |
| 78 | def update_image_and_anno( |