File size: 2,368 Bytes
379573c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import json
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# 1. Load the data
with open('/media/vrt/shared/DATASETS/I-BADAS/results/aupro_isolated_metrics.json', 'r') as f:
    data = json.load(f)

# 2. Flatten the data
rows = []
for model, cameras in data.items():
    if model == "PadimSmall":
        model = "Padim"
    for camera, scenes in cameras.items():
        for scene, classes in scenes.items():
            for cls, metrics in classes.items():
                rows.append({
                    'Model': model,
                    'Class': cls,
                    'AUPRO': metrics['Pixel_AUPRO']
                })
df = pd.DataFrame(rows)

# 3. Aggregate: Mean performance per Model and Class
df_agg = df.groupby(['Model', 'Class'])['AUPRO'].mean().reset_index()

# 4. Calculate Mean per Class (across all models)
class_means = df_agg.groupby('Class')['AUPRO'].mean()

# 5. Visualization
sns.set_theme(style="whitegrid", font_scale=1.1)
plt.figure(figsize=(14, 5))

# Create barplot
chart = sns.barplot(
    data=df_agg,
    x='Class',
    y='AUPRO',
    hue='Model',
    palette='viridis'
)

# 6. Add dotted line segments and text labels
classes = df_agg['Class'].unique()

for i, cls in enumerate(classes):
    mean_val = class_means[cls]
    
    # Draw horizontal line centered at i with width 0.8
    plt.hlines(y=mean_val, xmin=i - 0.4, xmax=i + 0.4, 
               colors='red', linestyles=':', linewidth=3, 
               label='Class Mean' if i == 0 else "")
    
    # Add red text below the line
    # (Adjust the '0.04' offset if the text overlaps with bars)
    plt.text(i + 0.3, mean_val + 0.018, f"{mean_val:.2f}", 
             color='red', ha='left', va='center', 
             fontsize=9, fontweight='bold')

# Aesthetics
plt.xticks(rotation=15, ha='right')
plt.xlabel('')  # Removed X-axis title
plt.ylabel('Mean Pixel AUPRO Score')

# Place legend inside, top-left corner
plt.legend(
    loc='upper left', 
    ncol=3, 
    frameon=True, 
    framealpha=0.2,       # 0.0 (transparent) to 1.0 (opaque)
    facecolor='white',    # Background color of the box
    edgecolor='black'      # Optional: light gray border, or use 'none' for no border
)

# 7. Save as PDF
plt.tight_layout()
plt.savefig("/media/vrt/shared/DATASETS/I-BADAS/results/performance_aupro_only_new.pdf", bbox_inches='tight')

plt.show()