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不会改变输入数据  

 

    原文作者:pytorch
    原文地址: https://www.cnblogs.com/leebxo/p/10096490.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞