pytorch方法测试——激活函数(ReLU)详解

yipeiwu_com6年前Python基础

测试代码:

import torch
import torch.nn as nn

#inplace为True,将会改变输入的数据 ,否则不会改变原输入,只会产生新的输出
m = nn.ReLU(inplace=True)
input = torch.randn(7)

print("输入处理前图片:")
print(input)

output = m(input)

print("ReLU输出:")
print(output)
print("输出的尺度:")
print(output.size())

print("输入处理后图片:")
print(input)

输出为:

输入处理前图片:

tensor([ 1.4940, 1.0278, -1.9883, -0.1871, 0.4612, 0.0297, 2.4300])

ReLU输出:

tensor([ 1.4940, 1.0278, 0.0000, 0.0000, 0.4612, 0.0297, 2.4300])

输出的尺度:

torch.Size([7])

输入处理后图片:

tensor([ 1.4940, 1.0278, 0.0000, 0.0000, 0.4612, 0.0297, 2.4300])

结论:

nn.ReLU(inplace=True)

inplace为True,将会改变输入的数据 ,否则不会改变原输入,只会产生新的输出

以上这篇pytorch方法测试——激活函数(ReLU)详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

详解Python中的序列化与反序列化的使用

学习过marshal模块用于序列化和反序列化,但marshal的功能比较薄弱,只支持部分内置数据类型的序列化/反序列化,对于用户自定义的类型就无能为力,同时marshal不支持自引用(递...

Python按行读取文件的简单实现方法

1:readline() file = open("sample.txt") while 1: line = file.readline() if not line:...

解决pip install的时候报错timed out的问题

安装包的时候报错,执行:pip install pyinstaller 问题: File "c:\python\python35\lib\site-packages\pip\_ven...

wxPython+Matplotlib绘制折线图表

wxPython+Matplotlib绘制折线图表

使用Matplotlib在wxPython的Panel上绘制曲线图,需要导入: import numpy from matplotlib.backends.backend_wxagg...

python base64库给用户名或密码加密的流程

给明文密码加密的流程: import base64 pwd_after_encrypt = base64.b64encode(b'this is a scret!') pwd_bef...