练习:卷积和池化过程中注意事项
生活随笔
收集整理的這篇文章主要介紹了
练习:卷积和池化过程中注意事项
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
元素化相乘
注意的是,我們在使用濾波器進行卷積的時候,是元素化相乘的,所以,要使用*,而不要使用np.multiply
卷積切片和池化切片
我們基于圖像學習來討論這個問題。
對于多維參數輸入而言,比如說,我們是A=(4,5,5,3)表示的的有4個輸入圖像,每個圖像是5×5,因為是RGB圖像,所以是有3層。
對于卷積而言,我們通常是三維卷積,所以,卷積切片代碼這樣寫:
for i in range(m): # loop over the batch of training examplesa_prev_pad = A_prev_pad[i] # Select ith training example's padded activationfor h in range(n_H): # loop over vertical axis of the output volumefor w in range(n_W): # loop over horizontal axis of the output volumefor c in range(n_C): # loop over channels (= #filters) of the output volume# Find the corners of the current "slice" (≈4 lines)vert_start = h*stridevert_end = vert_start + fhoriz_start = w*stridehoriz_end = horiz_start + f# Use the corners to define the (3D) slice of a_prev_pad (See Hint above the cell). (≈1 line)a_slice_prev = a_prev_pad[vert_start:vert_end, horiz_start:horiz_end, :]但是池化不是三維池化,所以最后一行代碼我們不是寫成:而是寫成c的形式,表示對某一通道進行切片操作,我們舉一個例子
A_prev = np.random.randn(10,4,4,3) A_prev = A_prev[1,1:3,1:3,2] print(A_prev) print(A_prev.shape)輸出效果如下:
[[ 1.07125243 -1.03918232][ 1.2066079 1.06897162]] (2, 2)下面是池化層代碼
for i in range(m): # loop over the training examplesfor h in range(n_H): # loop on the vertical axis of the output volumefor w in range(n_W): # loop on the horizontal axis of the output volumefor c in range (n_C): # loop over the channels of the output volume# Find the corners of the current "slice" (≈4 lines)vert_start = h*stridevert_end = vert_start + fhoriz_start = w*stridehoriz_end = horiz_start + f# Use the corners to define the current slice on the ith training example of A_prev, channel c. (≈1 line)# 不切片的我們寫成i的形式進行保留,池化是一個二維池化,而不是三維池化,所以我們這里寫成c的形式,不進行切片a_prev_slice = A_prev[i, vert_start:vert_end, horiz_start:horiz_end, c]總結
以上是生活随笔為你收集整理的练习:卷积和池化过程中注意事项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 练习:Padding 填充
- 下一篇: 谷歌云盘Colaboratory如何载入