Update grace_eval.py
Browse files- grace_eval.py +26 -18
grace_eval.py
CHANGED
@@ -1,30 +1,38 @@
|
|
|
|
|
|
1 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def compute_sample_scores(results, prompt):
|
4 |
-
|
5 |
return {
|
6 |
-
"sd_v1_5":
|
7 |
-
"openjourney_v4":
|
8 |
-
"ldm_256":
|
9 |
}
|
10 |
|
11 |
def plot_radar(scores_dict, out_path="radar.png"):
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
|
|
|
16 |
|
17 |
for model, scores in scores_dict.items():
|
18 |
-
|
19 |
-
|
20 |
-
angles =
|
21 |
-
angles += angles[:1]
|
22 |
-
ax.plot(angles, values, linewidth=1, linestyle='solid', label=model)
|
23 |
-
ax.fill(angles, values, alpha=0.1)
|
24 |
|
25 |
-
ax.
|
26 |
-
ax.
|
27 |
-
ax.set_title("GRACE 评估雷达图 (CPU模式)", size=12, y=1.1)
|
28 |
ax.legend(loc='upper right')
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import matplotlib
|
2 |
+
matplotlib.use('Agg')
|
3 |
import matplotlib.pyplot as plt
|
4 |
+
import numpy as np
|
5 |
+
from PIL import Image
|
6 |
+
import io
|
7 |
+
|
8 |
+
DIMENSIONS = ["Generalization", "Relevance", "Artistry", "Efficiency"]
|
9 |
|
10 |
def compute_sample_scores(results, prompt):
|
11 |
+
"""模拟评分 - 实际项目应替换为真实评估逻辑"""
|
12 |
return {
|
13 |
+
"sd_v1_5": [4, 4, 4, 3],
|
14 |
+
"openjourney_v4": [3, 4, 5, 3],
|
15 |
+
"ldm_256": [2, 3, 3, 5]
|
16 |
}
|
17 |
|
18 |
def plot_radar(scores_dict, out_path="radar.png"):
|
19 |
+
fig = plt.figure(figsize=(8, 8))
|
20 |
+
ax = fig.add_subplot(111, polar=True)
|
21 |
|
22 |
+
angles = np.linspace(0, 2*np.pi, len(DIMENSIONS), endpoint=False)
|
23 |
+
angles = np.concatenate((angles, [angles[0]]))
|
24 |
|
25 |
for model, scores in scores_dict.items():
|
26 |
+
data = np.concatenate((scores, [scores[0]]))
|
27 |
+
ax.plot(angles, data, linewidth=2, linestyle='solid', label=model)
|
28 |
+
ax.fill(angles, data, alpha=0.1)
|
|
|
|
|
|
|
29 |
|
30 |
+
ax.set_thetagrids(angles[:-1] * 180/np.pi, DIMENSIONS)
|
31 |
+
ax.set_title("GRACE Evaluation Radar", size=14, pad=20)
|
|
|
32 |
ax.legend(loc='upper right')
|
33 |
+
|
34 |
+
buf = io.BytesIO()
|
35 |
+
plt.savefig(buf, format='png', bbox_inches='tight')
|
36 |
+
plt.close()
|
37 |
+
buf.seek(0)
|
38 |
+
return Image.open(buf)
|