for_fake_test / plot.eer.py
fbsong's picture
Add files using upload-large-folder tool
917518d verified
Raw History Blame Contribute Delete
4.86 kB
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.patches as patches
plt.rcParams["font.family"] = "Times New Roman"
plt.rcParams["font.size"] = 10
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# 1. 构造数据(行和列完全按照你给的表格顺序)
# cols = [
# "LA19", "LA21", "itw", "CFAD_seen", "CFAD_unseen",
# "ST_codecfake", "omni-vocder", "omni-codec", "omni-adult",
# "omni-child", "omni-elder", "omni-lang_zh", "omni-lang_en",
# "omni-test", "omni-attack"
# ]
# # 数据矩阵(11行 × 15列),与你给出的表格完全一致
# data = np.array([
# [ 0.16, 0.78, 10.41, 14.74, 22.53, 40.71, 34.77, 38.62, 30.34, 38.12, 39.17, 36.20, 38.05, 36.70, 44.87],
# [ 2.77, 6.91, 10.97, 0.13, 24.87, 12.32, 21.16, 26.72, 19.72, 24.98, 27.30, 21.50, 26.70, 24.09, 42.62],
# [ 2.55, 7.02, 5.53, 8.38, 24.29, 0.01, 26.17, 13.67, 16.58, 23.23, 20.33, 18.10, 19.67, 19.95, 38.20],
# [ 4.73, 12.38, 2.54, 0.76, 26.91, 17.68, 0.68, 18.25, 11.58, 8.90, 12.43, 12.43, 11.59, 14.11, 10.97],
# [ 5.85, 10.86, 2.12, 4.28, 24.61, 0.64, 16.27, 0.27, 10.52, 10.13, 9.83, 9.83, 10.58, 15.75, 10.41],
# [ 1.80, 10.49, 2.34, 0.71, 24.42, 1.43, 11.85, 11.23, 0.45, 26.69, 7.48, 6.15, 17.90, 14.44, 11.56],
# [ 2.27, 8.45, 2.06, 1.00, 24.31, 2.99, 3.42, 2.25, 2.82, 0.76, 4.88, 2.81, 2.81, 10.93, 2.86],
# [ 1.40, 4.43, 1.94, 0.25, 24.43, 1.66, 10.71, 10.01, 3.70, 24.79, 1.45, 4.08, 15.35, 11.63, 10.36],
# [ 1.93, 9.27, 2.34, 0.11, 23.80, 1.35, 7.66, 6.89, 1.72, 13.41, 4.29, 1.02, 11.43, 11.29, 7.32],
# [ 1.05, 5.00, 1.76, 0.33, 22.89, 1.01, 3.70, 2.50, 1.16, 3.64, 3.93, 4.81, 0.94, 11.00, 3.14],
# [ 1.68, 5.99, 1.68, 0.11, 23.59, 0.55, 1.03, 0.56, 0.50, 0.68, 1.31, 0.96, 0.69, 0.82, 8.01]
# ])
cols = [
"LA19", "LA21", "itw", "CFAD",
"ST_codecfake", "omni-vocder", "omni-codec", "omni-adult",
"omni-child", "omni-elder", "omni-lang_zh", "omni-lang_en",
"omni-test", "omni-attack"
]
rows = [
"LA19", "CFAD", "ST_codecfake", "omni-vocder", "omni-codec",
"omni-adult", "omni-child", "omni-elder", "omni-lang_zh",
"omni-lang_en", "OmniSynSpoof"
]
# 数据矩阵(11行 × 15列),与你给出的表格完全一致
data = np.array([
[ 0.16, 0.78, 10.41, 14.74, 40.71, 34.77, 38.62, 30.34, 38.12, 39.17, 36.20, 38.05, 36.70, 44.87],
[ 2.77, 6.91, 10.97, 0.13, 12.32, 21.16, 26.72, 19.72, 24.98, 27.30, 21.50, 26.70, 24.09, 42.62],
[ 2.55, 7.02, 5.53, 8.38, 0.01, 26.17, 13.67, 16.58, 23.23, 20.33, 18.10, 19.67, 19.95, 38.20],
[ 4.73, 12.38, 2.54, 0.76, 17.68, 0.68, 18.25, 11.58, 8.90, 12.43, 12.43, 11.59, 10.97,14.11, ],
[ 5.85, 10.86, 2.12, 4.28, 0.64, 16.27, 0.27, 10.52, 10.13, 9.83, 9.83, 10.58, 10.41,15.75, ],
[ 1.80, 10.49, 2.34, 0.71, 1.43, 11.85, 11.23, 0.45, 26.69, 7.48, 6.15, 17.90, 11.56,14.44, ],
[ 2.27, 8.45, 2.06, 1.00, 2.99, 3.42, 2.25, 2.82, 0.76, 4.88, 2.81, 2.81, 2.86,10.93, ],
[ 1.40, 4.43, 1.94, 0.25, 1.66, 10.71, 10.01, 3.70, 24.79, 1.45, 4.08, 15.35, 10.36,11.63, ],
[ 1.93, 9.27, 2.34, 0.11, 1.35, 7.66, 6.89, 1.72, 13.41, 4.29, 1.02, 11.43, 7.32,11.29, ],
[ 1.05, 5.00, 1.76, 0.33, 1.01, 3.70, 2.50, 1.16, 3.64, 3.93, 4.81, 0.94, 3.14,11.00, ],
[ 1.68, 5.99, 1.68, 0.11, 0.55, 1.03, 0.56, 0.50, 0.68, 1.31, 0.96, 0.69, 0.82, 8.01]
])
df = pd.DataFrame(data, index=rows, columns=cols)
# 2. 设置字体(避免 Times New Roman 缺失警告)
plt.rcParams['font.family'] = 'sans-serif'
plt.rcParams['font.sans-serif'] = ['DejaVu Sans', 'Arial', 'Helvetica']
# 3. 绘图
plt.figure(figsize=(18, 8))
# 颜色映射:浅色=低EER(好),深色=高EER(差),并限制颜色范围
ax = sns.heatmap(df, annot=True, fmt=".2f", cmap="Blues_r", linewidths=0.5,
cbar_kws={'label': 'EER (%)'}, vmin=0, vmax=50)
# 4. 高亮行列名称相同的单元格(自身测试)
for i in range(len(rows)):
for j in range(len(cols)):
if rows[i] == cols[j]:
ax.add_patch(plt.Rectangle((j, i), 1, 1, fill=False, edgecolor='blue', lw=2))
elif rows[i] =='OmniSynSpoof' and cols[j]=='omni-test':
ax.add_patch(plt.Rectangle((j, i), 1, 1, fill=False, edgecolor='blue', lw=2))
# 5. 标题和标签
# plt.title("EER Heatmap", fontsize=14, fontweight='bold')
plt.xlabel("Test Dataset", fontsize=12)
plt.ylabel("Train Dataset", fontsize=12)
plt.xticks(rotation=45, ha='right')
plt.yticks(rotation=0)
plt.tight_layout()
# plt.savefig("eer_heatmap.png", dpi=150)
# plt.show()
plt.savefig("heatmap_usenix.pdf",dpi=600,bbox_inches="tight")
plt.savefig("heatmap_usenix.png",dpi=600,bbox_inches="tight")
plt.show()