我正在学习用python编写卷积神经网络,numpy。
我对这条线感到非常沮丧
col[:, :, y, x, :, :] = images[:, :, y:y_bound:stride[0], x:x_bound:stride[1]]
我不明白'='两边是什么意思,为什么左右两边都有不同的','数字。
完整代码
[来自https://github.com/rushter/MLAlgorithms/blob/master/mla/neuralnet/layers/convnet.py]
def image_to_column(images, filter_shape, stride, padding):
"""Rearrange image blocks into columns.
Parameters
----------
filter_shape : tuple(height, width)
images : np.array, shape (n_images, n_channels, height, width)
padding: tuple(height, width)
stride : tuple (height, width)
"""
n_images, n_channels, height, width = images.shape
f_height, f_width = filter_shape
out_height, out_width = convoltuion_shape(height, width, (f_height, f_width), stride, padding)
images = np.pad(images, ((0, 0), (0, 0), padding, padding), mode='constant')
col = np.zeros((n_images, n_channels, f_height, f_width, out_height, out_width))
for y in range(f_height):
y_bound = y + stride[0] * out_height
for x in range(f_width):
x_bound = x + stride[1] * out_width
col[:, :, y, x, :, :] = images[:, :, y:y_bound:stride[0], x:x_bound:stride[1]]
col = col.transpose(0, 4, 5, 1, 2, 3).reshape(n_images * out_height * out_width, -1)
return col
非常感谢!