DeCLIP-TPAMI / tools /plot_linearv2.py
xiaomoguhzz's picture
Add files using upload-large-folder tool
7e3773e verified
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# --------------------------------------------------------------
# 1. 数据
# --------------------------------------------------------------
resolution = [336.00, 448.00, 560.00, 672.00, 784.00, 896.00, 1024.00]
roi_thing = {
"Resolution": resolution,
"CLIPself": [65.90, 69.50, 70.90, 71.70, 72.00, 72.60, 72.30],
"RegionCLIP": [66.40, 70.00, 71.20, 72.10, 72.10, 72.00, 71.90],
"DeCLIP": [68.90, 72.10, 74.30, 75.20, 75.50, 75.70, 75.40]
}
mask_thing = {
"Resolution": resolution,
"CLIPself": [60.10, 66.00, 69.50, 71.40, 72.70, 74.00, 74.60],
"RegionCLIP": [60.60, 66.90, 69.70, 72.50, 73.50, 73.90, 74.70],
"DeCLIP": [62.00, 68.40, 72.20, 74.50, 75.80, 76.80, 77.20]
}
mask_stuff = {
"Resolution": resolution,
"CLIPself": [40.80, 43.10, 44.60, 45.40, 45.90, 46.50, 46.90],
"RegionCLIP": [28.20, 30.10, 30.30, 31.10, 32.50, 35.00, 34.80],
"DeCLIP": [45.50, 49.10, 50.40, 51.20, 51.30, 52.70, 52.50]
}
df_roi_thing = pd.DataFrame(roi_thing)
df_mask_thing = pd.DataFrame(mask_thing)
df_mask_stuff = pd.DataFrame(mask_stuff)
# --------------------------------------------------------------
# 2. 全局风格
# --------------------------------------------------------------
sns.set_style('white')
plt.rcParams.update({
'font.size' : 10,
'axes.labelsize' : 10,
'xtick.labelsize' : 8,
'ytick.labelsize' : 8,
# 折线 & 标记
'lines.linewidth' : 1.5, # 更细的折线
'lines.markersize' : 8, # 更大的数据点
'lines.markeredgewidth': 0.8, # 更细描边
# 图例
'legend.fontsize' : 9,
# 网格
'axes.grid' : True,
'grid.linestyle' : '--',
'grid.alpha' : 0.3, # 更淡
'grid.color' : 'gray',
'grid.linewidth' : 0.5, # 更细
# 坐标轴外框
'axes.spines.right': False,
'axes.spines.top' : False,
'axes.linewidth' : 1.2
})
# 调色盘与标记
palette = {
'CLIPself' : '#80b1d3', # 浅蓝
'RegionCLIP': '#fb8072', # 珊瑚红
'DeCLIP' : '#8dd3c7' # 青绿
}
markers = {
'CLIPself' : 'o',
'RegionCLIP': '^',
'DeCLIP' : 'D'
}
# --------------------------------------------------------------
# 3. 画图函数
# --------------------------------------------------------------
def plot_and_save(df, y_label, filename):
fig, ax = plt.subplots(figsize=(4, 3))
for key in ['CLIPself', 'RegionCLIP', 'DeCLIP']:
ax.plot(
df['Resolution'], df[key],
linestyle='-', # 实线
marker=markers[key],
color=palette[key],
markeredgecolor='black',
label=key
)
ax.set_xlabel('Resolution')
ax.set_ylabel(y_label)
ax.set_xticks(resolution)
ax.legend(frameon=False, loc='best')
fig.tight_layout()
fig.savefig(filename, dpi=300)
plt.close(fig)
# --------------------------------------------------------------
# 4. 生成三张图
# --------------------------------------------------------------
plot_and_save(df_roi_thing, 'RoI Align (Thing) mAcc', 'roi_thing.png')
plot_and_save(df_mask_thing, 'Mask Pooling (Thing) mAcc', 'mask_thing.png')
plot_and_save(df_mask_stuff, 'Mask Pooling (Stuff) mAcc', 'mask_stuff.png')