Skip to content
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

a method to modify the result file to csv #129

Open
unfollow7 opened this issue Apr 10, 2023 · 0 comments
Open

a method to modify the result file to csv #129

unfollow7 opened this issue Apr 10, 2023 · 0 comments

Comments

@unfollow7
Copy link

unfollow7 commented Apr 10, 2023

trackeval/metrics/_base_metric.py
def summary_results(self, table_res):
"""Returns a simple summary of final results for a tracker"""
res = {}
for k in table_res.keys():
res[k] = dict(zip(self.summary_fields, self._summary_row(table_res[k])))
return res

trackeval/utils.py
from pandas import DataFrame
def write_summary_results(summaries, cls, output_folder):
"""Write summary results to file"""
out_file = os.path.join(output_folder, cls + '_summary.csv')
if os.path.exists(out_file):
os.remove(out_file)
os.makedirs(os.path.dirname(out_file), exist_ok=True)
for sums in summaries:
x = DataFrame(sums)
x = DataFrame(x.values.T, index=x.columns, columns=x.index)
with open(out_file, 'a', newline='') as f:
x.to_csv(f, mode="a", index=True)
f.write("\n")

def write_detailed_results(details, cls, output_folder):
"""Write detailed results to file"""
out_file = os.path.join(output_folder, cls + 'detailed.csv')
if os.path.exists(out_file):
os.remove(out_file)
os.makedirs(os.path.dirname(out_file), exist_ok=True)
for detail in details:
x = DataFrame(detail)
x = DataFrame(x.values.T, index=x.columns, columns=x.index)
col_classes = {"ori": []}
for col in x.columns.tolist():
if "
" in col:
the_class = col.split("
_", 1)[0]
if the_class not in col_classes.keys():
col_classes[the_class] = [col]
else:
col_classes[the_class].append(col)
else:
col_classes["ori"].append(col)
for v in col_classes.values():
tmp_df = x[v]
with open(out_file, 'a', newline='') as f:
tmp_df.to_csv(f, mode="a", index=True)
f.write("\n")

@unfollow7 unfollow7 changed the title a method to modify the resultfile to csv a method to modify the result file to csv Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant