-
Notifications
You must be signed in to change notification settings - Fork 38
Add CLI for model submission evluation. #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import ast | ||
| import numpy as np | ||
| import pandas as pd | ||
| from cascade.utility.metrics import Metrics | ||
|
|
||
|
|
||
| def load_submission_data(submission_path): | ||
| """ | ||
| Extract necessary data for model evaluation from the submitted csv file. | ||
|
|
||
| Args: | ||
| submission_path (str): Complete path to the submission file. | ||
|
|
||
| Returns: | ||
| tuple: Contains: | ||
| - trial indices (1D array) | ||
| - image IDs (1D array) | ||
| - neuron IDs (1D array) | ||
| - predictions (2d array: trials x neurons) | ||
| """ | ||
| submission_df = pd.read_csv(submission_path) | ||
| trial_idx = submission_df["trial_indices"].values | ||
| image_ids = submission_df["image_ids"].values | ||
| neuron_ids = np.array(ast.literal_eval(submission_df["neuron_ids"].values[0])) | ||
| predictions = np.array( | ||
| [ast.literal_eval(v) for v in submission_df["prediction"].values] | ||
| ) | ||
|
|
||
| return trial_idx, image_ids, neuron_ids, predictions | ||
|
|
||
|
|
||
| def load_groundtruth_data(groundtruth_path): | ||
| """ | ||
| Extract necessary data for model evaluation from the ground truth data file. | ||
|
|
||
| Args: | ||
| groundtruth_path (str): Absolute path to the ground truth data file. | ||
|
|
||
| Returns: | ||
| tuple: Contains: | ||
| - trial indices (1D array) | ||
| - image IDs (1D array) | ||
| - neuron IDs (1D array) | ||
| - responses (2d array: trials x neurons) | ||
| """ | ||
| raise NotImplementedError() | ||
|
|
||
|
|
||
| def evaluate(submission_path, ground_truth_path): | ||
| """ | ||
| Compute evaluation metrics for a specific submission given the ground truth data. | ||
|
|
||
| Args: | ||
| submission_path (str): Absolute path to the submission csv file. | ||
| ground_truth_path (str): Absolute path to the ground truth data file. | ||
|
|
||
| Returns: | ||
| dict: Containing all the evaluation results for all the evaluation metrics. | ||
| """ | ||
| trial_idx_gt, image_ids_gt, neuron_ids_gt, responses = load_groundtruth_data( | ||
| ground_truth_path | ||
| ) | ||
| ( | ||
| trial_idx_submitted, | ||
| image_ids_submitted, | ||
| neuron_ids_submitted, | ||
| predictions, | ||
| ) = load_submission_data(submission_path) | ||
|
|
||
| metric = Metrics(responses, trial_idx_gt, image_ids_gt, neuron_ids_gt) | ||
|
|
||
| output = {} | ||
| output["Correlation (single trial)"] = metric.correlation_to_single_trials( | ||
| predictions, trial_idx_submitted, neuron_ids_submitted, per_neuron=False | ||
| ) | ||
| output["Correlation (mean)"] = metric.correlation_to_mean_across_repeats( | ||
| predictions, trial_idx_submitted, neuron_ids_submitted, per_neuron=False | ||
| ) | ||
| output["FEVE"] = metric.feve( | ||
| predictions, trial_idx_submitted, neuron_ids_submitted, per_neuron=False | ||
| ) | ||
| return output | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.