DeCLIP-TPAMI / tools /plot_radarv2.py
xiaomoguhzz's picture
Add files using upload-large-folder tool
c50dde6 verified
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Patch
# 数据
labels = [
'ADE847', 'PC459', 'ADE150', 'PC59', 'VOC20', 'VOC21',
'OV-COCO', 'OV-LVIS', 'Obj365', 'COCO',
'PC60', 'COCO-Obj', 'City', 'PC59', 'ADE', 'COCO-Stf'
]
declip_value = [15.3, 21.4, 36.3, 60.6, 96.6, 81.3,
49.5, 41.5, 20.0, 41.5,
37.9, 38.7, 35.7, 41.6, 23.1, 26.8]
catseg_value = [12.0, 19.0, 31.8, 57.5, 94.6, 77.3,
0, 0, 0, 0,
0, 0, 0, 0, 0, 0]
clipself_value = [0, 0, 0, 0, 0, 0,
44.3, 34.9, 19.5, 40.5,
0, 0, 0, 0, 0, 0]
clearclip_value = [0, 0, 0, 0,
0, 0, 0, 0, 0, 0,
32.6, 33.0, 30.0, 35.9, 16.7, 23.9]
declip_target = 40
# 自动计算归一化值
def normalize_values(target, base_values, method_values):
"""根据 base_values 和 method_values 的比例计算归一化值"""
normalized = []
for base, value in zip(base_values, method_values):
if base == 0 or value == 0: # 如果值为 0,不进行计算,直接保留 0
normalized.append(0)
else:
normalized.append((value / base) * target)
return normalized
declip = normalize_values(declip_target, declip_value, declip_value)
catseg = normalize_values(declip_target, declip_value, catseg_value)
clipself = normalize_values(declip_target, declip_value, clipself_value)
clearclip = normalize_values(declip_target, declip_value, clearclip_value)
# 设置不均匀的角度
group1_angles = np.linspace(0, np.deg2rad(90), 6).tolist() # 0-90度
gap1 = np.deg2rad(50) # 50度的间隔
group2_angles = np.linspace(np.deg2rad(90) + gap1, np.deg2rad(90) + gap1 + np.deg2rad(60), 4).tolist() # 140-200度
gap2 = np.deg2rad(50) # 50度的间隔
group3_angles = np.linspace(np.deg2rad(90) + gap1 + np.deg2rad(60) + gap2, np.deg2rad(90) + gap1 + np.deg2rad(60) + gap2 + np.deg2rad(90), 6).tolist() # 250-340度
angles = group1_angles + group2_angles + group3_angles
angles += angles[:1] # 闭合曲线
# 数据补充,首尾相连
declip = np.concatenate((declip, [declip[0]]))
catseg = np.concatenate((catseg, [catseg[0]]))
clipself = np.concatenate((clipself, [clipself[0]]))
clearclip = np.concatenate((clearclip, [clearclip[0]]))
# 创建图形,调整figsize
fig, ax = plt.subplots(figsize=(8, 8), subplot_kw=dict(polar=True))
ax.set_ylim(0, 41.5)
# 添加径向为40的圆
r_circle = 41.5
theta = np.linspace(0, 2 * np.pi, 500)
ax.plot(theta, [r_circle] * len(theta), color='black', linestyle='-', linewidth=1.2, alpha=1.0, zorder=0)
# 移除径向线的刻度
ax.set_yticks([10,20,30,40])
# 绘制每组数据的区域,增加透明度
ax.fill(angles, declip, color='#3dab5a', alpha=0.15, label='DECLIP', zorder=1)
ax.fill(angles, catseg, color='#ad4fa0', alpha=0.2, label='Previous SOTA CATSeg', zorder=1)
ax.fill(angles, clipself, color='#2b83bc', alpha=0.2, label='Previous SOTA CLIPSelf', zorder=1)
ax.fill(angles, clearclip, color='#C65F10', alpha=0.2, label='Previous SOTA ClearCLIP', zorder=1)
# 绘制边框线
ax.plot(angles, declip, color='#52b36a', linewidth=1.5, linestyle='solid', zorder=2)
ax.plot(angles, catseg, color='#ad4fa0', linewidth=1.5, linestyle='solid', zorder=2)
ax.plot(angles, clipself, color='#2b83bc', linewidth=1.5, linestyle='solid', zorder=2)
ax.plot(angles, clearclip, color='#C65F10', linewidth=1.5, linestyle='solid', zorder=2)
# 绘制数据点
ax.scatter(angles, declip, facecolors='#3dab5a', s=35, zorder=3, alpha=0.9)
ax.scatter(angles, catseg, facecolors='#ad4fa0', s=35, zorder=3, alpha=0.9)
ax.scatter(angles, clipself, facecolors='#2b83bc', s=35, zorder=3, alpha=0.9)
ax.scatter(angles, clearclip, facecolors='#C65F10', s=35, zorder=3, alpha=0.9)
# 设置标签
ax.set_xticks(angles[:-1])
ax.set_xticklabels(labels, fontsize=12, ha='center', va='top', color='black') # 标签颜色透明
# 在每个数据点上标注其对应的值(移除 declip 的数值标注部分)
for angle, position, value in zip(angles, catseg, catseg_value):
if value > 0:
ax.text(angle, position - 1, f'{value}', color='#92278f', fontsize=12, ha='right', va='top')
for angle, position, value in zip(angles, clipself, clipself_value):
if value > 0:
ax.text(angle, position - 1, f'{value}', color='#213f9a', fontsize=12, ha='left', va='top')
for angle, position, value in zip(angles, clearclip, clearclip_value):
if value > 0:
ax.text(angle, position - 1.0, f'{value}', color='#C65F10', fontsize=12, ha='right', va='bottom')
# 添加图例
legend_elements = [
Patch(facecolor='#3dab5a', edgecolor='#3dab5a', label='DeCLIP (Ours)'),
Patch(facecolor='#ad4fa0', edgecolor='#ad4fa0', label='CATSeg (OVSS SOTA)'),
Patch(facecolor='#2b83bc', edgecolor='#2b83bc', label='CLIPSelf (OVD SOTA)'),
Patch(facecolor='#C65F10', edgecolor='#C65F10', label='ClearCLIP (ZSSS SOTA)'),
]
ax.legend(
handles=legend_elements,
frameon=True,
fontsize='large',
loc='center',
bbox_to_anchor=(0.26, 0.99),
framealpha=0.5
)
ax.set_yticklabels([])
# 调整图形布局
plt.tight_layout()
# 保存图片
plt.savefig('radar_chart.png', dpi=200, bbox_inches='tight', transparent=True)
# 显示图像
plt.close()