Skip to content

Commit ca3347a

Browse files
Merge pull request #775 from mlcommons/dev
Dev -> main
2 parents a8bed08 + ec434a9 commit ca3347a

1 file changed

Lines changed: 35 additions & 6 deletions

File tree

scoring/score_submissions.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
'submission_directory',
3131
None,
3232
'Path to submission directory containing experiment directories.')
33-
flags.DEFINE_string('output_dir',
34-
'scoring_results',
35-
'Path to save performance profile table and plot.')
33+
flags.DEFINE_string(
34+
'output_dir',
35+
'scoring_results',
36+
'Path to save performance profile artifacts, submission_summaries and results files.'
37+
)
3638
flags.DEFINE_boolean('compute_performance_profiles',
3739
False,
3840
'Whether or not to compute the performance profiles.')
@@ -51,11 +53,16 @@
5153
None,
5254
'Filename to save the processed results that are fed into the performance profile functions.'
5355
)
54-
flags.DEFINE_boolean(
56+
flags.DEFINE_string(
5557
'load_results_from_filename',
5658
None,
5759
'Filename to load processed results from that are fed into performance profile functions'
5860
)
61+
flags.DEFINE_string(
62+
'exclude_submissions',
63+
'',
64+
'Optional comma seperated list of names of submissions to exclude from scoring.'
65+
)
5966
FLAGS = flags.FLAGS
6067

6168

@@ -129,6 +136,22 @@ def get_submission_summary(df, include_test_split=True):
129136
return df
130137

131138

139+
def compute_leaderboard_score(df, normalize=False):
140+
"""Compute leaderboard score by taking integral of performance profile.
141+
142+
Args:
143+
df: pd.DataFrame returned from `compute_performance_profiles`.
144+
normalize: divide by the range of the performance profile's tau.
145+
146+
Returns:
147+
pd.DataFrame with one column of scores indexed by submission.
148+
"""
149+
scores = np.trapz(df, x=df.columns)
150+
if normalize:
151+
scores /= df.columns.max() - df.columns.min()
152+
return pd.DataFrame(scores, columns=['score'], index=df.index)
153+
154+
132155
def main(_):
133156
results = {}
134157
os.makedirs(FLAGS.output_dir, exist_ok=True)
@@ -144,6 +167,8 @@ def main(_):
144167
for submission in os.listdir(
145168
os.path.join(FLAGS.submission_directory, team)):
146169
print(submission)
170+
if submission in FLAGS.exclude_submissions.split(','):
171+
continue
147172
experiment_path = os.path.join(FLAGS.submission_directory,
148173
team,
149174
submission)
@@ -185,9 +210,13 @@ def main(_):
185210
os.mkdir(FLAGS.output_dir)
186211
performance_profile.plot_performance_profiles(
187212
performance_profile_df, 'score', save_dir=FLAGS.output_dir)
188-
perf_df = tabulate(
213+
performance_profile_str = tabulate(
189214
performance_profile_df.T, headers='keys', tablefmt='psql')
190-
logging.info(f'Performance profile:\n {perf_df}')
215+
logging.info(f'Performance profile:\n {performance_profile_str}')
216+
scores = compute_leaderboard_score(performance_profile_df)
217+
scores.to_csv(os.path.join(FLAGS.output_dir, 'scores.csv'))
218+
scores_str = tabulate(scores, headers='keys', tablefmt='psql')
219+
logging.info(f'Scores: \n {scores_str}')
191220

192221

193222
if __name__ == '__main__':

0 commit comments

Comments
 (0)