| | from shapely.geometry import Polygon |
| | import yaml |
| | from pathlib import Path |
| |
|
| | |
| | |
| | def check_box_intersection(box_1, box_2, threshold=0.6): |
| | |
| | formatted_box_1 = [[box_1[0], box_1[1]], [box_1[2], box_1[1]], [box_1[2], box_1[3]], [box_1[0], box_1[3]]] |
| |
|
| | poly_1 = Polygon(formatted_box_1) |
| | poly_2 = Polygon(box_2) |
| | try: |
| | iou = poly_1.intersection(poly_2).area / poly_1.union(poly_2).area |
| | scaled_iou = iou * ((poly_1.area) / (poly_2.area)) |
| | |
| | |
| | return (scaled_iou > threshold) |
| | except ZeroDivisionError: |
| | |
| | print("ZERO DIVISION ERROR", poly_1.area, poly_2.area) |
| | return False |
| |
|
| | |
| | def load_yaml_database(yaml_path): |
| | config_file = None |
| |
|
| | with open(yaml_path, "r") as file: |
| | config_file = yaml.safe_load(file) |
| | |
| | root = Path(config_file['path']) |
| | train_dir = root / config_file['train'] |
| | valid_dir = root / config_file['val'] |
| | test_dir = root / config_file['test'] |
| | image_size = config_file['img_size'] |
| | classes = config_file['names'] |
| |
|
| | |
| | return (train_dir, valid_dir, test_dir), (image_size, classes) |