目前,我希望提高阅读数据的性能。我使用TensorFlow的DataSet api从磁盘读取数据。我想知道是否有从内存中读取图像数据的方法以及如何将图像加载到内存中。我的图像大小不同,需要预处理。 现在,我从磁盘读取图像的代码就是研究员:
# Reads an image from a file, decodes it into a dense tensor, and resizes it
# to a fixed shape.
def _parse_function(filename, label):
image_string = tf.read_file(filename)
image_decoded = tf.image.decode_image(image_string)
image_resized = tf.image.resize_images(image_decoded, [28, 28])
return image_resized, label
# A vector of filenames.
filenames = tf.constant(["/var/data/image1.jpg", "/var/data/image2.jpg", ...])
# `labels[i]` is the label for the image in `filenames[i].
labels = tf.constant([0, 37, ...])
dataset = tf.data.Dataset.from_tensor_slices((filenames, labels))
dataset = dataset.map(_parse_function)