当前位置:网站首页>Pytorch weight decay and dropout
Pytorch weight decay and dropout
2022-07-05 11:42:00 【My abyss, my abyss】
There are two common methods to solve over fitting :
1、 Weight decline
Common methods :L1,L2 Regularization
L2 Regularization :
A neural network is trained to loss When converging , There will be multiple w,b eligible . If w Too big , Then the noise of the input layer will be amplified , The result will also be inaccurate , So we need to minimize w Value . Regularization makes the learned model parameters smaller by adding penalty terms to the loss function of the model .
2、 The law of abandonment ( Can only be used in the full connection layer )

dropout Do not change the expected value of its input , Only use it during model training
Yes p Probability ,hi It will be cleared
Yes 1-p Probability ,hi Will divide by 1-p Do stretching 

import torch
from torch import nn
from d2l import torch as d2l
dropout1, dropout2 = 0.2, 0.2
net = nn.Sequential(nn.Flatten(),
nn.Linear(784, 256),
nn.ReLU(),
# Add one after the first fully connected layer dropout layer
nn.Dropout(dropout1),
nn.Linear(256, 256),
nn.ReLU(),
# Add a... After the second fully connected layer dropout layer
nn.Dropout(dropout2),
nn.Linear(256, 10))
def init_weights(m):
if type(m) == nn.Linear:
nn.init.normal_(m.weight, std=0.01)
net.apply(init_weights);
num_epochs, lr, batch_size = 10, 0.5, 256
loss = nn.CrossEntropyLoss(reduction='none')
train_iter, test_iter = d2l.load_data_fashion_mnist(batch_size)
trainer = torch.optim.SGD(net.parameters(), lr=lr)
d2l.train_ch3(net, train_iter, test_iter, loss, num_epochs, trainer)
边栏推荐
- 爬虫(9) - Scrapy框架(1) | Scrapy 异步网络爬虫框架
- pytorch训练进程被中断了
- Startup process of uboot:
- COMSOL -- three-dimensional graphics random drawing -- rotation
- ibatis的动态sql
- Solve the grpc connection problem. Dial succeeds with transientfailure
- redis集群中hash tag 使用
- Empêcher le navigateur de reculer
- 石油化工企业安全生产智能化管控系统平台建设思考和建议
- Home office things community essay
猜你喜欢

【爬虫】charles unknown错误

Advanced technology management - what is the physical, mental and mental strength of managers

龙蜥社区第九次运营委员会会议顺利召开

12.(地图数据篇)cesium城市建筑物贴图

Idea set the number of open file windows

【使用TensorRT通过ONNX部署Pytorch项目】

idea设置打开文件窗口个数

Harbor镜像仓库搭建

comsol--三维图形随便画----回转

13.(地图数据篇)百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换
随机推荐
Project summary notes series wstax kt session2 code analysis
Harbor image warehouse construction
c#操作xml文件
POJ 3176 cow bowling (DP | memory search)
Open3D 网格(曲面)赋色
Zcmu--1390: queue problem (1)
COMSOL -- three-dimensional graphics random drawing -- rotation
splunk配置163邮箱告警
COMSOL -- establishment of geometric model -- establishment of two-dimensional graphics
百问百答第45期:应用性能探针监测原理-node JS 探针
Unity xlua monoproxy mono proxy class
阻止瀏覽器後退操作
2048游戏逻辑
pytorch-softmax回归
解决readObjectStart: expect { or n, but found N, error found in #1 byte of ...||..., bigger context ..
Differences between IPv6 and IPv4 three departments including the office of network information technology promote IPv6 scale deployment
【TFLite, ONNX, CoreML, TensorRT Export】
【云原生 | Kubernetes篇】Ingress案例实战(十三)
XML parsing
12. (map data) cesium city building map