自学内容网 自学内容网

Dropout案例演示

# 导入必备工具包
import torch

# 预定义的网络层torch.nn, 工具开发者已经帮助我们开发好的一些常用层,
# 比如,卷积层, lstm层, embedding层等, 不需要我们再重新造轮子.
import torch.nn as nn

# 置零比例
m = nn.Dropout(p=0.2)
input = torch.randn(4,5)
output = m(input)
print(output)

"""
tensor([[-0.0000, -0.0000, -0.0178, -2.4944,  0.4807],
        [ 1.1298, -0.7785, -0.2947, -2.9571, -1.3370],
        [ 0.0748,  0.1100,  2.5367,  0.0000,  0.0000],
        [-0.5269, -2.4903,  1.7516, -0.0658, -1.4673]])
"""

原文地址:https://blog.csdn.net/w13716207404/article/details/140731165

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!