-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredict_challenge.py
More file actions
63 lines (53 loc) · 1.75 KB
/
Copy pathpredict_challenge.py
File metadata and controls
63 lines (53 loc) · 1.75 KB
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
"""
Predict Challenge
Runs the challenge model inference on the test dataset and saves the
predictions to disk
Usage: python predict_challenge.py --uniqname=<uniqname>
"""
import argparse
import torch
import numpy as np
import pandas as pd
import utils
from dataset import get_challenge
from model.challenge import Challenge
from train_common import *
from utils import config
import utils
from sklearn import metrics
from torch.nn.functional import softmax
def predict_challenge(data_loader, model):
"""
Runs the model inference on the test set and outputs the predictions
"""
y_score = []
for X, y in data_loader:
output = model(X)
y_score.append(softmax(output.data, dim=1)[:, 1])
return torch.cat(y_score)
def main(uniqname):
"""Train challenge model."""
# data loaders
if check_for_augmented_data("./data"):
ch_loader, get_semantic_label = get_challenge(
task="target",
batch_size=config("challenge.batch_size"), augment = True
)
else:
ch_loader, get_semantic_label = get_challenge(
task="target",
batch_size=config("challenge.batch_size"),
)
model = Challenge()
# Attempts to restore the latest checkpoint if exists
model, _, _ = restore_checkpoint(model, config("challenge.checkpoint"))
# Evaluate model
model_pred = predict_challenge(ch_loader, model)
print("saving challenge predictions...\n")
pd_writer = pd.DataFrame(model_pred, columns=["predictions"])
pd_writer.to_csv(uniqname + ".csv", index=False, header=False)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--uniqname", required=True)
args = parser.parse_args()
main(args.uniqname)