卷积层的梯度

第l层的卷积操作的一个简单的例子,s=1:

a[l1]0a[l1]4a[l1]8a[l1]12a[l1]1a[l1]5a[l1]9a[l1]13a[l1]2a[l1]6a[l1]10a[l1]14a[l1]3a[l1]7a[l1]11a[l1]15f[l]0f[l]3f[l]6f[l]1f[l]4f[l]7f[l]2f[l]5f[l]8=[z[l]0z[l]2z[l]1z[l]3] [ a 0 [ l − 1 ] a 1 [ l − 1 ] a 2 [ l − 1 ] a 3 [ l − 1 ] a 4 [ l − 1 ] a 5 [ l − 1 ] a 6 [ l − 1 ] a 7 [ l − 1 ] a 8 [ l − 1 ] a 9 [ l − 1 ] a 10 [ l − 1 ] a 11 [ l − 1 ] a 12 [ l − 1 ] a 13 [ l − 1 ] a 14 [ l − 1 ] a 15 [ l − 1 ] ] ∗ [ f 0 [ l ] f 1 [ l ] f 2 [ l ] f 3 [ l ] f 4 [ l ] f 5 [ l ] f 6 [ l ] f 7 [ l ] f 8 [ l ] ] = [ z 0 [ l ] z 1 [ l ] z 2 [ l ] z 3 [ l ] ]

a的梯度:

第1次卷积的梯度:

da[l1]0da[l1]4da[l1]8da[l1]12da[l1]1da[l1]5da[l1]9da[l1]13da[l1]2da[l1]6da[l1]10da[l1]14da[l1]3da[l1]7da[l1]11da[l1]15=f[l]0dz[l]0f[l]3dz[l]0f[l]6dz[l]00f[l]1dz[l]0f[l]4dz[l]0f[l]7dz[l]00f[l]2dz[l]0f[l]5dz[l]0f[l]8dz[l]000000 [ d a 0 [ l − 1 ] d a 1 [ l − 1 ] d a 2 [ l − 1 ] d a 3 [ l − 1 ] d a 4 [ l − 1 ] d a 5 [ l − 1 ] d a 6 [ l − 1 ] d a 7 [ l − 1 ] d a 8 [ l − 1 ] d a 9 [ l − 1 ] d a 10 [ l − 1 ] d a 11 [ l − 1 ] d a 12 [ l − 1 ] d a 13 [ l − 1 ] d a 14 [ l − 1 ] d a 15 [ l − 1 ] ] = [ f 0 [ l ] d z 0 [ l ] f 1 [ l ] d z 0 [ l ] f 2 [ l ] d z 0 [ l ] 0 f 3 [ l ] d z 0 [ l ] f 4 [ l ] d z 0 [ l ] f 5 [ l ] d z 0 [ l ] 0 f 6 [ l ] d z 0 [ l ] f 7 [ l ] d z 0 [ l ] f 8 [ l ] d z 0 [ l ] 0 0 0 0 0 ]

第2次卷积的梯度:
da[l1]0da[l1]4da[l1]8da[l1]12da[l1]1da[l1]5da[l1]9da[l1]13da[l1]2da[l1]6da[l1]10da[l1]14da[l1]3da[l1]7da[l1]11da[l1]15=0000f[l]0dz[l]1f[l]3dz[l]1f[l]6dz[l]10f[l]1dz[l]1f[l]4dz[l]1f[l]7dz[l]10f[l]2dz[l]1f[l]5dz[l]1f[l]8dz[l]10 [ d a 0 [ l − 1 ] d a 1 [ l − 1 ] d a 2 [ l − 1 ] d a 3 [ l − 1 ] d a 4 [ l − 1 ] d a 5 [ l − 1 ] d a 6 [ l − 1 ] d a 7 [ l − 1 ] d a 8 [ l − 1 ] d a 9 [ l − 1 ] d a 10 [ l − 1 ] d a 11 [ l − 1 ] d a 12 [ l − 1 ] d a 13 [ l − 1 ] d a 14 [ l − 1 ] d a 15 [ l − 1 ] ] = [ 0 f 0 [ l ] d z 1 [ l ] f 1 [ l ] d z 1 [ l ] f 2 [ l ] d z 1 [ l ] 0 f 3 [ l ] d z 1 [ l ] f 4 [ l ] d z 1 [ l ] f 5 [ l ] d z 1 [ l ] 0 f 6 [ l ] d z 1 [ l ] f 7 [ l ] d z 1 [ l ] f 8 [ l ] d z 1 [ l ] 0 0 0 0 ]

第3次卷积的梯度:
da[l1]0da[l1]4da[l1]8da[l1]12da[l1]1da[l1]5da[l1]9da[l1]13da[l1]2da[l1]6da[l1]10da[l1]14da[l1]3da[l1]7da[l1]11da[l1]15=0f[l]0dz[l]2f[l]3dz[l]2f[l]6dz[l]20f[l]1dz[l]2f[l]4dz[l]2f[l]7dz[l]20f[l]2dz[l]2f[l]5dz[l]2f[l]8dz[l]20000 [ d a 0 [ l − 1 ] d a 1 [ l − 1 ] d a 2 [ l − 1 ] d a 3 [ l − 1 ] d a 4 [ l − 1 ] d a 5 [ l − 1 ] d a 6 [ l − 1 ] d a 7 [ l − 1 ] d a 8 [ l − 1 ] d a 9 [ l − 1 ] d a 10 [ l − 1 ] d a 11 [ l − 1 ] d a 12 [ l − 1 ] d a 13 [ l − 1 ] d a 14 [ l − 1 ] d a 15 [ l − 1 ] ] = [ 0 0 0 0 f 0 [ l ] d z 2 [ l ] f 1 [ l ] d z 2 [ l ] f 2 [ l ] d z 2 [ l ] 0 f 3 [ l ] d z 2 [ l ] f 4 [ l ] d z 2 [ l ] f 5 [ l ] d z 2 [ l ] 0 f 6 [ l ] d z 2 [ l ] f 7 [ l ] d z 2 [ l ] f 8 [ l ] d z 2 [ l ] 0 ]

第4次卷积的梯度:
da[l1]0da[l1]4da[l1]8da[l1]12da[l1]1da[l1]5da[l1]9da[l1]13da[l1]2da[l1]6da[l1]10da[l1]14da[l1]3da[l1]7da[l1]11da[l1]15=00000f[l]0dz[l]3f[l]3dz[l]3f[l]6dz[l]30f[l]1dz[l]3f[l]4dz[l]3f[l]7dz[l]30f[l]2dz[l]3f[l]5dz[l]3f[l]8dz[l]3 [ d a 0 [ l − 1 ] d a 1 [ l − 1 ] d a 2 [ l − 1 ] d a 3 [ l − 1 ] d a 4 [ l − 1 ] d a 5 [ l − 1 ] d a 6 [ l − 1 ] d a 7 [ l − 1 ] d a 8 [ l − 1 ] d a 9 [ l − 1 ] d a 10 [ l − 1 ] d a 11 [ l − 1 ] d a 12 [ l − 1 ] d a 13 [ l − 1 ] d a 14 [ l − 1 ] d a 15 [ l − 1 ] ] = [ 0 0 0 0 0 f 0 [ l ] d z 3 [ l ] f 1 [ l ] d z 3 [ l ] f 2 [ l ] d z 3 [ l ] 0 f 3 [ l ] d z 3 [ l ] f 4 [ l ] d z 3 [ l ] f 5 [ l ] d z 3 [ l ] 0 f 6 [ l ] d z 3 [ l ] f 7 [ l ] d z 3 [ l ] f 8 [ l ] d z 3 [ l ] ]

加起来

da[l1]0da[l1]4da[l1]8da[l1]12da[l1]1da[l1]5da[l1]9da[l1]13da[l1]2da[l1]6da[l1]10da[l1]14da[l1]3da[l1]7da[l1]11da[l1]15=f[l]0dz[l]0+0+0+0f[l]3dz[l]0+0+f[l]0dz[l]2+0f[l]6dz[l]0+0+f[l]3dz[l]2+00+0+f[l]6dz[l]2+0f[l]1dz[l]0+f[l]0dz[l]1+0+0f[l]4dz[l]0+f[l]3dz[l]1+f[l]1dz[l]2+f[l]0dz[l]3f[l]7dz[l]0+f[l]6dz[l]1+f[l]4dz[l]2+f[l]3dz[l]30+0+f[l]7dz[l]2+f[l]6dz[l]3f[l]2dz[l]0+f[l]1dz[l]1+0+0f[l]5dz[l]0+f[l]4dz[l]1+f[l]2dz[l]2+f[l]1dz[l]3f[l]8dz[l]0+f[l]7dz[l]1+f[l]5dz[l]2+f[l]4dz[l]30+0+f[l]8dz[l]2+f[l]7dz[l]30+f[l]2dz[l]1+0+00+f[l]5dz[l]1+0+f[l]2dz[l]30+f[l]8dz[l]1+0+f[l]5dz[l]30+0+0+f[l]8dz[l]3 [ d a 0 [ l − 1 ] d a 1 [ l − 1 ] d a 2 [ l − 1 ] d a 3 [ l − 1 ] d a 4 [ l − 1 ] d a 5 [ l − 1 ] d a 6 [ l − 1 ] d a 7 [ l − 1 ] d a 8 [ l − 1 ] d a 9 [ l − 1 ] d a 10 [ l − 1 ] d a 11 [ l − 1 ] d a 12 [ l − 1 ] d a 13 [ l − 1 ] d a 14 [ l − 1 ] d a 15 [ l − 1 ] ] = [ f 0 [ l ] d z 0 [ l ] + 0 + 0 + 0 f 1 [ l ] d z 0 [ l ] + f 0 [ l ] d z 1 [ l ] + 0 + 0 f 2 [ l ] d z 0 [ l ] + f 1 [ l ] d z 1 [ l ] + 0 + 0 0 + f 2 [ l ] d z 1 [ l ] + 0 + 0 f 3 [ l ] d z 0 [ l ] + 0 + f 0 [ l ] d z 2 [ l ] + 0 f 4 [ l ] d z 0 [ l ] + f 3 [ l ] d z 1 [ l ] + f 1 [ l ] d z 2 [ l ] + f 0 [ l ] d z 3 [ l ] f 5 [ l ] d z 0 [ l ] + f 4 [ l ] d z 1 [ l ] + f 2 [ l ] d z 2 [ l ] + f 1 [ l ] d z 3 [ l ] 0 + f 5 [ l ] d z 1 [ l ] + 0 + f 2 [ l ] d z 3 [ l ] f 6 [ l ] d z 0 [ l ] + 0 + f 3 [ l ] d z 2 [ l ] + 0 f 7 [ l ] d z 0 [ l ] + f 6 [ l ] d z 1 [ l ] + f 4 [ l ] d z 2 [ l ] + f 3 [ l ] d z 3 [ l ] f 8 [ l ] d z 0 [ l ] + f 7 [ l ] d z 1 [ l ] + f 5 [ l ] d z 2 [ l ] + f 4 [ l ] d z 3 [ l ] 0 + f 8 [ l ] d z 1 [ l ] + 0 + f 5 [ l ] d z 3 [ l ] 0 + 0 + f 6 [ l ] d z 2 [ l ] + 0 0 + 0 + f 7 [ l ] d z 2 [ l ] + f 6 [ l ] d z 3 [ l ] 0 + 0 + f 8 [ l ] d z 2 [ l ] + f 7 [ l ] d z 3 [ l ] 0 + 0 + 0 + f 8 [ l ] d z 3 [ l ] ]

f的梯度

和求a的梯度相似
第1次卷积的梯度:

df[l]0df[l]3df[l]6df[l]1df[l]4df[l]7df[l]2df[l]5df[l]8=a[l1]0dz[l]0a[l1]4dz[l]0a[l1]8dz[l]0a[l1]1dz[l]0a[l1]5dz[l]0a[l1]9dz[l]0a[l1]2dz[l]0a[l1]6dz[l]0a[l1]10dz[l]0 [ d f 0 [ l ] d f 1 [ l ] d f 2 [ l ] d f 3 [ l ] d f 4 [ l ] d f 5 [ l ] d f 6 [ l ] d f 7 [ l ] d f 8 [ l ] ] = [ a 0 [ l − 1 ] d z 0 [ l ] a 1 [ l − 1 ] d z 0 [ l ] a 2 [ l − 1 ] d z 0 [ l ] a 4 [ l − 1 ] d z 0 [ l ] a 5 [ l − 1 ] d z 0 [ l ] a 6 [ l − 1 ] d z 0 [ l ] a 8 [ l − 1 ] d z 0 [ l ] a 9 [ l − 1 ] d z 0 [ l ] a 10 [ l − 1 ] d z 0 [ l ] ]

第2次卷积的梯度:
df[l]0df[l]3df[l]6df[l]1df[l]4df[l]7df[l]2df[l]5df[l]8=a[l1]1dz[l]1a[l1]5dz[l]1a[l1]9dz[l]1a[l1]2dz[l]1a[l1]6dz[l]1a[l1]10dz[l]1a[l1]3dz[l]1a[l1]7dz[l]1a[l1]11dz[l]1 [ d f 0 [ l ] d f 1 [ l ] d f 2 [ l ] d f 3 [ l ] d f 4 [ l ] d f 5 [ l ] d f 6 [ l ] d f 7 [ l ] d f 8 [ l ] ] = [ a 1 [ l − 1 ] d z 1 [ l ] a 2 [ l − 1 ] d z 1 [ l ] a 3 [ l − 1 ] d z 1 [ l ] a 5 [ l − 1 ] d z 1 [ l ] a 6 [ l − 1 ] d z 1 [ l ] a 7 [ l − 1 ] d z 1 [ l ] a 9 [ l − 1 ] d z 1 [ l ] a 10 [ l − 1 ] d z 1 [ l ] a 11 [ l − 1 ] d z 1 [ l ] ]

第3次卷积的梯度:
df[l]0df[l]3df[l]6df[l]1df[l]4df[l]7df[l]2df[l]5df[l]8=a[l1]4dz[l]2a[l1]8dz[l]2a[l1]12dz[l]2a[l1]5dz[l]2a[l1]9dz[l]2a[l1]13dz[l]2a[l1]6dz[l]2a[l1]10dz[l]2a[l1]14dz[l]2 [ d f 0 [ l ] d f 1 [ l ] d f 2 [ l ] d f 3 [ l ] d f 4 [ l ] d f 5 [ l ] d f 6 [ l ] d f 7 [ l ] d f 8 [ l ] ] = [ a 4 [ l − 1 ] d z 2 [ l ] a 5 [ l − 1 ] d z 2 [ l ] a 6 [ l − 1 ] d z 2 [ l ] a 8 [ l − 1 ] d z 2 [ l ] a 9 [ l − 1 ] d z 2 [ l ] a 10 [ l − 1 ] d z 2 [ l ] a 12 [ l − 1 ] d z 2 [ l ] a 13 [ l − 1 ] d z 2 [ l ] a 14 [ l − 1 ] d z 2 [ l ] ]

第4次卷积的梯度:
df[l]0df[l]3df[l]6df[l]1df[l]4df[l]7df[l]2df[l]5df[l]8=a[l1]5dz[l]3a[l1]9dz[l]3a[l1]13dz[l]3a[l1]6dz[l]3a[l1]10dz[l]3a[l1]14dz[l]3a[l1]7dz[l]3a[l1]11dz[l]3a[l1]15dz[l]3 [ d f 0 [ l ] d f 1 [ l ] d f 2 [ l ] d f 3 [ l ] d f 4 [ l ] d f 5 [ l ] d f 6 [ l ] d f 7 [ l ] d f 8 [ l ] ] = [ a 5 [ l − 1 ] d z 3 [ l ] a 6 [ l − 1 ] d z 3 [ l ] a 7 [ l − 1 ] d z 3 [ l ] a 9 [ l − 1 ] d z 3 [ l ] a 10 [ l − 1 ] d z 3 [ l ] a 11 [ l − 1 ] d z 3 [ l ] a 13 [ l − 1 ] d z 3 [ l ] a 14 [ l − 1 ] d z 3 [ l ] a 15 [ l − 1 ] d z 3 [ l ] ]

最后加起来。(不写了,公式太长了。。。)

你可能感兴趣的:(deeplearning.ai)