-
Notifications
You must be signed in to change notification settings - Fork 0
/
classify_data.py
122 lines (47 loc) · 1.99 KB
/
classify_data.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Detects RPD in dataset.
Usage:
python .\classify_data.py "model_folder" "data_folder" "output_file"
"""
import sys
import os
import numpy as np
import pandas as pd
import preprocessing
import trained_model
import tensorflow as tf
def classify_main(model_folder='./Models/AREDS2/Deep-RPD-Net+', data_folder='./Data/AREDS2', output='predictions.csv'):
print('Loading Deep-RPD-Net')
model = trained_model.load(model_folder)
dataset = 'areds' if 'areds' in data_folder.lower() else 'daamd'
if dataset == 'areds':
scan_list = [d for d in os.listdir(data_folder) if os.path.isdir(os.path.join(data_folder, d))]
else:
scan_list = [file for file in os.listdir(data_folder) if file.endswith('.npy')]
print('#scans in folder is', len(scan_list))
predictions = []
for scan_name in scan_list:
print('predicting scan', scan_name.replace('.npy', ''))
scan_path = os.path.join(data_folder, scan_name)
scan = preprocessing.preprocess_scan(scan_path=scan_path, dataset=dataset)
scan = preprocessing.match_dims(scan)
pred = model.predict(scan, verbose=0)
pred = np.argmax(pred[0])
print(f'prediction is {pred}')
predictions.append(pred)
predictions = np.array(predictions)
df = pd.DataFrame(predictions, columns=['prediction'])
df.to_csv(output, index=False)
if __name__ == "__main__":
print('Running ...')
argv = sys.argv[1:]
# print(len(argv))
# print(argv)
if len(argv) == 3: # parameters are passed
print('Taking args ...')
model_folder = argv[0]
data_folder = argv[1]
output_file = argv[2]
classify_main(model_folder, data_folder, output_file)
else: # no parameters, using the defaults
classify_main()