参考链接: torch.nn.functional.linear(input, weight, bias=None)
参考链接: class torch.nn.Linear(in_features, out_features, bias=True)
代码实验展示:
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
>>> import torch.nn as nn
>>> import torch.nn.functional as F
>>> torch.manual_seed(seed=20200910)
<torch._C.Generator object at 0x000002470C22D330>
>>>
>>> data_in = torch.randn(3,4,5,6,7)
>>> data_in.shape
torch.Size([3, 4, 5, 6, 7])
>>> linear4cxq = nn.Linear(7, 30)
>>>
>>> linear4cxq
Linear(in_features=7, out_features=30, bias=True)
>>>
>>> data_out = linear4cxq(data_in)
>>> data_out.shape
torch.Size([3, 4, 5, 6, 30])
>>>
>>> data_in.shape
torch.Size([3, 4, 5, 6, 7])
>>>
>>>
>>>