介绍
本篇文章为大家展示了怎么在pytorch中绘制一个曲线,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
具体内容如下
import 火炬 import torch.nn.functional  as F 得到torch.autograd import 变量 import matplotlib.pyplot  as plt , # fake 数据 时间=x torch.linspace (5,, 5, 200), #, x data (张量),形状=(100,1) 时间=x 变量(x), #创建,变量(变量),构造神经网络要使用变量类型 时间=x_np x.data.numpy (), #, numpy array for 策划,用于绘图的numpy数组 , #,following 断开连接;popular  activation 功能,以下是常用的激活函数 时间=y_relu torch.relu (x) .data.numpy () 时间=y_sigmoid torch.sigmoid (x) .data.numpy () 时间=y_tanh torch.tanh (x) .data.numpy () 时间=y_softplus F.softplus (x) .data.numpy(), #,还有# 39;s no softplus 拷贝torch.torch没有softplus=#,y_softmax torch.softmax (x,,暗=0).data.numpy (), softmax is a special kind of activation 函数,it is about 概率 # softmax是一种特殊的激活函数,它与概率有关 , , #,plt 用visualize these activation 函数 #将这些激活函数可视化 plt.figure (1, figsize=(8, 6)), #,横坐标与纵坐标 plt.subplot (221) # plt.subplot()函数用于直接指定划分方式和位置进行绘图。 #,使用plt.subplot来创建小图只plt.subplot(221)表示将整个图像窗口分为2行2列,,当前位置为1。 plt.plot (x_np, y_relu, c=& # 39;红色# 39;,,标签=& # 39;relu& # 39;) # plt.plot (x, y, format_string * * kwargs) # x轴数据,y轴数据,format_string控制曲线的格式字串 # format_string 由颜色字符,风格字符,和标记字符 plt.ylim((1), 5)), #,设置纵坐标的范围 plt.legend (loc=& # 39;最佳# 39;)# plt.legend()函数的作用是给图像加图例,就左上角relu那个 #图例是集中于地图一角或一侧的地图上各种符号和颜色所代表内容与指标的说明,有助于更好的认识地图 , plt.subplot(222) #,使用plt.subplot来创建小图只plt.subplot(221)表示将整个图像窗口分为2行2列,,当前位置为2。 plt.plot (x_np, y_sigmoid, c=& # 39;红色# 39;,,标签=& # 39;乙状结肠# 39;) # plt.plot (x, y, format_string * * kwargs) # x轴数据,y轴数据,format_string控制曲线的格式字串 # format_string 由颜色字符,风格字符,和标记字符 plt.ylim((-0.2, 1.2), #,设置纵坐标的范围 plt.legend (loc=& # 39;最佳# 39;)# plt.legend()函数的作用是给图像加图例,就左上角relu那个 #图例是集中于地图一角或一侧的地图上各种符号和颜色所代表内容与指标的说明,有助于更好的认识地图 , plt.subplot(223) #,使用plt.subplot来创建小图只plt.subplot(221)表示将整个图像窗口分为2行2列,,当前位置为3。 plt.plot (x_np, y_tanh, c=& # 39;红色# 39;,,标签=& # 39;双曲正切# 39;) # plt.plot (x, y, format_string * * kwargs) # x轴数据,y轴数据,format_string控制曲线的格式字串 # format_string 由颜色字符,风格字符,和标记字符 plt.ylim((-1.2, 1.2)) #,设置纵坐标的范围 plt.legend (loc=& # 39;最佳# 39;)# plt.legend()函数的作用是给图像加图例,就左上角relu那个 #图例是集中于地图一角或一侧的地图上各种符号和颜色所代表内容与指标的说明,有助于更好的认识地图 , plt.subplot(224) #,使用plt.subplot来创建小图只plt.subplot(221)表示将整个图像窗口分为2行2列,,当前位置为4。 plt.plot (x_np, y_softplus, c=& # 39;红色# 39;,,标签=& # 39;softplus& # 39;) # plt.plot (x, y, format_string * * kwargs) # x轴数据,y轴数据,format_string控制曲线的格式字串 # format_string 由颜色字符,风格字符,和标记字符 plt.ylim((-0.2, 6)) #,设置纵坐标的范围 plt.legend (loc=& # 39;最佳# 39;)# plt.legend()函数的作用是给图像加图例,就左上角relu那个 #图例是集中于地图一角或一侧的地图上各种符号和颜色所代表内容与指标的说明,有助于更好的认识地图 , plt.show () # plt.show()则是将plt.imshow()处理后的函数显示出来。
运行结果:
上述内容就是怎么在pytorch中绘制一个曲线,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。