目录:
1: 参数说明
2: 功能
3: 例子
一 参数说明:
torch.nn.Linear(
in_features, 输入的神经元个数
out_features, 输出神经元个数
bias=True 是否包含偏置 )
模型主要实现如下功能:(x,w 都是行向量)
二 实现功能:
向量是按照行向量排列的
三: 例子
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 24 09:25:45 2022
@author: chengxf2
"""
import torch
from torch import nn
def Linear():
conv = nn.Linear(in_features= 4, out_features =2)
X = torch.randn(10, 4)
out = conv(X)
print("\n 输出 ",out.shape)
print("\n 权重系数",conv.weight.shape)
print("\n 偏置系数 ",conv.bias.shape)
if __name__ == "__main__":
Linear()
输出 torch.Size([10, 2])
权重系数 torch.Size([2, 4])
偏置系数 torch.Size([2])