MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / get_dataset

Function get_dataset

computer_vision/mosaic_augmentation.py:57–84  ·  view source on GitHub ↗

- 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)

Source from the content-addressed store, hash-verified

55
56
57def 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
87def update_image_and_anno(

Callers 1

mainFunction · 0.70

Calls 2

splitMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected