def convolve(patchDim, numFeatures, images, W):
m = np.shape(images)[3]
imageDim = np.shape(images)[0]
imageChannels = np.shape(images)[2]
convolvedFeatures = np.zeros((numFeatures, m, \
imageDim - patchDim + 1, imageDim - patchDim + 1))
for imageNum in range(m):
for featureNum in range(numFeatures):
convolvedImage = np.zeros((imageDim - patchDim + 1, imageDim - patchDim + 1))
for channel in range(imageChannels):
feature = np.zeros((patchDim, patchDim))
start = channel * patchDim*patchDim
stop = start + patchDim*patchDim
feature += np.reshape(W[featureNum, start:stop], (patchDim, patchDim), order="F")
feature = np.flipud(np.fliplr(feature))
im = images[:, :, channel, imageNum]
convolvedImage += sig.convolve2d(im, feature, "valid")
# sparse filtering activation function
convolvedImage = np.sqrt(1e-8 + np.multiply(convolvedImage, convolvedImage))
convolvedFeatures[featureNum, imageNum, :, :] = convolvedImage
return convolvedFeatures
评论列表
文章目录