Scatterplot of deep learning model performance comparison

In the top conference articles, you can often see that when comparing models, it is often necessary to compare the efficiency, parameter quantity, accuracy and other indicators of the models. In the last article, I also compared the parameters of the model, FLOPs, accuracy, etc. I personally only use a single model for comparison, and record the code here for everyone to share. At the same time, you can see that a series of models are often selected for comparison in the top conference articles, and I also made this kind of picture. As shown below. (Text position can be adjusted as needed)

The code can be run directly.

import matplotlib.pyplot as plt
import numpy as np

#数据归一化
def nm(list):
    l = []
    M = max(list)
    m = min(list)
    for i in range(len(list)):
        x = (list[i] - m) / (M - m)
        l.append(x)
    return l

# 准备数据
#原始数据
parameters = [35,55, 72, 67, 60, 51,45,39]  # 参数量数据
flops = [8,50, 65, 49, 35, 15,29,60]  # FLOPs数据 X轴
miou = [20,64, 55, 49, 59, 63,70,75]  # MIou值数据  Y轴
txt = ["A","B","C","D","E","F","G","H"] #散点名称

# 设置散点的直径
diameter = nm(parameters) #归一化
diameters = [m * 10 for m in parameters]  # 将MIou值进行缩放,乘以100以适当调整直径大小

#显示网格线
plt.grid()
plt.grid(color='b',linestyle='--', linewidth=0.5,alpha=0.5)

#设置坐标轴刻度
x_ticks = np.arange(0, 80, 5)
y_ticks = np.arange(10, 100, 5)
plt.xticks(x_ticks)
plt.yticks(y_ticks)

#设置散点之间连线
#红色的点
rx = [8,15,50,60]
ry = [20,63,64,75]
plt.scatter(rx , ry)
plt.plot(rx, ry,linestyle='solid',color='r')
#黄色的点
yx = [65,35]
yy = [55,59]
plt.scatter(yx , yy)
plt.plot(yx , yy,linestyle='solid',color='y')

# 设置颜色列表 需要写成颜色对应的十六进制数
colors =['#FF0000','#FF0000','#FFD700','#FF1493','#FFD700','#FF0000','#008080','#FF0000']
# colors = np.random.rand(len(miou)) #随机设置颜色

# 绘制散点图
plt.scatter(flops,miou, s=diameters, c=colors,alpha=0.5,marker='o',linewidths=3)
# plt.scatter(flops,miou, s=diameters, c=colors,alpha=0.4,)

# 设置标题和坐标轴标签
# plt.title("Scatter Plot: Parameter vs FLOPs")
plt.xlabel("FLOPs")
plt.ylabel("MIoU")

#显示各散点名称以及调整文字的位置
for i in range(len(miou)):
    if i == 1:
        plt.annotate(txt[i], xy=(flops[i], miou[i]), xytext=(flops[i] - 3.5, miou[i] - 0.5))
    elif i == 2:
        plt.annotate(txt[i], xy=(flops[i], miou[i]), xytext=(flops[i] - 5, miou[i] + 0.4))
    elif i == 3:
        plt.annotate(txt[i], xy=(flops[i], miou[i]), xytext=(flops[i] - 2, miou[i] + 0.25),c="b",weight='heavy')
    elif i == 5:
        plt.annotate(txt[i], xy=(flops[i], miou[i]), xytext=(flops[i] - 4, miou[i] + 0.4))
    elif i == 6:
        plt.annotate(txt[i], xy=(flops[i], miou[i]), xytext=(flops[i] - 3, miou[i] + 0.35),c="y",weight='heavy')
    else:
        plt.annotate(txt[i], xy=(flops[i], miou[i]), xytext=(flops[i] - 3, miou[i] + 0.4))

#保存图片
plt.savefig("figure.jpg",dpi=1000,bbox_inches = 'tight')#当前路径下

# 显示图表
plt.show()




 The code generates a picture like this (you can set the scattered points you want to connect to the same color) 

Guess you like

Origin blog.csdn.net/qq_39333636/article/details/131812995