【PyTorch】教程:torch.nn.ReLU6

torch.nn.ReLU6

原型

CLASS torch.nn.ReLU6(inplace=False)

参数

  • inplace (bool) – can optionally do the operation in-place. Default: False

定义

ReLU6 ( x ) = min ⁡ ( max ⁡ ( 0 , x ) , 6 ) \text{ReLU6}(x)=\min(\max(0, x), 6) ReLU6(x)=min(max(0,x),6)

在这里插入图片描述

代码

import torch
import torch.nn as nn

m = nn.ReLU6()
input = torch.randn(4)
output = m(input)

print("input: ", input)   # input:  tensor([-0.0236,  0.9640,  0.2721,  2.5475])
print("output: ", output) # output:  tensor([0.0000, 0.9640, 0.2721, 2.5475])

【参考】

ReLU6 — PyTorch 1.13 documentation

猜你喜欢

转载自blog.csdn.net/zhoujinwang/article/details/129482130