我正在创建自己的神经网络库,现在我正在创建卷积算法。我试图将输入分成局部感受野,然后将其乘以相应的权重,对乘以的感受野求和,加上偏差并返回结果。我正在使用'numpy.lib.stride\u tricks.as\u strided'函数,我不确定如何设置步幅。我非常感谢你的帮助。代码如下:
"""
the matrix shape is:
mini_batch_size X
numberOfFilters X
numberOfInputFeatureMaps X
sizeOfInputImage[0] X
sizeOfInputImage[1]
the kernel shape is:
mini_batch_size X
numberOfFilters X
sizeOfLocalReceptiveField[0] X
sizeOfLocalReceptiveField[1]
"""
s1, s2, s3, s4, s5 = matrix.strides
imageWidth, imageHeight = matrix.shape[-2:]
localReceptiveFieldWidth, localReceptiveFieldHeight = kernel.shape[-2:]
matrix_shape = matrix.shape
numberOfLocalReceptiveFields =
(1 + (imageWidth - localReceptiveFieldWidth) // stride) *
(1 + (imageHeight - localReceptiveFieldHeight) // stride) *
matrix_shape[1]
view_shape = (
matrix_shape[0], # mini batch size
matrix_shape[1], # number of filters
numberOfLocalReceptiveFields,
localReceptiveFieldWidth,
localReceptiveFieldHeight
)
strides = () # don't know what to put here
subs = numpy.lib.stride_tricks.as_strided(matrix, view_shape, strides=strides)
嘿,如果有人感兴趣,我设法以这种方式创建了一个算法:
相关问题 更多 >
编程相关推荐