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_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就可以了!

来源:http://yann.lecun.com/exdb/mnist/

关于python - Mnist 数据图像和标签不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49587628/

相关文章:

Python Setuptools 和 PBR - 如何使用 git 标签作为版本创建包版本?

python - 如何使用discord.py 查找用户上次事件的时间?

python - 下载了Python版的SciPy,无法使用

python - 如何删除从文档中获取的图像的边框(如 MNIST 手写字符)?

python-3.x - 无法将大小为 64 的数组 reshape 为形状 (28,28)

python - 访问对象存储器地址

可选参数和位置参数之间的 Python argparse 大小写不一致

python - 在 Tensorflow 中对 MNIST 运行测试时出现数据类型转换错误

python - TensorFlow 模型恢复 ValueError - 至少两个变量具有相同的名称

Tensorflow 中的 Python SSL 认证问题