-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_submission.py
38 lines (31 loc) · 1.18 KB
/
make_submission.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
import os
import pandas as pd
import numpy as np
from scipy.stats.mstats import gmean
def sigmoid(x, derivative=False):
return x*(1-x) if derivative else 1/(1+np.exp(-x))
if __name__ == '__main__':
os.makedirs("submission", exist_ok=True)
threshold = 0.3
preds = []
for model_name in ["xception"]:
for fold in [0, 1, 2, 3, 4, 5]:
# for checkpoint in range(5):
pred = np.load(f"/raid/bac/kaggle/logs/imet2019/finetune/{model_name}_320/fold_{fold}/predicts/infer.logits.npy")
pred = sigmoid(pred)
preds.append(pred)
print(len(preds))
preds = np.asarray(preds)
preds = np.mean(preds, axis=0)
print(preds.shape)
preds = preds > threshold
prediction = []
for i in range(preds.shape[0]):
pred1 = np.argwhere(preds[i] == 1.0).reshape(-1).tolist()
pred_str = " ".join(list(map(str, pred1)))
prediction.append(pred_str)
test_df = pd.read_csv("/raid/data/kaggle/imet2019/sample_submission.csv")
test_df.attribute_ids = prediction
os.makedirs("submission", exist_ok=True)
test_df.to_csv(f"./submission/{model_name}_kfold.csv", index=False)
print(test_df.head())