当前位置:网站首页>Pytorch框架学习记录9——非线性激活
Pytorch框架学习记录9——非线性激活
2022-08-01 20:36:00 【柚子Roo】
Pytorch框架学习记录9——非线性激活
1. ReLU函数介绍

torch.nn.ReLU(inplace=False)
参数
inplace- 可以选择就地执行操作。默认:
False形状:
输入:( * ), 在哪里**表示任意数量的维度。输出:( * ),与输入的形状相同。
import torch
from torch import nn
input = torch.tensor([[1, 0.5],
[4, -2]])
input = torch.reshape(input, (-1, 1, 2, 2))
class Test(nn.Module):
def __init__(self):
super(Test, self).__init__()
self.relu = nn.ReLU(inplace=False)
def forward(self, input):
input = self.relu(input)
return input
test = Test()
output = test(input)
print(output)
2. Sigmoid函数

形状:
- 输入:( * ), 在哪里**表示任意数量的维度。
- 输出:( * ),与输入的形状相同。
import torchvision
from torch import nn
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter
dataset = torchvision.datasets.CIFAR10(root='./dataset', train=False, transform=torchvision.transforms.ToTensor(), download=True)
dataloader = DataLoader(dataset, batch_size=64)
class Test(nn.Module):
def __init__(self):
super(Test, self).__init__()
self.sigmod = nn.Sigmoid()
def forward(self, input):
input = self.sigmod(input)
return input
test = Test()
writer = SummaryWriter('logs')
step = 0
for data in dataloader:
imgs, target = data
output = test(imgs)
writer.add_images("sigmod", output, global_step=step)
step += 1
writer.close()

边栏推荐
- 【节能学院】推进农业水价综合改革的意见解读
- 】 【 nn. The Parameter () to generate and why do you want to initialize
- 算法---解码方法(Kotlin)
- 进行交互或动画时如何选择Visibility, Display, and Opacity
- SIPp 安装及使用
- 面试突击70:什么是粘包和半包?怎么解决?
- 【多任务模型】Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized(RecSys‘20)
- 漏刻有时文档系统之XE培训系统二次开发配置手册
- 数字孪生北京故宫,元宇宙推进旅游业进程
- latex论文神器--服务器部署overleaf
猜你喜欢

Excel advanced drawing techniques, 100 (22) - how to respectively the irregular data

【Dart】dart构造函数学习记录(含dart单例模式写法)

Application of Acrel-5010 online monitoring system for key energy consumption unit energy consumption in Hunan Sanli Group

【torch】张量乘法:matmul,einsum

使用Huggingface在矩池云快速加载预训练模型和数据集
![[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear](/img/6d/05233ce5c91a612b6247ea07d7982e.jpg)
[Energy Conservation Institute] Application of Intelligent Control Device in High Voltage Switchgear

实用新型专利和发明专利的区别?秒懂!

98.嵌入式控制器EC实战 EC开发板开发完成

算法---解码方法(Kotlin)

泰德制药董事长郑翔玲荣膺“2022卓越影响力企业家奖” 泰德制药荣获“企业社会责任典范奖”
随机推荐
通俗解释:什么是临床预测模型
98.嵌入式控制器EC实战 EC开发板开发完成
98. Embedded controller EC actual combat EC development board development completed
Fork/Join线程池
启明云端分享|盘点ESP8684开发板有哪些功能
Addition, Subtraction, Multiplication of Large Integers, Multiplication and Division of Large Integers and Ordinary Integers
myid file is missing
9月备考PMP,应该从哪里备考?
【Untitled】
Redis does web page UV statistics
Application of Acrel-5010 online monitoring system for key energy consumption unit energy consumption in Hunan Sanli Group
Imitation cattle forum project
Qt设置应用程序开机自启 解决设置失败原因
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
Redis 做网页UV统计
Protocol Buffer usage
Which websites are commonly used for patent searches?
Interview Blitz 70: What are sticky packs and half packs?How to deal with it?
Where should I prepare for the PMP exam in September?
【节能学院】数据机房中智能小母线与列头柜方案的对比分析