void forward_dropout_layer(dropout_layer l, network net)
{
int i;
if (!net.train) return;
for(i = 0; i < l.batch * l.inputs; ++i){
float r = rand_uniform(0, 1);
l.rand[i] = r;
if(r < l.probability) net.input[i] = 0;
else net.input[i] *= l.scale;
}
}
void backward_dropout_layer(dropout_layer l, network net)
{
int i;
if(!net.delta) return;
for(i = 0; i < l.batch * l.inputs; ++i){
float r = l.rand[i];
if(r < l.probability) net.delta[i] = 0;
else net.delta[i] *= l.scale;
}
}tmep
Dropout层前向与反向传播
最新推荐文章于 2025-07-31 18:31:54 发布
本文介绍了一个简单的dropout层实现,包括其前向传播和反向传播过程。在训练过程中,通过随机丢弃一部分输入节点来减少过拟合风险,并在反向传播时相应调整梯度。
9586

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



