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不會改變輸入數據  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM