天天看點

【PyTorch學習筆記】class torch.nn.Sigmoid

參考連結: class torch.nn.Sigmoid

參考連結: torch.nn.functional.sigmoid(input) → Tensor

【PyTorch學習筆記】class torch.nn.Sigmoid
【PyTorch學習筆記】class torch.nn.Sigmoid

代碼實驗展示:

Microsoft Windows [版本 10.0.18363.1316]
(c) 2019 Microsoft Corporation。保留所有權利。

C:\Users\chenxuqi>conda activate ssd4pytorch1_2_0

(ssd4pytorch1_2_0) C:\Users\chenxuqi>python
Python 3.7.7 (default, May  6 2020, 11:45:54) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000001D44FE2D330>
>>>
>>> data = torch.randn(3,5)
>>> data
tensor([[ 0.2824, -0.3715,  0.9088, -1.7601, -0.1806],
        [ 2.0937,  1.0406, -1.7651,  1.1216,  0.8440],
        [ 0.1783,  0.6859, -1.5942, -0.2006, -0.4050]])
>>> data[0,1] = 0.0
>>> data
tensor([[ 0.2824,  0.0000,  0.9088, -1.7601, -0.1806],
        [ 2.0937,  1.0406, -1.7651,  1.1216,  0.8440],
        [ 0.1783,  0.6859, -1.5942, -0.2006, -0.4050]])
>>>
>>> torch.nn.functional.sigmoid(data)
D:\Anaconda3\envs\ssd4pytorch1_2_0\lib\site-packages\torch\nn\functional.py:1350: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.
  warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.")
tensor([[0.5701, 0.5000, 0.7127, 0.1468, 0.4550],
        [0.8903, 0.7390, 0.1461, 0.7543, 0.6993],
        [0.5445, 0.6650, 0.1688, 0.4500, 0.4001]])
>>>
>>>
>>> model = torch.nn.Sigmoid()
>>> model(data)
tensor([[0.5701, 0.5000, 0.7127, 0.1468, 0.4550],
        [0.8903, 0.7390, 0.1461, 0.7543, 0.6993],
        [0.5445, 0.6650, 0.1688, 0.4500, 0.4001]])
>>>
>>>
           

繼續閱讀