-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_canditate_nodules.py
57 lines (43 loc) · 1.64 KB
/
test_canditate_nodules.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
# -*- coding:UTF-8 -*-
# !/usr/bin/env python
#########################################################################
# File Name: test_canditate_nodules.py
# Author: Banggui
# mail: [email protected]
# Created Time: 2017年05月08日 星期一 11时22分52秒
#########################################################################
import numpy as np
import os
import math
def get_nodules(path):
fi = open(path, 'r')
files = fi.readlines()
fi.close()
nodules = {}
for file in files[1:]:
row = file.strip('\n').split(',')
if row[0] not in nodules.keys():
nodules[row[0]] = []
nodules[row[0]].append(np.array([float(row[1]), float(row[2]), float(row[3])]))
return nodules
def euclidean_dist(p1, p2):
square = (p1 - p2) ** 2
return math.sqrt(sum(square))
def main():
annotation_nodules = get_nodules('./data/csv_files/val/annotations.csv')
candidate_nodules = get_nodules('./output/test_masks/candidate_nodules_centroids.csv')
#candidate_nodules = get_nodules('./output/submission/submission_file_1.csv')
pred_count = 0
total_candidate_nodules = 0
for patient in annotation_nodules.keys():
total_candidate_nodules += len(annotation_nodules[patient])
coords_A = annotation_nodules[patient]
coords_C = candidate_nodules[patient]
for p in coords_A:
for q in coords_C:
if euclidean_dist(p, q) <= 10.0:
pred_count += 1
break
print ('There are {} nodules have been predict.'.format((1.0 * pred_count) / total_candidate_nodules))
if __name__ == "__main__":
main()