PyTorch中ReLU激活函数的测试方法有哪些详细讲解?

2026-06-09 20:521阅读0评论SEO基础
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计311个文字,预计阅读时间需要2分钟。

PyTorch中ReLU激活函数的测试方法有哪些详细讲解?

测试代码:导入PyTorch库和相关模块

pythonimport torchimport torch.nn as nn

测试代码:

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])

输入处理后图片:

PyTorch中ReLU激活函数的测试方法有哪些详细讲解?

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

结论:

nn.ReLU(inplace=True)

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

以上这篇pytorch方法测试——激活函数(ReLU)详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

本文共计311个文字,预计阅读时间需要2分钟。

PyTorch中ReLU激活函数的测试方法有哪些详细讲解?

测试代码:导入PyTorch库和相关模块

pythonimport torchimport torch.nn as nn

测试代码:

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])

输入处理后图片:

PyTorch中ReLU激活函数的测试方法有哪些详细讲解?

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

结论:

nn.ReLU(inplace=True)

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

以上这篇pytorch方法测试——激活函数(ReLU)详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。