def get_batch(image, label, image_W, image_H, batch_size, capacity):
image = tf.cast(image, tf.string)
label = tf.cast(label, tf.int32)
#生成列队
input_queue = tf.train.slice_input_producer([image, label])
label = input_queue[1]
image_contents = tf.read_file(input_queue[0])
image = tf.image.decode_jpeg(image_contents, channels=3)
image = tf.image.resize_image_with_crop_or_pad(image, image_W, image_H)
a = tf.reduce_mean(image)
image = tf.subtract(image,a)
image_batch, label_batch = tf.train.batch([image, label],
batch_size= batch_size,
num_threads= 16,
capacity = capacity)
label_batch = tf.reshape(label_batch, [batch_size])
image_batch = tf.cast(image_batch, tf.float32)
return image_batch, label_batch
&nb

本文介绍了在TensorFlow中如何实现数据的批处理。通过一个线程读取硬盘上的图片并放入队列,另一个线程负责计算任务,直接从队列获取数据。使用tf.train.Coordinator创建线程协调器,调用tf.train.start_queue_runners启动线程,确保数据正确读取。tf.train.batch函数根据传入参数类型返回tensor列表或单个tensor。

1677

被折叠的 条评论
为什么被折叠?



