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

2020-01-15

测试代码:

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)详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持北冥有鱼。

《pytorch方法测试——激活函数(ReLU)详解.doc》

下载本文的Word格式文档,以方便收藏与打印。