如何在不冻结计算机的情况下加载一堆图像进行深度学习

问题描述 投票:0回答:1

我有一堆tiff图像,我的目标是将这些图像加载到numpy数组中,以便在python 3的keras模型中使用它。问题是,当我将图像转换为数组时,计算机冻结了。我首先尝试将图像转换为数组并将所有内容保存为HDF5格式,现在我仅尝试保存1000张图像,然后使用gc.collect()函数释放一些内存,然后执行相同的过程,直到出现没有图像,但效果不佳。

因此,我想知道一种将这些图像放入模型的有效方法。我这里大约有50.000张图片。你能帮我吗?

python-3.x performance memory-management deep-learning tiff
1个回答
0
投票

我认为您可以使用Tensorflow数据管道来有效地加载和使用图像。这是一个可能对您有用的示例脚本。阿苏

files = tf.data.Dataset.list_files('./*.tiff') # need to change path to point image directory
images = files.map(lambda f: tf.io.read_file(f))
images = images.map(lambda image: tf.io.decode_jpeg(image))

如果您要进行任何预处理,以下内容可能会对您有所帮助。

images = images.map(lambda image: tf.cast(tf.image.resize(image, (128, 128)), tf.uint8))
images = images.map(lambda image: tf.cast(image, tf.float32) / 255)

您可能需要重新整理,重复,批处理数据集

有关更多信息,请查看Tensorflow website中的tf.data页面

© www.soinside.com 2019 - 2024. All rights reserved.