上次听完安晟大神的讲解,将测试集中图像的尺寸设置为了(60, 120),再次运行baseline,将epochs设置为了15次,以下是训练集和验证集的损失函数值。

使用matplotlib绘制出曲线图:

在上图中可以看出训练集的损失函数值是在不断的下降,而验证集的损失函数值在第七次时出现了上升, 而且到后面不出现下降,说明该模型出现的过拟合。

上一篇也说了处理过拟合的方法,这次详细介绍一下dropout方法。
Dropout是广泛应用于深度学习的正则化技术。它会在每次迭代中随机关闭一些神经元。

dropout第二个隐藏层。在每次迭代中,以概率1 - keep_prob或以概率keep_prob(此处为50%)关闭此层的每个神经元。关闭的神经元对迭代的正向和反向传播均无助于训练。
1 带有Dropout的正向传播
def forward_propagation_with_dropout(X, parameters, keep_prob = 0.5):
"""
Implements the forward propagation:LINEAR->RELU->LINEAR->RELU->LINEAR->SIGMOID
Args:
X: -- input dataset, of shape (2, number of examples)
parameters: -- python dictionary containing your parameters W1, b1, W2, b2, W3, b3
W1 -- weight matrix of shape (20, 2)
b1 -- bias vector of shape (20, 1)
W2 -- weight matrix of shape (3, 20)
b2 -- bias vector of shape (3, 1)
W3 -- weight matrix of shape (3, 1)
b3 -- bias vector of shape (1, 1)
keep_prob: -- probability of keeping a neuron active during drop-out, scalar
Returns:
A3 -- last activation value, output of the forward propagation, of shape(1, 1)
cache -- tuple, information stored for computing the backward propagation
"""
np.random.seed(1)
# retrieve parameters
W1 = parameters['W1']
b1 = parameters['b1']
W2 = parameters['W2']
b2 = parameters['b2']
W3 = parameters['W3']
b3 = parameters

本文介绍了一种防止深度学习模型过拟合的技术——Dropout。通过在训练过程中随机关闭部分神经元,Dropout能够提高模型的泛化能力。文章详细解释了Dropout的工作原理,并提供了带有Dropout的正向传播和反向传播的实现代码。
最低0.47元/天 解锁文章

被折叠的 条评论
为什么被折叠?



