DeCLIP-TPAMI / tools /plot_hyperv2.py
xiaomoguhzz's picture
Add files using upload-large-folder tool
7e3773e verified
import matplotlib.pyplot as plt
import numpy as np
# 数据集
datasets = {
"COCO-Stuff": [25.44, 26.07, 26.64, 26.82, 26.91, 27.05, 27.0, 27.13, 27.17, 27.21],
"ADE": [21.88, 22.54, 23.03, 23.14, 23.16, 23.24, 23.17, 23.24, 23.24, 23.22],
"CityScape": [34.53, 35.62, 35.81, 35.75, 35.71, 35.59, 35.37, 35.37, 35.36, 35.38],
"COCO-Obj": [37.01, 37.9, 38.55, 38.7, 38.71, 38.76, 38.58, 38.79, 38.79, 38.82],
"Context 60": [35.82, 36.71, 37.69, 37.9, 38.05, 38.25, 38.48, 38.53, 38.59, 38.65],
"Context 59": [39.64, 40.46, 41.41, 41.63, 41.75, 41.94, 42.2, 42.2, 42.25, 42.32],
"VOC 20": [83.53, 84.57, 85.29, 85.33, 85.43, 85.58, 85.17, 85.62, 85.63, 85.58],
"VOC 21": [61.44, 62.58, 63.74, 64.1, 64.39, 64.74, 64.91, 65.19, 65.33, 65.44],
"OV-COCO": [41.7, 42.8, 43.3, 42.7, 42.4, 42.0, 42.2, 41.8, 42.0, 41.5],
}
hyperparams = np.linspace(0.1, 1.0, 10)
# 可自定义
colors = ['#9467bd', '#ff7f0e', '#2ca02c', '#2077b4', '#8c564b']
markers = ['o', 's', '^', 'D', 'P']
linestyle = '--'
groups = [
["COCO-Stuff", "ADE"], # 组1
["COCO-Obj", "Context 60", "Context 59", "CityScape", "OV-COCO"], # 组2
["VOC 20", "VOC 21"], # 组3
]
# 组的文件名
group_filenames = ["group1.png", "group2.png", "group3.png"]
# OV-COCO 专属样式
ov_coco_color = '#d62728'
ov_coco_marker = 'o'
ov_coco_linestyle = '-'
for group_idx, group in enumerate(groups):
plt.figure(figsize=(6, 4))
for idx, dataset_name in enumerate(group):
if dataset_name == "OV-COCO":
plt.plot(
hyperparams, datasets[dataset_name],
label=dataset_name,
linestyle=ov_coco_linestyle, # 实线
marker=ov_coco_marker,
color=ov_coco_color,
linewidth=5,
markersize=10,
zorder=10,
)
else:
color = colors[idx % len(colors)]
marker = markers[idx % len(markers)]
plt.plot(
hyperparams, datasets[dataset_name],
label=dataset_name,
linestyle=linestyle,
marker=marker,
color=color,
linewidth=4,
markersize=8,
)
plt.xlabel("")
plt.ylabel("")
plt.grid(True, linestyle='--', alpha=0.6)
plt.tick_params(axis='both', which='major', labelsize=8)
plt.tight_layout()
# 针对第二组手动设置 legend 位置
if group_idx == 1:
# 你可以在这里调整 loc 和 bbox_to_anchor
plt.legend(fontsize=10, loc='upper left', bbox_to_anchor=(0.5, 0.41),ncol=2)
else:
plt.legend(fontsize=15,loc='center right')
plt.savefig(group_filenames[group_idx], dpi=300)
plt.close()