tensorflow 读取cifar_tensorflow cifar10读取数据get stu

我试图用tensorflow读取cifar10的输入数据。我知道tensorflow/models github repo下存在cifar10.py。当运行以下代码时,它基本上会卡住,并且在屏幕上没有显示任何结果。帮忙谢谢。在from __future__ import absolute_import

from __future__ import division

from __future__ import print_function

import time

import numpy as np

import tensorflow as tf

from tensorflow.contrib import learn

from tensorflow.contrib.learn.python.learn.estimators import model_fn as model_fn_lib

tf.logging.set_verbosity(tf.logging.INFO)

def read_input(filename_queue):

label_bytes = 1

record_bytes = label_bytes + (32 * 32 * 3)

reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)

key, value = reader.read(filename_queue)

single_row_bytes = tf.decode_raw(value, tf.uint8)

label = tf.cast(tf.strided_slice(single_row_bytes, [0], [1]), tf.int32)

image = tf.transpose(tf.reshape(tf.strided_slice(single_row_bytes, [1], [3073]), [3, 32, 32]), [1,2,0])

return label, image

def generate_image_and_label_batch(label, image, batch_size, num_preprocess_threads, min_queue_examples):

images, label_batch = tf.train.batch(

[image, label],

batch_size=batch_size,

num_threads=num_preprocess_threads,

capacity=min_queue_examples + 3 * batch_size)

return images, tf.reshape(label_batch, [batch_size])

def mainFunction(file_names):

filename_queue = tf.train.string_input_producer(file_names)

label, image = read_input(filename_queue)

image.set_shape([32, 32, 3])

label.set_shape([1])

return generate_image_and_label_batch(label, image, 10, 2, 4000)

def main(unused_argv):

with tf.Graph().as_default():

with tf.Session() as sess:

x, y = sess.run(mainFunction(["cifar-10-batches-py/data_batch_" + str(i) for i in range(1,2)]))

print(x)

print(y)

if __name__ == "__main__":

tf.app.run()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值