nn.Linear( )
import torch
from torch import nn
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision.transforms import ToTensor
model = nn.Linear(2, 1) # 输入特征数为2,输出特征数为1
input = torch.Tensor([1, 2]) # 给一个样本,该样本有2个特征(这两个特征的值分别为1和2)
output = model(input)
print(output)
for param in model.parameters():
print(param)
# tensor([0.4590], grad_fn=<AddBackward0>)
# Parameter containing:
# tensor([[-0.2976, 0.2795]], requires_grad=True)
# Parameter containing:
# tensor([0.1975], requires_grad=True)
#-0.2976+0.2795*2+0.1975 = 0.4589