如果您希望使该输入管道正常工作,则需要添加一个异步队列机制来生成大量示例。这是通过创建
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图像的任意目录上运行此预处理脚本的通用版本。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)