-
Notifications
You must be signed in to change notification settings - Fork 0
/
error_metrics.py
39 lines (34 loc) · 1.26 KB
/
error_metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import numpy as np
def compute_angular_error(y_true, y_pred):
"""
Angle between the RGB triplet of the measured ground truth
illumination and RGB triplet of estimated illuminant
Args:
y_true (np.array): ground truth RGB illuminants
y_pred (np.array): predicted RGB illuminants
Returns:
err (np.array): angular error
"""
gt_norm = np.linalg.norm(y_true, axis=1)
gt_normalized = y_true / gt_norm[..., np.newaxis]
est_norm = np.linalg.norm(y_pred, axis=1)
est_normalized = y_pred / est_norm[..., np.newaxis]
dot = np.sum(gt_normalized * est_normalized, axis=1)
err = np.degrees(np.arccos(dot))
return err
def compute_angular_error_stats(ang_err):
"""
Angular error statistics such as min, max, mean, etc.
Args:
ang_err (np.array): angular error
Returns:
ang_err_stats (dict): angular error statistics
"""
ang_err = ang_err[~np.isnan(ang_err)]
ang_err_stats = {"min": np.min(ang_err),
"10prc": np.percentile(ang_err, 10),
"median": np.median(ang_err),
"mean": np.mean(ang_err),
"90prc": np.percentile(ang_err, 90),
"max": np.max(ang_err)}
return ang_err_stats