欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Focal Loss的python绘图

程序员文章站 2022-05-21 09:29:47
...

Focal Loss的python代码如下:

#coding:utf-8

import matplotlib.pyplot as plt
import numpy as np
from numpy.lib.scimath import logn
from math import e
import matplotlib as mpl
#防止中文乱码问题
mpl.rcParams['font.sans-serif']=[u'SimHei']
mpl.rcParams['axes.unicode_minus']=False

mpl.rcParams['figure.figsize'] = [9, 8] # for square canvas
x=np.arange(0,1,0.01)  #创建100个0到6之间的等比数列

#plt.plot(x,np.log(x)/np.log(0.5),'y-', linewidth=2, label=u'log0.5(x)')#log0.5(x)
plt.plot(x,-logn(e,x),'b-',linewidth=2, label=u'β= 0')#loge(x)
plt.plot(x,-logn(e,x)*(1-x),'r-',linewidth=2, label=u'β= 1')
plt.plot(x,-logn(e,x)*pow((1-x),2),'g-',linewidth=2, label=u'β= 2')
plt.plot(x,-logn(e,x)*pow((1-x),3),'y-',linewidth=2, label=u'β= 3')
plt.plot(x,-logn(e,x)*pow((1-x),4),'c-',linewidth=2, label=u'β= 4')
#plt.plot(x,np.log(x)/np.log(5))
#plt.plot(x,logn(5,x),'g-',linewidth=2, label=u'loge(x)') #等于求log5(X)
#plt.plot(x,np.log10(x),'r-',linewidth=2, label=u'loge(x)')#log10(x)

plt.axis([0, 1, 0, 5.])#指定画图板的长宽


plt.xticks( size = 12)
plt.yticks( size = 12)

plt.ylabel("损失L",fontdict={'weight': 'normal', 'size': 13})
plt.xlabel("类别概率Pt",fontdict={'weight': 'normal', 'size': 14})
plt.legend(loc = 'upper right',prop={ 'size' : 13}) #图例的位置
#plt.grid(True)#需要网格
plt.show()

Focal Loss的python绘图

#coding:utf-8

import matplotlib.pyplot as plt
import numpy as np
from numpy.lib.scimath import logn
from math import e
import matplotlib as mpl
#防止中文乱码问题
mpl.rcParams['font.sans-serif']=[u'SimHei']
mpl.rcParams['axes.unicode_minus']=False

mpl.rcParams['figure.figsize'] = [9, 8] # for square canvas
#x=np.arange(0,1,0.01)  #创建100个0到6之间的等比数列
x=np.linspace(0,1,50)  #创建100个0到6之间的等比数列

#plt.plot(x,np.log(x)/np.log(0.5),'y-', linewidth=2, label=u'log0.5(x)')#log0.5(x)
plt.plot(x,-logn(e,x),'ob-',linewidth=0.5,markersize=3, label=u'β= 0')#loge(x)
plt.plot(x,-logn(e,x)*(1-x),'+r-',linewidth=0.5,markersize=5, label=u'β= 1')
plt.plot(x,-logn(e,x)*pow((1-x),2),'sg-',linewidth=0.5,markersize=3, label=u'β= 2')
plt.plot(x,-logn(e,x)*pow((1-x),3),'*y-',linewidth=0.5,markersize=3, label=u'β= 3')
plt.plot(x,-logn(e,x)*pow((1-x),4),'+c-',linewidth=0.5,markersize=3, label=u'β= 4')
#plt.plot(x,np.log(x)/np.log(5))
#plt.plot(x,logn(5,x),'g-',linewidth=2, label=u'loge(x)') #等于求log5(X)
#plt.plot(x,np.log10(x),'r-',linewidth=2, label=u'loge(x)')#log10(x)

plt.axis([0, 1, 0, 5.])#指定画图板的长宽


plt.xticks( size = 12)
plt.yticks( size = 12)

plt.ylabel("损失L",fontdict={'weight': 'normal', 'size': 13})
plt.xlabel("类别概率Pt",fontdict={'weight': 'normal', 'size': 14})
plt.legend(loc = 'upper right',prop={ 'size' : 13}) #图例的位置
#plt.grid(True)#需要网格
plt.show()

 Focal Loss的python绘图

相关标签: python plot