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 groupby 函数 as_index详解

在官方网站中对as_index有以下介绍: as_index : boolean, default True For aggregated output, return object w...

python对数组进行反转的方法

本文实例讲述了python对数组进行反转的方法。分享给大家供大家参考。具体实现方法如下: arr = [1,2,3] arr.reverse() print(arr) 输出:...

使用pandas的DataFrame的plot方法绘制图像的实例

使用pandas的DataFrame的plot方法绘制图像的实例

使用了pandas的Series方法绘制图像体验之后感觉直接用matplotlib的功能好用了不少,又试用了DataFrame的方法之后发现这个更加人性化。 写代码如下: from...

在Python中字符串、列表、元组、字典之间的相互转换

在Python中字符串、列表、元组、字典之间的相互转换

一、字符串(str) 字符串转换为列表 使用list()方法 str_1 = "1235" str_2 = 'zhangsan' str_3 = '''lisi''' tuple_1...

python conda操作方法

conda 虚拟环境安装 List item conda env list #查看已安装虚拟环境 coda创建虚拟环境非常方便:官方教程:https://conda.io/project...