|
mport torch |
|
import numpy as np |
|
from sklearn.metrics import accuracy_score |
|
|
|
|
|
TEST_DATA_PATH = "test_data.pt" |
|
TEST_LABELS_PATH = "test_labels.pt" |
|
|
|
test_data = torch.load(TEST_DATA_PATH) |
|
test_labels = torch.load(TEST_LABELS_PATH) |
|
|
|
|
|
def evaluate_submission(model_checkpoint_path: str): |
|
""" |
|
Evaluates the submitted model on the hidden test set. |
|
Args: |
|
model_checkpoint_path (str): Path to the submitted model checkpoint. |
|
|
|
Returns: |
|
dict: A dictionary containing the evaluation metrics. |
|
""" |
|
|
|
model = torch.load(model_checkpoint_path) |
|
model.eval() |
|
|
|
|
|
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
|
model = model.to(device) |
|
test_data_tensor = test_data.to(device) |
|
|
|
|
|
with torch.no_grad(): |
|
predictions = model(test_data_tensor) |
|
predictions = torch.argmax(predictions, axis=1).cpu().numpy() |
|
|
|
|
|
accuracy = accuracy_score(test_labels, predictions) |
|
|
|
return {"accuracy": accuracy} |
|
|
|
if __name__ == "__main__": |
|
|
|
sample_model_path = "sample_submission.pt" |
|
result = evaluate_submission(sample_model_path) |
|
print(result) |
|
|