当前位置: 首页 > news >正文

pytorch学习(九)激活函数

1.pytorch常用激活函数如下:

#ReLU激活函数
#Leaky ReLU激活函数
#Sigmoid激活函数
#Tanh激活函数
#Softmax激活函数
#Softplus

2.代码

import torch.nn as nn
import torch
import numpy
from torch.utils.tensorboard import SummaryWriterwriter = SummaryWriter("logs")input = torch.arange(-10,10,dtype=float)#ReLU激活函数
relu = nn.ReLU()
output_relu = relu(input)#Leaky ReLU激活函数
LeakyReLU=nn.LeakyReLU()
output_LeakyReLU = LeakyReLU(input)#Sigmoid激活函数
Sigmoid = nn.Sigmoid()
output_Sigmoid = Sigmoid(input)#Tanh激活函数
Tanh = nn.Tanh()
output_Tanh = Tanh(input)#Softmax激活函数
Softmax = nn.Softmax(dim=0)
output_Softmax = Softmax(input)Softplus = torch.nn.Softplus()
output_Softplus = Softplus(input)for i in range(len(input)):writer.add_scalar('Relu',output_relu[i],input[i])writer.add_scalar('LeakyReLU',output_LeakyReLU[i],input[i])writer.add_scalar('Sigmoid',output_Sigmoid[i],input[i])writer.add_scalar('Tanh',output_Tanh[i],input[i])writer.add_scalar('Softmax',output_Softmax[i],input[i])writer.add_scalar('Softplus',output_Softplus[i],input[i])# writer.add_scalars('run_14h', {'Relu': output_relu[i],#                                'LeakyReLU': output_LeakyReLU[i],#                                'Sigmoid': output_Sigmoid[i]}, input[i])writer.close()

3.结果显示:

http://www.lryc.cn/news/403232.html

相关文章:

  • conda 环境打包与使用
  • jenkins 插件版本冲突
  • Python print() 格式化输出
  • 【Qt+opencv】计时函数与图像变换
  • nodejs下载+react安装
  • linux service小例
  • iOS 开发包管理之 Swift Package Manager
  • 【C语言初阶】C语言数组基础:从定义到遍历的全面指南
  • AI开源战争的真相
  • 使用Java填充Word模板的技术详解
  • vmware配置centos+配置静态ip联网+更换镜像
  • 广州数据中心服务器搬迁方案
  • uniapp开发钉钉小程序流程
  • 河南萌新联赛2024第(一)场:河南农业大学 A D F G H I K
  • 通信协议_C#实现CAN通信
  • 【AI工具基础】—B树(B-tree)
  • STM32智能仓库管理系统教程
  • 空间计算开发:Volu的集成开发工具包
  • 02-Redis未授权访问漏洞
  • Linux——多路复用之poll
  • 【AI资讯】7.19日凌晨OpenAI发布迷你AI模型GPT-4o mini
  • 3.设计模式--创建者模式--工厂模式
  • IOT 的 10 种常见协议、组网模式、特点及其使用场景浅析
  • 【Android】 dp与sp,加冕为王
  • R语言画散点图-饼图-折线图-柱状图-箱线图-直方图-曲线图-热力图-雷达图
  • 影响转化率的多元因素分析及定制开发AI智能名片S2B2C商城系统小程序的应用案例
  • 数据仓库中事实表设计的关键步骤解析
  • .net6 core Worker Service项目,使用Exchange Web Services (EWS) 分页获取电子邮件收件箱列表,邮件信息字段
  • 通过 EMR Serverless Spark 提交 PySpark 流任务
  • 【Linux网络】epoll实现的echo服务器{nocopy类/智能指针/echo服务器}