我知道这可能是一个愚蠢的问题,但我真的不知道为什么。下面是我尝试从训练数据中打印具有相同索引的单个图像和标签的代码
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)图像显示为1,但标签为0。0。0。0。0。0。0。0。0。1.
发布于 2018-06-02 10:17:56
在文件"train-labels.idx1-ubyte“中,你有一个偏移量,看一下:
偏移值
0000 32位整数0x00000801(2049)幻数(MSB优先)
0004 32位整数10000项数
0008无符号字节??标签
0009无符号字节??标签
.
xxxx无符号字节??标签
加上8的偏移量就可以了!
资料来源:http://yann.lecun.com/exdb/mnist/
https://stackoverflow.com/questions/49587628
复制相似问题