forked from TugaAhmed/Real_Or_Fake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
31 lines (24 loc) · 939 Bytes
/
test.py
File metadata and controls
31 lines (24 loc) · 939 Bytes
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
import torch
import pandas as pd
from dataloader import GraphDataset
from models.model import GNN
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load test data
test_loader = GraphDataset(split='test').get_loader(shuffle=False)
sample_data = next(iter(test_loader))
# Load the saved model
model = GNN(sample_data.num_features).to(device)
model.load_state_dict(torch.load("models/saved_model.model", map_location=device))
model.eval()
all_preds = []
all_ids = []
with torch.no_grad():
for data in test_loader:
data = data.to(device)
out = model(data.x, data.edge_index, data.batch)
all_preds.extend(torch.round(out.view(-1)).cpu().numpy())
all_ids.extend(data.graph_id.cpu().numpy())
# Save submission
submission = pd.DataFrame({"id": all_ids, "y_pred": all_preds})
submission.to_csv("submissions/sample_submission/predictions.csv", index=False)
print("Submission saved!")