keras数据读取(图像数据)的方式,可以不使用keras的方法而使用opencv或者pil直接读取做处理。这里主要总结了keras封装的几种图像数据读取方法,
一、keras.preprocessing.image.load_img()读取单张图像
1)load_img()指定图像路径读取图像,看源码可知就是对pil的简单封装,使用PIL.mage.open()读取
def load_img(path, grayscale=False, target_size=None,
interpolation='nearest'):
"""Loads an image into PIL format.
# Arguments
path: Path to image file
grayscale: Boolean, whether to load the image as grayscale.
target_size: Either `None` (default to original size)
or tuple of ints `(img_height, img_width)`.
interpolation: Interpolation method used to resample the image if the
target size is different from that of the loaded image.
Supported methods are "nearest", "bilinear", and "bicubic".
If PIL version 1.1.3 or newer is installed, "lanczos" is also
supported. If PIL version 3.4.0 or newer is installed,

本文详细介绍了Keras中图像数据的读取及处理方法,包括使用load_img()和img_to_array()进行图像加载与转换,以及ImageDataGenerator类实现的数据增强技巧。通过实例展示了如何利用这些工具进行高效的图像预处理。
最低0.47元/天 解锁文章
5148





