首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >来自多个文件的Tensorflow shuffle_batch破坏标记

来自多个文件的Tensorflow shuffle_batch破坏标记
EN

Stack Overflow用户
提问于 2017-05-23 23:02:57
回答 1查看 220关注 0票数 0

我正在尝试使用Tensorflow编写我自己的MNIST数字分类器,并且我被一个tf.train.shuffle_batch函数的奇怪行为困住了。

当我试图从不同的文件中加载图像和标签时,这个问题出现了,洗牌批次似乎要对标签和图像进行单独的洗牌,从而产生错误的标签数据。这些数据取自这里

它是shuffle_batch函数的定义行为吗?当数据和标签是不同的文件时,您建议如何处理这种情况?

这是我的密码

代码语言:javascript
运行
复制
DATA = 'train-images.idx3-ubyte'
LABELS = 'train-labels.idx1-ubyte'
data_queue = tf.train.string_input_producer([DATA,])
label_queue = tf.train.string_input_producer([LABELS,])

NUM_EPOCHS = 2
BATCH_SIZE = 10

reader_data = tf.FixedLengthRecordReader(record_bytes=28*28, header_bytes = 16)
reader_labels = tf.FixedLengthRecordReader(record_bytes=1, header_bytes = 8)

(_,data_rec) = reader_data.read(data_queue)
(_,label_rec) = reader_labels.read(label_queue)

image = tf.decode_raw(data_rec, tf.uint8)
image = tf.reshape(image, [28, 28, 1])
label = tf.decode_raw(label_rec, tf.uint8)
label = tf.reshape(label, [1])


image_batch, label_batch = tf.train.shuffle_batch([image, label],
                                                 batch_size=BATCH_SIZE,
                                                 capacity=100,
                                                 min_after_dequeue = 30)


sess = tf.InteractiveSession()
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)

image = image_batch[1]
im = image.eval()
print("im_batch shape :" + str(image_batch.get_shape().as_list()))
print("label shape :" + str(label_batch.get_shape().as_list()))
print("label is :" + str(label_batch[1].eval()))
# print("output is :" + str(conv1.eval()))

plt.imshow(np.reshape(im, [-1, 28]), cmap='gray')
plt.show()
coord.request_stop()
coord.join(threads)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-23 23:15:55

我认为问题的出现是因为您在单独的image调用中评估label_batch[1]Tensor.eval()。这意味着您正在从两个不同的批中获取值。如果你写的是:

代码语言:javascript
运行
复制
im, lbl = sess.run([image_batch[1], label_batch[1]])

...you应该从同一批获得匹配的图像和标签。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44146395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档