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 Django框架模板渲染功能示例

Python Django框架模板渲染功能示例

本文实例讲述了Python Django框架模板渲染功能。分享给大家供大家参考,具体如下: 项目名/settings.py(项目配置,配置模板文件的路径): import os #...

python实现查找excel里某一列重复数据并且剔除后打印的方法

本文实例讲述了python实现查找excel里某一列重复数据并且剔除后打印的方法。分享给大家供大家参考。具体分析如下: 在python里面excel的简单读写操作我这里推荐使用xlrd(...

python列表list保留顺序去重的实例

常规通过迭代或set方法,都无法保证去重后的顺序问题 如下,我们可以通过列表的索引功能,对set结果进行序列化 old_list=["a",1,"b","a","b",2,5,1]...

详解python 字符串和日期之间转换 StringAndDate

python 字符串和日期之间转换 StringAndDate           这里给出实现...

python中的reduce内建函数使用方法指南

官方解释: Apply function of two arguments cumulatively to the items of iterable, from left to r...