Pytorch-nn.functional.ReLU()

测试代码:

  import torch

  import torch.nn as nn

  

  m = nn.ReLU(inplace=True)

  input = torch.randn(10)

  print(input)

  output = m(input)

  print(output)

  print(input)

输出为:

  tensor([ 0.2837, -1.2100, -0.4476,  1.0861,  2.2029, -0.3802, -0.0020,  1.8135, 0.5749,  0.5932])

  tensor([0.2837, 0.0000, 0.0000, 1.0861, 2.2029, 0.0000, 0.0000, 1.8135, 0.5749, 0.5932])

  tensor([0.2837, 0.0000, 0.0000, 1.0861, 2.2029, 0.0000, 0.0000, 1.8135, 0.5749, 0.5932])

结论:

  nn.ReLU(inplace=True)

  inplace=True会改变输入数据,inplace=False不会改变输入数据  

 

posted @ 2018-12-10 14:55  Le1B_o  阅读(3292)  评论(0编辑  收藏  举报