xiehuangbao1122 commited on
Commit
baa93b6
·
verified ·
1 Parent(s): a20155e

Update grace_eval.py

Browse files
Files changed (1) hide show
  1. 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": {"G": 4, "R": 4, "A": 4, "E": 3},
7
- "openjourney_v4": {"G": 3, "R": 4, "A": 5, "E": 3},
8
- "ldm_256": {"G": 2, "R": 3, "A": 3, "E": 5}
9
  }
10
 
11
  def plot_radar(scores_dict, out_path="radar.png"):
12
- categories = list(scores_dict.values())[0].keys()
13
- N = len(categories)
14
 
15
- fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
 
16
 
17
  for model, scores in scores_dict.items():
18
- values = list(scores.values())
19
- values += values[:1] # 闭合雷达图
20
- angles = [n / float(N) * 2 * 3.14159 for n in range(N)]
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.set_xticks(angles[:-1])
26
- ax.set_xticklabels(categories)
27
- ax.set_title("GRACE 评估雷达图 (CPU模式)", size=12, y=1.1)
28
  ax.legend(loc='upper right')
29
- plt.savefig(out_path, bbox_inches='tight')
30
- plt.close()
 
 
 
 
 
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)