例如,我从 mat 文件加载的 background-Mnist 为训练集提供了 50,000x784。
应该有 50,000 个 28x28 图像
我用
f_train = scio.loadmat('mnist_background_images/mnist_background_images_train.mat')
f_test = scio.loadmat('mnist_background_images/mnist_background_images_test.mat')
data_train = f_train['mnist_background_images_train']
data_test = f_test['mnist_background_images_test'] #this gives 50,000x785 where last column is y
x_train = data_train[:, :-1]
x_test= data_test[:, :-1] #now it's 50,000x784
x_train = np.reshape(x_train, newshape=(-1, 28, 28 )) #new shape 50,000x28x28
x_test = np.reshape(x_test, newshape=(-1, 28, 28))
这给出了正确的尺寸。
但是,当我尝试通过
img = x_train[2]
out = Image.fromarray(img, mode = 'L')
print(x_train.shape)
给出 (50000, 784)
这张图片看起来一点也不像 MNIST 数据。像素混合在一起,到处都是,就像一切都被打乱了一样。我在某个地方犯了一个愚蠢的错误吗?
