【发布时间】:2019-07-31 13:48:29
【问题描述】:
我加载形状为 (10000, 28, 28, 1) 的 MNIST(测试)数据集(这意味着 10000 张图像(灰度 28x28 图像))。我想在每个图像上应用运动模糊内核并获得相同形状的输出(10000、28、28、1)。 我尝试使用 def、vectorize 但它没有按预期工作。
它在 python 3.6 上运行
x_test.shape
--> (numpy.ndarray) (10000, 28, 28, 1)
def blurize(x):
# kernel
k = np.array([[0,0,0,0,0,0,0.0013],
[0,0,0,0.0086,0.0574,0.1061,0.1165],
[0,0.0450,0.0938,0.1426,0.0938,0.0450,0],
[0.1165,0.1061,0.0574,0.0086,0,0,0],
[0.0013,0,0,0,0,0,0]])
return (ndimage.convolve(x.reshape(28,28), k, mode='constant', cval=0.0))
blurred = blurize(x_test)
plt.imshow(blurred[1], interpolation='none', cmap='gray')
plt.show()
结果:
ValueError: cannot reshape array of size 7840000 into shape (28,28)
如果我尝试过
blurred = blurize(x_test[1]). 它有效,但仅适用于第二张图片。因为我不想通过 x_test[i] 循环整个数组并将帧再次合并到 (10000, 28, 28, 1) 的预期输出数组中。
谢谢。
【问题讨论】: