def nudge_dataset(X, Y):
"""
This produces a dataset 5 times bigger than the original one,
by moving the 8x8 images in X around by 1px to left, right, down, up
"""
direction_vectors = [[[0, 1, 0],[0, 0, 0],[0, 0, 0]],
[[0, 0, 0],[1, 0, 0],[0, 0, 0]],
[[0, 0, 0],[0, 0, 1],[0, 0, 0]],
[[0, 0, 0],[0, 0, 0],[0, 1, 0]]]
shift = lambda x, w: convolve(x.reshape((8, 8)), mode='constant', weights=w).ravel()
X = np.concatenate([X] + [np.apply_along_axis(shift, 1, X, vector) for vector in direction_vectors])
Y = np.concatenate([Y for _ in range(5)], axis=0)
return X, Y
#6.11
评论列表
文章目录