Examples of torch.NN.Functional.Relu() and torch.NN.Relu()

 

Code:

Microsoft Windows [V 10.0.18363.1256]
(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 0x000001CD8F73D330>
>>>
>>> input = torch.randn(3, 5)
>>> input
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]])
>>>
>>>
>>> output1 = torch.nn.ReLU()(input)
>>> output1
tensor([[0.2824, 0.0000, 0.9088, 0.0000, 0.0000],
        [2.0937, 1.0406, 0.0000, 1.1216, 0.8440],
        [0.1783, 0.6859, 0.0000, 0.0000, 0.0000]])
>>>
>>> input
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]])
>>> output2 = torch.nn.functional.relu(input)
>>> output2
tensor([[0.2824, 0.0000, 0.9088, 0.0000, 0.0000],
        [2.0937, 1.0406, 0.0000, 1.1216, 0.8440],
        [0.1783, 0.6859, 0.0000, 0.0000, 0.0000]])
>>>
>>>
>>>

Similar Posts: