Python Mnist数据图像和标签不匹配
我知道这可能是个愚蠢的问题,但我真的不明白为什么。下面是我试图打印单个图像和标签的代码,这些图像和标签的索引与Python Mnist数据图像和标签不匹配,python,mnist,Python,Mnist,我知道这可能是个愚蠢的问题,但我真的不明白为什么。下面是我试图打印单个图像和标签的代码,这些图像和标签的索引与 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_t
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位整数0x0000081(2049)幻数(MSB优先)
0004 32位整数10000个项目
0008无符号字节??标签
0009无符号字节??标签
xxxx无符号字节??标签
加上8的偏移量就可以了
来源:您确定所有其他“一”的编码方式都不相同吗?您使用的是一个one\u hot
编码器,没有理由认为1
应该排在第二位。因此,只要具有相同编号的所有图像具有相同的标签,就没有问题。