keras 数据读取几种方式

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

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,
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值