Initial clean commit

This commit is contained in:
Andre Neto
2025-04-12 03:19:13 +01:00
commit 62ff4d6c25
96 changed files with 104109 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
'''
Filename: evaluation.py
Path: /home/netoa/Desktop/ISR/scripts/nr_fusion
Created Date: Monday March 24th 2025
Author: Andre Neto
-----
Last Modified: Tue Mar 25 2025
Modified By: Andre Neto
-----
Copyright (c) 2025 Institute of Systems and Robotics
'''
import os
import matplotlib.pyplot as plt
import numpy as np
from sklearn.metrics import mean_squared_error, mean_absolute_error
from scipy.stats import pearsonr, spearmanr
def evaluate_and_plot(y_true, y_pred, output_dir, show_trend=True):
"""
Compute evaluation metrics and generate scatter plot.
Args:
y_true (array-like): Ground truth pseudo-MOS values.
y_pred (array-like): Predicted pseudo-MOS values.
output_dir (str): Directory to save plots.
show_trend (bool): Whether to include a fitted trendline.
"""
os.makedirs(output_dir, exist_ok=True)
# Plot
plt.figure(figsize=(7, 7))
plt.scatter(y_true, y_pred, alpha=0.6, color="darkorange", s=20)
# Diagonal reference
min_val = min(min(y_true), min(y_pred))
max_val = max(max(y_true), max(y_pred))
plt.plot([min_val, max_val], [min_val, max_val], '--', color="gray", alpha=0.7)
# Optional trendline
if show_trend:
z = np.polyfit(y_true, y_pred, 1)
p = np.poly1d(z)
plt.plot(y_true, p(y_true), color="blue", linewidth=1.5, label="Trendline")
plt.legend()
plt.xlabel("Fusion_RF (pseudo-MOS)")
plt.ylabel("NR Prediction")
plt.title("NR IQA Prediction vs. Fusion_RF")
plt.grid(True, linestyle="--", alpha=0.4)
plt.tight_layout()
plt.savefig(os.path.join(output_dir, "nr_vs_fusion_rf.png"), dpi=300)
plt.savefig(os.path.join(output_dir, "nr_vs_fusion_rf.eps"), dpi=300)
plt.close()
def compute_correlation_scores(y_true, y_pred):
"""
Compute correlation scores between ground truth and predicted values.
Args:
y_true (array-like): Ground truth pseudo-MOS scores.
y_pred (array-like): Predicted scores from NR IQA model.
Returns:
dict: Dictionary with PLCC and SRCC scores.
"""
# Compute metrics
mse = mean_squared_error(y_true, y_pred)
mae = mean_absolute_error(y_true, y_pred)
plcc, _ = pearsonr(y_true, y_pred)
srcc, _ = spearmanr(y_true, y_pred)
return {"PLCC": plcc,
"SRCC": srcc,
"MSE": mse,
"MAE": mae}