我正在尝试shift()
在 MNIST 图像上使用该功能。
但是,不知何故,当我查看原始数据和移位数据时,看起来恰好为零的移位值正在变成非常小的非零值而不是零。这方面的一个例子是,在移位之前的值为零,而在移位之后的值类似于##########e-18
. 因此,所有其他值都变成了##########e+02
.
这是我正在运行的代码。
from sklearn.datasets import fetch_openml
mnist = fetch_openml('mnist_784')
x, y = mnist['data'], mnist['target']
x_train, x_test, y_train, y_test = x[:60000], x[60000:], y[:60000], y[60000:]
import numpy as np
shuffle_index = np.random.permutation(60000)
x_train, y_train = x_train[shuffle_index], y_train[shuffle_index]
image = x_train[99]
reshaped = image.reshape(28,28)
reshaped_2 = reshaped.reshape(784,)
from scipy.ndimage.interpolation import shift
print(reshaped[7:10,:])
print(shift(reshaped, [1,0], cval=0)[8:11,:])
这是输出
[[ 0. 0. 0. 0. 0. 0. 0. 0. 32. 109. 109. 110. 109. 109.
109. 255. 253. 253. 253. 255. 211. 109. 47. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 32. 73. 73. 155. 217. 227. 252. 252. 253. 252. 252.
252. 253. 252. 252. 252. 253. 252. 252. 108. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 109. 252. 252. 252. 236. 226. 252. 231. 217. 215. 195.
71. 72. 71. 71. 154. 253. 252. 252. 108. 0. 0. 0. 0. 0.]]
[[-1.45736740e-17 2.08908499e-18 1.97425281e-17 1.32870826e-14
2.88143171e-14 2.90612090e-14 2.63726515e-14 2.89883698e-14
3.20000000e+01 1.09000000e+02 1.09000000e+02 1.10000000e+02
1.09000000e+02 1.09000000e+02 1.09000000e+02 2.55000000e+02
2.53000000e+02 2.53000000e+02 2.53000000e+02 2.55000000e+02
2.11000000e+02 1.09000000e+02 4.70000000e+01 8.06113136e-16
-1.58946559e-16 -9.39990682e-17 2.66688532e-17 -5.77791548e-17]
[-5.61019971e-16 2.32169340e-15 7.43877530e-15 3.20000000e+01
7.30000000e+01 7.30000000e+01 1.55000000e+02 2.17000000e+02
2.27000000e+02 2.52000000e+02 2.52000000e+02 2.53000000e+02
2.52000000e+02 2.52000000e+02 2.52000000e+02 2.53000000e+02
2.52000000e+02 2.52000000e+02 2.52000000e+02 2.53000000e+02
2.52000000e+02 2.52000000e+02 1.08000000e+02 3.29017268e-16
-6.57046610e-16 -1.22504799e-16 2.64344390e-17 -1.25480283e-16]
[-2.16877621e-15 7.92064171e-15 2.39544414e-14 1.09000000e+02
2.52000000e+02 2.52000000e+02 2.52000000e+02 2.36000000e+02
2.26000000e+02 2.52000000e+02 2.31000000e+02 2.17000000e+02
2.15000000e+02 1.95000000e+02 7.10000000e+01 7.20000000e+01
7.10000000e+01 7.10000000e+01 1.54000000e+02 2.53000000e+02
2.52000000e+02 2.52000000e+02 1.08000000e+02 3.04124747e-15
3.67217141e-17 -2.67076835e-16 -1.16801314e-16 -1.39584861e-16]]
是什么导致了这种行为?它是 MNIST 数据集的特性吗?这是我的代码中的错误吗?
Is it possible to use vector methods to shift storage in a numpy ndarray for data augmentation 中的答案?解决了如何更有效地进行移位操作,但它没有回答我的其他问题。