- 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)
| 55 | |
| 56 | |
| 57 | def get_dataset(label_dir: str, img_dir: str) -> tuple[list, list]: |
| 58 | """ |
| 59 | - label_dir <type: str>: Path to label include annotation of images |
| 60 | - img_dir <type: str>: Path to folder contain images |
| 61 | Return <type: list>: List of images path and labels |
| 62 | """ |
| 63 | img_paths = [] |
| 64 | labels = [] |
| 65 | for label_file in glob.glob(os.path.join(label_dir, "*.txt")): |
| 66 | label_name = label_file.split(os.sep)[-1].rsplit(".", 1)[0] |
| 67 | with open(label_file) as in_file: |
| 68 | obj_lists = in_file.readlines() |
| 69 | img_path = os.path.join(img_dir, f"{label_name}.jpg") |
| 70 | |
| 71 | boxes = [] |
| 72 | for obj_list in obj_lists: |
| 73 | obj = obj_list.rstrip("\n").split(" ") |
| 74 | xmin = float(obj[1]) - float(obj[3]) / 2 |
| 75 | ymin = float(obj[2]) - float(obj[4]) / 2 |
| 76 | xmax = float(obj[1]) + float(obj[3]) / 2 |
| 77 | ymax = float(obj[2]) + float(obj[4]) / 2 |
| 78 | |
| 79 | boxes.append([int(obj[0]), xmin, ymin, xmax, ymax]) |
| 80 | if not boxes: |
| 81 | continue |
| 82 | img_paths.append(img_path) |
| 83 | labels.append(boxes) |
| 84 | return img_paths, labels |
| 85 | |
| 86 | |
| 87 | def update_image_and_anno( |