DeCLIP-TPAMI / tools /plot_cc3m.py
xiaomoguhzz's picture
Add files using upload-large-folder tool
7e3773e verified
import matplotlib.pyplot as plt
import seaborn as sns
# 设置数据
data_size = ["30K", "60K", "120K", "240K", "480K"]
avg_segmentation_MIoU = [37.05, 41.7, 42.0, 41.9, 41.8]
# COCO Distill 数据
coco_distill_avg_segmentation_MIoU = [None, None, 41.9, None, None] # 只画一个点
# 设置绘图风格和颜色
sns.set_style("whitegrid")
# 定义新的颜色、线条样式和标记符号
color_palette = ['#1f77b4', '#ff7f0e', '#2ca02c'] # 为 COCO 添加新颜色
line_styles = ['--', '-.', ':'] # 为 COCO 添加新线条样式
markers = ['o', 's', 'D'] # 为 COCO 添加新标记符号
# 设置全局字体和线宽
plt.rcParams.update({
'font.size': 10, # 字体大小
'axes.labelsize': 10,
'lines.linewidth': 2.0, # 线条宽度
'legend.fontsize': 8, # 图例字体大小
'xtick.labelsize': 8, # x轴刻度字体大小
'ytick.labelsize': 8, # y轴刻度字体大小
'grid.color': 'gray', # 网格线颜色
'grid.alpha': 0.3, # 调整网格线透明度
})
# 绘制折线图
plt.figure(figsize=(4, 2)) # 调整图的大小
plt.plot(data_size, avg_segmentation_MIoU, linestyle=line_styles[0], marker=markers[0], color=color_palette[0], label='Avg mIoU (CC3M Distillation)')
# 绘制 COCO 点(空心红色散点)
plt.scatter(
data_size,
coco_distill_avg_segmentation_MIoU,
edgecolor='red', # 散点边框颜色
facecolor='none', # 空心
marker=markers[2], # 标记样式
s=50, # 散点大小(增大)
linewidths=2, # 边框宽度(加粗)
label='Avg mIoU (COCO Distillation)',
zorder=5
)
# 设置轴标签并调整标签与坐标轴的距离
plt.xlabel('Data Size (sample from CC3M)', labelpad=0) # 横坐标标签,设置距离
plt.ylabel('Performance (ViT-B)', labelpad=0) # 纵坐标标签,设置距离
plt.grid(True, linestyle='--', color='gray', alpha=0.3) # 更淡的网格
plt.legend(loc='best', fontsize=10) # 图例位置和字体大小
plt.tight_layout()
plt.savefig('data_size_metrics.pdf', dpi=300) # 保存为PDF
plt.close()