Initial clean commit
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
'''
|
||||
Filename: mos.py
|
||||
Path: /home/netoa/Desktop/ISR/metrics/subjective
|
||||
Created Date: Saturday January 25th 2025
|
||||
Author: Andre Neto
|
||||
-----
|
||||
Last Modified: Wed Mar 12 2025
|
||||
Modified By: Andre Neto
|
||||
-----
|
||||
Copyright (c) 2025 Institute of Systems and Robotics
|
||||
'''
|
||||
|
||||
import os
|
||||
import pandas as pd
|
||||
|
||||
# pylint: disable=C0301
|
||||
|
||||
def compute_mos(test_csv, session_csv, user_csv, image_csv, output_csv):
|
||||
""" Compute and save MOS for images, with optional analysis. """
|
||||
|
||||
# Load CSV files
|
||||
test_df = pd.read_csv(test_csv)
|
||||
session_df = pd.read_csv(session_csv)
|
||||
user_df = pd.read_csv(user_csv)
|
||||
image_df = pd.read_csv(image_csv)
|
||||
|
||||
# Merge dataframes to include all relevant information
|
||||
combined_df = (
|
||||
test_df.merge(session_df, left_on="session_id", right_on="id", suffixes=("", "_session"))
|
||||
.merge(user_df, left_on="user_id", right_on="id", suffixes=("", "_user"))
|
||||
.merge(image_df, left_on="image_id", right_on="id", suffixes=("", "_image"))
|
||||
)
|
||||
|
||||
# Compute overall MOS for each image
|
||||
image_stats = combined_df.groupby("image_id")["rating"].agg(
|
||||
mos="mean", lower_score="min", max_score="max", median="median", std_dev="std", num_evaluators="count"
|
||||
).reset_index()
|
||||
|
||||
image_stats["mos"] = image_stats["mos"].round(2)
|
||||
image_stats["std_dev"] = image_stats["std_dev"].round(2)
|
||||
|
||||
# Add image file names to the output
|
||||
image_stats = image_stats.merge(image_df[["id", "file_name"]], left_on="image_id", right_on="id", how="left")
|
||||
image_stats = image_stats.drop(columns=["image_id"])
|
||||
image_stats = image_stats.sort_values(by="file_name", ascending=True)
|
||||
|
||||
# Save overall MOS to output file
|
||||
overall_output = os.path.splitext(output_csv)[0] + "_overall.csv"
|
||||
image_stats.to_csv(overall_output, index=False)
|
||||
print(f"MOS saved to {overall_output}")
|
||||
|
||||
|
||||
def main():
|
||||
""" Main script for computing MOS. """
|
||||
|
||||
tables_dir = 'metrics/subjective/tables'
|
||||
results_dir = 'results/sheets'
|
||||
|
||||
os.makedirs(tables_dir, exist_ok=True)
|
||||
os.makedirs(results_dir, exist_ok=True)
|
||||
|
||||
# CSV files
|
||||
user_csv = os.path.join(tables_dir, "app_user_user.csv")
|
||||
session_csv = os.path.join(tables_dir, "app_ss_session.csv")
|
||||
test_csv = os.path.join(tables_dir, "app_ss_test.csv")
|
||||
image_csv = os.path.join(tables_dir, "app_database_image.csv")
|
||||
output_csv = os.path.join(results_dir, "iqa_subjective.csv")
|
||||
|
||||
# Compute MOS
|
||||
compute_mos(test_csv, session_csv, user_csv, image_csv, output_csv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user