5个简单的例子教你在FFNN, RNN以及CNN模型中计算参数个数。
手动计算深度学习模型的参数个数常常被认为太过于琐碎,而且是在做无用功。由于你的代码已经可以为你做到这一点。然而我还是执意想写这篇文章,以便咱们偶尔参考一下。下面是咱们要用到的模型:文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
1. 前馈神经网络(FFNN)文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
num_params_layer2文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
= g × [h(h+i) + h]文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
= 4 × [50(50+10) + 50]文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
= 12,200文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
total_params = 420 + 12,200 = 12,620文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
默许情况下,merge_mode是串连的。文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
CNNs文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
在只有一层的情况下,文章源自微观生活(93wg.com)微观生活-https://93wg.com/23923.html
i,输入通道个数
f,过滤器大小(只是长度)
o,输出通道个数。(这是由使用了多少过滤器来定义的)
每一个输入通道都有一个过滤器。
num_params
= [i × (f×f) × o] + o
例3.1:1×1过滤器的灰度图象、输出通道为3
图3.1:灰度图象的卷积为2×2过滤器,输出通道为3
i = 1 (灰度图只有一个通道)
f = 2
o = 3
num_params
= [i × (f×f) × o] + o
= [1 × (2×2) × 3] + 3
= 15
例3.2:有着2×2过滤器,输出通道为1的RGB图象
每一个输入特征映照都有一个过滤器。生成的卷积按元素顺序添加,并向每一个元素添加一个偏差项。这将给出一个带有特征映照的输出。
图3.2:一个2×2的RGB图象的卷积过滤器输出1通道
i = 3 (RGB图象有3个通道)
f = 2
o = 1
num_params
= [i × (f×f) × o] + o
= [3 × (2×2) × 1] + 1
= 13
例3.3:图象有2个通道,2×2过滤器,以及3通道的输出
每一个输入的特征映照有3个过滤器(紫色、黄色、青色)。生成的卷积按元素顺序添加,并向每一个元素添加一个偏差项。这给出了一个带有3个特性映照的输出。
图3.1:2通道图象的卷积为2×2过滤器,输出3频道
i = 2
f = 2
o = 3
num_params
= [i × (f×f) × o] + o
= [2 × (2×2) × 3] + 3
= 27
关于深度学习相关文章举荐:
1.《Animated RNN, LSTM and GRU》链接:https://towardsdatascience.com/animated-rnn-lstm-and-gru-ef124d06cf45
2.《Step-by-Step Tutorial on Linear Regression with Stochastic Gradient Descent》链接:https://towardsdatascience.com/step-by-step-tutorial-on-linear-regression-with-stochastic-gradient-descent-1d35b088a843
3.《10 Gradient Descent Optimisation Algorithms + Cheat Sheet》链接:https://towardsdatascience.com/10-gradient-descent-optimisation-algorithms-86989510b5e9
4.《Attn: Illustrated Attention》链接:https://towardsdatascience.com/attn-illustrated-attention-5ec4ad276ee3
以上就是微观生活(93wg.com)关于“小白必读:5个简单的例子教你把基础数学与机器联络起来”的详细内容,希望对大家有所帮助!
评论