-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheval_acc10.py
71 lines (52 loc) · 2.09 KB
/
eval_acc10.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
import pandas as pd
import keras
from keras.models import load_model
import numpy as np
from tqdm import tqdm
from submission.output_formatter import write_predictions_to_file
def generate_predictions(df_path, model_path, batch_size=150, testing=False, n_channels=4, test_limit=5, validation=False):
df = pd.read_csv(df_path)
model = load_model(model_path)
predictions = {}
for lig_id, grp in tqdm(df.groupby('lig_id')):
grp.sort_values('pro_id', inplace=True)
grp.reset_index(inplace=True)
dims = (24,24,24)
X = np.empty((len(grp), *dims, n_channels))
for row in grp.itertuples():
X[row[0],] = np.load(row.dest)
probs = model.predict(X, batch_size=batch_size)
probs = probs.flatten()
# validation lig_ids have an offset of +2700
if validation:
lig_id -= 2700
predictions[lig_id] = probs
if testing:
if test_limit == 0:
break
test_limit-=1
return predictions
def _test_predictions():
# for testing the prediction generator
df_path = './data/csv/test_acc10_2_300.csv'
model_path = './models/finals/final_epochs_11.h5'
predictions = generate_predictions(df_path, model_path, 150, testing=True, n_channels=4, test_limit=500, validation=True)
score = 0
for lig_id, probs in predictions.items():
relative_lig_id = lig_id - 2701
largest_first = list(reversed(np.argsort(probs).tolist()))
top10 = largest_first[:10]
if relative_lig_id in top10:
score += 1
print(score/len(predictions))
def _test_submit():
# for testing the submit function
df_path = './data/csv/test_acc10_2_300.csv'
model_path = './models/final_model.h5'
predictions = generate_predictions(df_path, model_path, 150, validation=True)
write_predictions_to_file(predictions)
if __name__ == "__main__":
df_path = './data/csv/eval_acc10_2.csv'
model_path = './models/final_model.h5'
predictions = generate_predictions(df_path, model_path, 350)
write_predictions_to_file(predictions)