卷积神经网络之池化层学习笔记
github代码地址:https://github.com/taichuai/d2l_zh_tensorflow2.0
def pool2d(X, pool_size, mode='max'):
p_h, p_w = pool_size
Y = tf.zeros((X.shape[0] - p_h + 1, X.shape[1] - p_w +1))
Y = tf.Variable(Y)
for i in range(Y.shape[0]):
for j in range(Y.shape[1]):
if mode == 'max':
Y[i,j].assign(tf.reduce_max(X[i:i+p_h, j:j+p_w]))
elif mode =='avg':
Y[i,j].assign(tf.reduce_mean(X[i:i+p_h, j:j+p_w]))
return Y