Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,23 +61,41 @@ def compute_f1_score(cm):
|
|
61 |
f1 = np.nan_to_num(f1) # Replace NaN with 0
|
62 |
return np.mean(f1) # Return the mean F1-score across all classes
|
63 |
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
# Compute the average F1-score
|
66 |
avg_f1 = compute_f1_score(cm)
|
67 |
|
68 |
# Choose the color scheme based on the mode
|
69 |
-
if
|
70 |
-
plt.style.use('default') # Use default (light) mode styling
|
71 |
-
text_color = 'black'
|
72 |
-
cmap = 'Blues' # Light-mode-friendly colormap
|
73 |
-
else:
|
74 |
plt.style.use('dark_background') # Use dark mode styling
|
75 |
text_color = 'white'
|
76 |
cmap = 'cividis' # Dark-mode-friendly colormap
|
|
|
|
|
|
|
|
|
77 |
|
78 |
plt.figure(figsize=(10, 10))
|
79 |
|
80 |
-
# Plot the confusion matrix with
|
81 |
sns.heatmap(cm, cmap=cmap, cbar=True, linecolor='white', vmin=0, vmax=cm.max(), alpha=0.85)
|
82 |
|
83 |
# Add F1-score to the title
|
@@ -98,7 +116,6 @@ def plot_confusion_matrix_beamPred(cm, classes, title, save_path, light_mode=Tru
|
|
98 |
# Return the saved image
|
99 |
return Image.open(save_path)
|
100 |
|
101 |
-
|
102 |
def compute_average_confusion_matrix(folder):
|
103 |
confusion_matrices = []
|
104 |
max_num_labels = 0
|
|
|
61 |
f1 = np.nan_to_num(f1) # Replace NaN with 0
|
62 |
return np.mean(f1) # Return the mean F1-score across all classes
|
63 |
|
64 |
+
import matplotlib.pyplot as plt
|
65 |
+
import seaborn as sns
|
66 |
+
import numpy as np
|
67 |
+
from PIL import Image
|
68 |
+
|
69 |
+
def plot_confusion_matrix_beamPred(cm, classes, title, save_path, dark_mode=None):
|
70 |
+
"""
|
71 |
+
Plot confusion matrix and adjust colors based on light/dark mode settings.
|
72 |
+
:param cm: Confusion matrix data.
|
73 |
+
:param classes: List of class labels.
|
74 |
+
:param title: Plot title.
|
75 |
+
:param save_path: Path to save the plot.
|
76 |
+
:param dark_mode: Boolean to toggle between light and dark modes. If None, use the current theme.
|
77 |
+
"""
|
78 |
+
|
79 |
+
# If dark_mode is None, try detecting it from rcParams (matplotlib theme)
|
80 |
+
if dark_mode is None:
|
81 |
+
dark_mode = plt.rcParams['axes.facecolor'] == '#333333' # Check if dark background is set
|
82 |
+
|
83 |
# Compute the average F1-score
|
84 |
avg_f1 = compute_f1_score(cm)
|
85 |
|
86 |
# Choose the color scheme based on the mode
|
87 |
+
if dark_mode:
|
|
|
|
|
|
|
|
|
88 |
plt.style.use('dark_background') # Use dark mode styling
|
89 |
text_color = 'white'
|
90 |
cmap = 'cividis' # Dark-mode-friendly colormap
|
91 |
+
else:
|
92 |
+
plt.style.use('default') # Use default (light) mode styling
|
93 |
+
text_color = 'black'
|
94 |
+
cmap = 'Blues' # Light-mode-friendly colormap
|
95 |
|
96 |
plt.figure(figsize=(10, 10))
|
97 |
|
98 |
+
# Plot the confusion matrix with the selected colormap
|
99 |
sns.heatmap(cm, cmap=cmap, cbar=True, linecolor='white', vmin=0, vmax=cm.max(), alpha=0.85)
|
100 |
|
101 |
# Add F1-score to the title
|
|
|
116 |
# Return the saved image
|
117 |
return Image.open(save_path)
|
118 |
|
|
|
119 |
def compute_average_confusion_matrix(folder):
|
120 |
confusion_matrices = []
|
121 |
max_num_labels = 0
|