-
Notifications
You must be signed in to change notification settings - Fork 24
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
Visualizeinit #20
Open
nvidia-johnq
wants to merge
2
commits into
NVIDIA:master
Choose a base branch
from
nvidia-johnq:visualizeinit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Visualizeinit #20
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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,116 @@ | ||
import os | ||
import sys | ||
import json | ||
import numpy as np | ||
import pandas as pd | ||
import argparse | ||
import matplotlib.pyplot as plt | ||
import csv | ||
|
||
def parse_args(): | ||
parser = argparse.ArgumentParser( | ||
description="Visualize benchmarks against another version") | ||
parser.add_argument("-d1", required=True, type=str, | ||
help="The first csv file directory with results") | ||
parser.add_argument("-d2", required=True, type=str, | ||
help="The second csv file directory with results") | ||
parser.add_argument("-metric", default="train_time", type=str, | ||
help=("The metric we want to visulaize")) | ||
parser.add_argument("-title", default="graph", type=str, | ||
help=("The title of the graph")) | ||
parser.add_argument("-output", default=sys.path[0] + "/results.png", type=str, | ||
help="Output json file with visualization") | ||
args = parser.parse_args() | ||
return args | ||
|
||
def autolabel(rects): | ||
"""Attach a text label above each bar in *rects*, displaying its height.""" | ||
for rect in rects: | ||
height = rect.get_height() | ||
ax.annotate('{}'.format(height), | ||
xy=(rect.get_x() + rect.get_width() / 2, height), | ||
xytext=(0, 3), # 3 points vertical offset | ||
textcoords="offset points", | ||
ha='center', va='bottom') | ||
|
||
def algo_trimmer(algo): | ||
print(f"algo: {algo}") | ||
s = "" | ||
for i in range(len(algo)): | ||
if(algo[i] == '_'): | ||
break | ||
s+=algo[i] | ||
return s | ||
|
||
def plot_error_bars(df, args): | ||
gp = df.groupby("dataset") | ||
means = gp.mean() | ||
errors = gp.std() | ||
if(args.metric == "train-time"): | ||
fig, ax = plt.subplots() | ||
pl = means.plot.bar(yerr=errors, ax=ax, capsize=10, rot=0, logy=True) | ||
for idx, label in enumerate(list(means.index)): | ||
for acc in means.columns: | ||
value = np.round(means.iloc[idx,0]/means.iloc[idx, 1],decimals=2) | ||
ax.annotate(value, | ||
(idx, value), | ||
xytext=(0, 15), | ||
textcoords='offset points') | ||
else: | ||
fig, ax = plt.subplots() | ||
pl = means.plot.bar(yerr=errors, ax=ax, capsize=10, rot=0, figsize=(12, 12)) | ||
for p in ax.patches: | ||
h = p.get_height() | ||
x = p.get_x()+p.get_width()/2. | ||
if h != 0: | ||
ax.annotate("%g" % round(p.get_height(), 2), xy=(x,h), xytext=(0,4), rotation=90, | ||
textcoords="offset points", ha="center", va="bottom") | ||
ax.legend(ncol=len(df.columns), loc="lower left", bbox_to_anchor=(0,1.02,1,0.08), | ||
borderaxespad=0, mode="expand") | ||
plt.ylabel(f"{args.metric}") | ||
plt.title(args.title) | ||
plt.savefig(args.output) | ||
|
||
def train_timer(args): | ||
df = pd.DataFrame() | ||
for idx, i in enumerate([args.d1, args.d2]): | ||
temp_df = pd.read_csv(i) | ||
temp_df = temp_df.drop(columns=["test_time", "AUC", "Accuracy", "F1","Precision", | ||
"Recall","MeanAbsError","MeanSquaredError","MedianAbsError", "algorithm"]) | ||
if(idx == 0): | ||
temp_df = temp_df.rename(columns={"train_time": f"{args.d1}_train_time"}) | ||
df = df.append(temp_df) | ||
else: | ||
temp_df = temp_df.rename(columns={"train_time": f"{args.d2}_train_time"}) | ||
df = df.merge(temp_df, on="dataset") | ||
return df | ||
|
||
def accuracy_timer(args): | ||
df = pd.DataFrame() | ||
for idx, i in enumerate([args.d1, args.d2]): | ||
temp_df = pd.read_csv(i) | ||
temp_df = temp_df.drop(columns=["test_time", "AUC", "train_time", "F1","Precision", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please consider using a variable name that's easier to understand. What's in the df after drop? :-) |
||
"Recall","MeanAbsError","MeanSquaredError","MedianAbsError", "algorithm"]) | ||
if(idx == 0): | ||
temp_df = temp_df[temp_df["Accuracy"] != "-na-"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is gbm bench outputting the symbol |
||
temp_df = temp_df.rename(columns={"Accuracy": f"{args.d1}_Accuracy"}) | ||
df = df.append(temp_df) | ||
else: | ||
temp_df = temp_df[temp_df["Accuracy"] != "-na-"] | ||
temp_df = temp_df.rename(columns={"Accuracy": f"{args.d2}_Accuracy"}) | ||
df = df.merge(temp_df, on="dataset") | ||
df = df.astype({f"{args.d1}_Accuracy": 'float32', f"{args.d2}_Accuracy": 'float32'}) | ||
return df | ||
|
||
def main(): | ||
args = parse_args() | ||
df = pd.DataFrame() | ||
if(args.metric == 'train-time'): | ||
df = train_timer(args) | ||
else: | ||
df = accuracy_timer(args) | ||
plot_error_bars(df, args) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
_
mean?