-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
76 lines (52 loc) · 1.81 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# This file will use to score your implementations.
# You should not change this file
import os
import sys
import time
import cv2
import numpy as np
from landing_detector import LandingDetector
def read_label(label_file):
with open(label_file, "r") as f:
line = f.readline()
tmp = line.strip().split(' ')
w, h = img.shape[1], img.shape[0]
x = [(float)(w.strip()) for w in tmp]
x1 = int(x[1] * w)
width = int(x[3] * w)
y1 = int(x[2] * h)
height = int(x[4] * h)
return x1 - width // 2, y1 - height // 2, x1 + width // 2, y1 + height // 2
# TODO: Implementation IOU
def iou_score(output, target):
return 0.5
def calc_precision(iou, t):
return 1.0 * len(iou[iou > t]) / len(iou)
if __name__ == "__main__":
input_folder = sys.argv[1]
label_folder = sys.argv[2]
start_time = time.time()
detector = LandingDetector()
init_time = time.time() - start_time
print("Run time in: %.2f s" % init_time)
list_files = os.listdir(input_folder)
print("Total test images: ", len(list_files))
iou = []
start_time = time.time()
total = 0
for filename in list_files:
if not ('jpg' in filename or 'jpeg' in filename):
continue
total += 1
img = cv2.imread(os.path.join(input_folder, filename))
target = read_label(os.path.join(label_folder, filename[:-4] + "txt"))
print(img.shape)
output_x1, output_y1, output_x2, output_y2 = detector.detect(img)
iou.append(iou_score((output_x1, output_y1, output_x2, output_y2),
target))
map_scores = []
for i in range(50, 100, 5):
map_scores += calc_precision(iou, 0.01 * i)
run_time = time.time() - start_time
print("Map score: %.6f" % np.mean(map_scores))
print("Run time: ", run_time)