当前位置:网站首页>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()

边栏推荐
猜你喜欢
![[Energy Conservation Institute] Ankerui Food and Beverage Fume Monitoring Cloud Platform Helps Fight Air Pollution](/img/ca/e67c8e2196adb5a078acc44ba5ad6f.jpg)
[Energy Conservation Institute] Ankerui Food and Beverage Fume Monitoring Cloud Platform Helps Fight Air Pollution

OSG笔记:设置DO_NOT_COMPUTE_NEAR_FAR,手动计算远近平面

StringTable Detailed String Pool Performance Tuning String Concatenation

What is the difference between a utility model patent and an invention patent?Understand in seconds!
![[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)](/img/7d/f8f150ad13f4cacc143491fcd8420b.png)
[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)

Digital twin Beijing the imperial palace, yuan universe is the process of tourism

【无标题】

仿牛客论坛项目
![[Energy Conservation Institute] Comparative analysis of smart small busbar and column head cabinet solutions in data room](/img/c2/456eec59930321b4f088020905c246.jpg)
[Energy Conservation Institute] Comparative analysis of smart small busbar and column head cabinet solutions in data room

小数据如何学习?吉大最新《小数据学习》综述,26页pdf涵盖269页文献阐述小数据学习理论、方法与应用
随机推荐
使用Huggingface在矩池云快速加载预训练模型和数据集
Debug一个ECC的ODP数据源
微信小程序云开发|个人博客小程序
进行交互或动画时如何选择Visibility, Display, and Opacity
用户体验好的Button,在手机上不应该有Hover态
Redis does web page UV statistics
The Internet giant development process
StringTable详解 串池 性能调优 字符串拼接
卷积神经网络(CNN)mnist数字识别-Tensorflow
Postman 批量测试接口详细教程
tiup mirror init
任务调度线程池基本介绍
Digital twin Beijing the imperial palace, yuan universe is the process of tourism
【节能学院】安科瑞餐饮油烟监测云平台助力大气污染攻坚战
Convolutional Neural Network (CNN) mnist Digit Recognition - Tensorflow
自定义指令,获取焦点
任务调度线程池-应用定时任务
[Multi-task model] Progressive Layered Extraction: A Novel Multi-Task Learning Model for Personalized (RecSys'20)
根据Uniprot ID/PDB ID批处理获取蛋白质.pdb文件
数字孪生北京故宫,元宇宙推进旅游业进程