欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MXNet动手学深度学习笔记:Dropout

程序员文章站 2022-07-13 10:52:54
...
#coding:utf-8

from mxnet import ndarray as nd

def dropout(X,drop_probability):
    keep_probability = 1 - drop_probability
    assert 0 <= keep_probability <= 1
    if keep_probability == 0:
        return X.zeros_like()
    # 随机选择一部分该层的输出
    mask = nd.random.uniform(0,1.0,X.shape,ctx=X.context) < keep_probability
    scale = 1 / keep_probability
    return mask * X * scale

A = nd.arange(20).reshape((5,4))
print(dropout(A,1.0))

 

转载于:https://my.oschina.net/wujux/blog/1809876