如何从示例队列将数据读取到TensorFlow批处理中?

如何从示例队列将数据读取到TensorFlow批处理中?,第1张

如何从示例队列将数据读取到TensorFlow批处理中?

如果您希望使该输入管道正常工作,则需要添加一个异步队列机制来生成大量示例。这是通过创建

atf.RandomShuffleQueue
atf.FIFOQueue
并插入已读取,解码和预处理的JPEG图像来执行的。

您可以使用方便的结构,这些结构将通过

tf.train.shuffle_batch_join
或生成队列和用于运行队列的相应线程
tf.train.batch_join
。这是一个简单的示例。请注意,此代码未经测试:

# Let's assume there is a Queue that maintains a list of all filenames# called 'filename_queue'_, file_buffer = reader.read(filename_queue)# Depre the JPEG imagesimages = []image = depre_jpeg(file_buffer)# Generate batches of images of this size.batch_size = 32# Depends on the number of files and the training speed.min_queue_examples = batch_size * 100images_batch = tf.train.shuffle_batch_join(  image,  batch_size=batch_size,  capacity=min_queue_examples + 3 * batch_size,  min_after_dequeue=min_queue_examples)# Run your network on this batch of images.predictions = my_inference(images_batch)

根据您需要扩展工作的方式,您可能需要运行多个独立的线程来读取/解码/预处理图像并将其转储到示例队列中。Inception / ImageNet模型中提供了此类管道的完整示例。看一下batch_inputs:

https://github.com/tensorflow/models/blob/master/inception/inception/image_processing.py#L407

最后,如果要使用> O(1000)JPEG图像,请记住,单独准备1000个小文件的效率极低。这会大大减慢您的训练速度。

将图像数据集转换TFRecord为Example原型碎片的更强大,更快速的解决方案。这是一个完全有效的脚本,用于将ImageNet数据集转换为这种格式。这是一组说明,用于在包含JPEG图像的任意目录上运行此预处理脚本的通用版本。



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5617367.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存