def convolve_flatten(X):
# input will be (32, 32, 3, N)
# output will be (N, 32*32)
N = X.shape[-1]
flat = np.zeros((N, 32*32))
for i in xrange(N):
#flat[i] = X[:,:,:,i].reshape(3072)
bw = X[:,:,:,i].mean(axis=2) # make it grayscale
Gx = convolve2d(bw, Hx, mode='same')
Gy = convolve2d(bw, Hy, mode='same')
G = np.sqrt(Gx*Gx + Gy*Gy)
G /= G.max() # normalize it
flat[i] = G.reshape(32*32)
return flat
评论列表
文章目录