当前位置:网站首页>理解卷积神经网络中的权值共享
理解卷积神经网络中的权值共享
2022-07-26 15:29:00 【华为云】
首先介绍单层网络实行的权重共享袁力介绍
简单从共享的角度来说:权重共享即filter的值共享
卷积神经网络两大核心思想:
1.网络局部连接(Local Connectivity)
2.卷积核参数共享(Parameter Sharing)
两者的一个关键作用就是减少参数数量,使运算变得简洁、高效,能够在超大规模数据集上运算。
下面来用最直观的图示,来阐明两者的作用。
CNN的正确打开方式,如下所示
概括为:一个
的卷积核在图像上扫描,进行特征提取。通常
,
,
的卷积核较为常用,如果channels为 [公式] 的话(32,64是较为常用的通道数),那么参数总量为
。
- 不进行parameter sharing
如果不用parameter sharing实现上图的运算,卷积核结构就会变成下图所示

这个是不难发现:卷积核的参数数量与图像像素矩阵的大小保持一致,即
例如:Inception V3的输入图像尺寸是192192的,**如果把第一层3332的卷积核去掉参数共享,那么参数数目就会变成192192*32,约为120万个参数,是原来288个参数的50万倍。**
- 不进行local connectivity
如果不用局部连接,那当然就是全连接网络了(fully connect),即每个元素单元与隐层的神经原进行全连接,网络结构如下所示。
此时参数量变为
,因为像素矩阵很大,所以也会选择较多的隐含层节点,这时一个单隐层的参数数目通常就超过了1千万个,导致网络很难进行训练。
以下是pytorch对多层网络实行的权重共享代码
import torchimport torch.nn as nnimport randomimport matplotlib.pyplot as plt # 绘制loss曲线def plot_curve(data): fig = plt.figure() plt.plot(range(len(data)), data, color='blue') plt.legend(['value'], loc='upper right') plt.xlabel('step') plt.ylabel('value') plt.show() class DynamicNet(nn.Module): def __init__(self, D_in, H, D_out): super(DynamicNet, self).__init__() self.input_linear = nn.Linear(D_in, H) self.middle_linear = nn.Linear(H, H) self.output_linear = nn.Linear(H, D_out) def forward(self, x): h_relu = self.input_linear(x).clamp(min=0) # 重复利用Middle linear模块 for _ in range(random.randint(0, 3)): h_relu = self.middle_linear(h_relu).clamp(min=0) y_pred = self.output_linear(h_relu) return y_pred # N是批大小;D是输入维度# H是隐藏层维度;D_out是输出维度N, D_in, H, D_out = 64, 1000, 100, 10 # 模拟训练数据x = torch.randn(N, D_in)y = torch.randn(N, D_out) model = DynamicNet(D_in, H, D_out)criterion = nn.MSELoss(reduction='sum')# 用平凡的随机梯度下降训练这个奇怪的模型是困难的,所以我们使用了momentum方法。optimizer = torch.optim.SGD(model.parameters(), lr=1e-4, momentum=0.9) loss_list = []for t in range(500): # 前向传播 y_pred = model(x) # 计算损失 loss = criterion(y_pred, y) loss_list.append(loss.item()) # 清零梯度,反向传播,更新权重 optimizer.zero_grad() loss.backward() optimizer.step() plot_curve(loss_list)边栏推荐
- 2023 catering industry exhibition, China catering supply chain exhibition and Jiangxi catering Ingredients Exhibition were held in February
- Familiarize you with the "phone book" of cloud network: DNS
- R language tests the significance of correlation coefficient: use Cor The test function calculates the value and confidence interval of the correlation coefficient and its statistical significance (if
- Refuse noise, the entry journey of earphone Xiaobai
- 什么是虚拟摄像头
- Qt最基本的布局,创建window界面
- Basic specification of component development, localstorage and sessionstorage, object data to basic value, prototype chain use
- OSPF综合实验
- 阿里巴巴一面 :十道经典面试题解析
- 谷歌尝试为ChromeOS引入密码强度指示器以提升线上安全性
猜你喜欢

谷歌尝试为ChromeOS引入密码强度指示器以提升线上安全性

Refuse noise, the entry journey of earphone Xiaobai

FOC电机控制基础

If you want to be good at work, you must first use its tools -c language expansion -- embedded C language (11)
原来卡布奇诺信息安全协会是干这个的呀,一起来看看吧。

TI C6000 TMS320C6678 DSP+ Zynq-7045的PS + PL异构多核案例开发手册(2)

Enterprise digital transformation needs in-depth research, and it cannot be transformed for the sake of transformation

If food manufacturing enterprises want to realize intelligent and collaborative supplier management, it is enough to choose SRM supplier system

Digital warehouse: iqiyi digital warehouse platform construction practice

cs224w(图机器学习)2021冬季课程学习笔记5
随机推荐
VS添加作者信息和时间信息的设置
软测(七)性能测试(1)简要介绍
数商云:引领化工业态数字升级,看摩贝如何快速打通全场景互融互通
81.(cesium之家)cesium修改灰色背景(默认蓝色)
原来卡布奇诺信息安全协会是干这个的呀,一起来看看吧。
HTB-Apocalyst
我们被一个 kong 的性能 bug 折腾了一个通宵
教程篇(7.0) 05. 通过FortiClient EMS发放FortiClient * FortiClient EMS * Fortinet 网络安全专家 NSE 5
阿里巴巴一面 :十道经典面试题解析
Interview with data center and Bi business (IV) -- look at the essence of ten questions
[leetcode daily question] - 121. The best time to buy and sell stocks
# 工欲善其事必先利其器-C语言拓展--嵌入式C语言(十一)
Refuse noise, the entry journey of earphone Xiaobai
777. Exchange adjacent characters in LR string
Using information entropy to construct decision tree
示波器的使用
R language tests the significance of correlation coefficient: use Cor The test function calculates the value and confidence interval of the correlation coefficient and its statistical significance (if
【DSCTF2022】pwn补题记录
邻接矩阵的COO格式
持续集成(二)Jenkins基本使用介绍
