pytorch中ReLU6的inplace参数到底是个啥????

测试代码

import torch
import torch.nn as nn

relu1 = nn.ReLU6(True)
relu2 = nn.ReLU6(False)

inputs1 = torch.tensor([50,-2,6,5,3])
inputs2 = torch.tensor([50,-2,6,5,3])

x1 = relu1(inputs1)
x2 = relu2(inputs2)

打印结果

 x1 = tensor([6, 0, 6, 5, 3]),
 x2 = tensor([6, 0, 6, 5, 3]),
 inputs1 = tensor([6, 0, 6, 5, 3]),
 inputs2 = tensor([50, -2,  6,  5,  3])

结论

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

猜你喜欢

转载自blog.csdn.net/qq_38973721/article/details/113857679