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

Added option to export explanation csv for all files #228

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ matplotlib==3.8.4
numpy==1.26.4
opencv-contrib-python==4.9.0.80
opencv-python==4.9.0.80
pandas==2.2.1
rich==13.7.1
pandas==2.2.2
rich==13.8.0
rich-tools==0.5.1
scipy==1.12.0
screeninfo==0.8.1
shapely==2.0.3
8 changes: 8 additions & 0 deletions src/algorithm/evaluation/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def __init__(
self.draw_question_verdicts,
self.draw_score,
self.should_explain_scoring,
self.should_export_explanation_csv,
) = map(
outputs_configuration.get,
[
Expand All @@ -466,6 +467,7 @@ def __init__(
"draw_question_verdicts",
"draw_score",
"should_explain_scoring",
"should_export_explanation_csv",
],
)
if self.draw_question_verdicts["enabled"]:
Expand Down Expand Up @@ -1014,6 +1016,12 @@ def conditionally_print_explanation(self):
def get_should_explain_scoring(self):
return self.should_explain_scoring

def get_should_export_explanation_csv(self):
return self.should_export_explanation_csv

def get_explanation_table(self):
return self.explanation_table

def get_formatted_answers_summary(self, answers_summary_format_string=None):
if answers_summary_format_string is None:
answers_summary_format_string = self.draw_answers_summary[
Expand Down
3 changes: 3 additions & 0 deletions src/algorithm/template/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def get_multi_marked_dir(self):
def get_errors_dir(self):
return self.directory_handler.path_utils.errors_dir

def get_eval_dir(self):
return self.directory_handler.path_utils.eval_dir

def read_omr_response(self, input_gray_image, colored_image, file_path):
# Convert posix path to string
file_path = str(file_path)
Expand Down
10 changes: 10 additions & 0 deletions src/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
from rich.table import Table
from rich_tools import table_to_df
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome find!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually I read it as rich.tools, is this a new package getting installed?
Need to update requirements.txt in that case

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it is a new package, will update requirements.txt

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking if it should be abstracted inside evaluation only, entry.py doesn't need to know underlying tools getting used. Directly a way to access the df from evaluation_config_for_response


from src.algorithm.evaluation.config import EvaluationConfig
from src.algorithm.evaluation.evaluation import evaluate_concatenated_response
Expand Down Expand Up @@ -326,6 +327,15 @@ def process_directory_files(
logger.info(
f"(/{files_counter}) Graded with score: {round(score, 2)}\t {default_answers_summary} \t file: '{file_id}'"
)
if evaluation_config_for_response.get_should_export_explanation_csv():
explanation_table = evaluation_config_for_response.get_explanation_table()
explanation_table = table_to_df(explanation_table)
explanation_table.to_csv(
template.get_eval_dir().joinpath(file_name + ".csv"),
quoting=QUOTE_NONNUMERIC,
index=False,
)

else:
logger.info(f"(/{files_counter}) Processed file: '{file_id}'")

Expand Down
4 changes: 4 additions & 0 deletions src/schemas/evaluation_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@
"description": "Whether to print the table explaining question-wise verdicts",
"type": "boolean",
},
"should_export_explanation_csv": {
tushar-badlani marked this conversation as resolved.
Show resolved Hide resolved
"description": "Whether to export the explanation of evaluation results as a CSV file",
"type": "boolean",
},
"draw_score": {
"description": "The configuration for drawing the final score",
"type": "object",
Expand Down
2 changes: 2 additions & 0 deletions src/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def __init__(self, output_dir):
self.manual_dir = output_dir.joinpath("Manual")
self.errors_dir = self.manual_dir.joinpath("ErrorFiles")
self.multi_marked_dir = self.manual_dir.joinpath("MultiMarkedFiles")
self.eval_dir = output_dir.joinpath("Evaluations")
tushar-badlani marked this conversation as resolved.
Show resolved Hide resolved
self.debug_dir = output_dir.joinpath("Debug")

def create_output_directories(self):
Expand Down Expand Up @@ -96,6 +97,7 @@ def create_output_directories(self):
for save_output_dir in [
self.results_dir,
self.image_metrics_dir,
self.eval_dir,
]:
if not os.path.exists(save_output_dir):
logger.info(f"Created : {save_output_dir}")
Expand Down
Loading