1
0
0

神经网络概览

神经网络概括.png

人工神经网络

人工神经网络:输入层 | 隐藏层 | 输出层

全连接层 = 每一个神经元都是和上一层的所有神经元相连接,每一层的神经元互不连接

神经元(加权求和|激活函数)

加权求和 - 线性转换

激活函数(4) - 非线性因素

使用场景:

隐藏层(激活函数: ReLU 、tanh ) 输出层(激活函数:Sigmoid、Softmax)

sigmoid 值域 0~1 有效定义域 -6,6 高效定义域-3,3

sigmoid 导函数值域 0~0.25

激活函数

隐藏层(导函数):

ReLU : 0~1

tanh : 0~1

输出层(原函数):

sigmoid : 0~1

softmax : 将内容转换为概率

搭建神经网络(掌握)

1.定义一个类,继承nn.Module

class Model(nn.Module):

2.重写__init__方法 - 定义层

​ def init():

​ 2.0 - 调用父类初始化方法

​ super().init()

​ 2.1 - 搭建神经网络层

​ self.fc1 = torch.nn.Linear(上一层输出的数量x1,当前层的神经元数量x2) #x1表示特征有多少

​ self.fc2 = torch.nn.Linear(上一层输出的数量x2,当前层的神经元数量x3)

​ self.out = torch.nn.Linear(上一层输出的数量x3,当前层的神经元数量x4) #x4表示标签有多少

​ 2.2 - 定义每层的权重

​ torch.nn.init.kaiming_normal(self.fc1.weight)

​ torch.nn.init.kaiming_normal(self.fc2.weight)

​ 2.3 - 定义每层的偏置

​ torch.nn.init.ones(self.fc1.bias)

​ torch.nn.init.ones(self.fc2.bias)

3.定义一个forward方法 - 定义激活函数

​ def forward(self,x):

​ x1 = torch.relu(self.fc1(x))

​ x2 = torch.relu(self.fc2(x1))

​ result = torch.sigmoid(self.out(x2))

​ return result

初始化参数:
1.全0 - torch.nn.init.zeros()
2.全1 - torch.nn.init.ones()
3.指定 - torch.nn.init.constant(权重,0.123)
4.随机 - torch.nn.init.uniform()
5.正态 - torch.nn.init.normal()
6.凯明(只关心输入) - torch.nn.init.kaiming_normal() / torch.nn.init.kaiming_uniform()
7.泽维尔(关心输入输出) - torch.nn.init.xavier_normal() / torch.nn.init.xavier_uniform()

损失函数

衡量真实值与预测值之间误差的函数

回归问题:

​ L1Loss

​ MSELoss

​ SmoothL1Loss

分类问题:

​ BCELoss

​ CrossEntropyLoss

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或者给予支持!