我知道这可能是一个愚蠢的问题,但我真的不明白为什么。下面是我尝试从训练数据中打印单个图像和具有相同索引的标签的代码
import matplotlib.pyplot as plt
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
mndata = input_data.read_data_sets("MNIST_data/", one_hot=True)
images_train=mndata.train.images # training set
labels_train=mndata.train.labels
images_test=mndata.test.images # testing set
labels_test=mndata.test.labels
##### Testing single image to network
train_index=4
image = images_train[train_index]
label = labels_train[train_index]
plt.imshow(image.reshape(28,28))
plt.show()
print('label',label)
图像显示为一张 但标签是[ 0.0.0.0.0.0.0.0.0.1.]
最佳答案
在文件“train-labels.idx1-ubyte”中,您有一个偏移量,请查看:
[偏移量][类型][值][描述]
0000 32 位整数 0x00000801(2049) 魔数(Magic Number)(MSB 在前)
0004 32位整数10000个项目
0008 无符号字节 ??标签
0009 无符号字节??标签
......
xxxx 无符号字节 ??标签
加上偏移量8就可以了!
关于python - Mnist 数据图像和标签不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49587628/