【TensorFlow2.0】tf.keras.preprocessing.image.ImageDataGenerator#flow_from_diectory

flow_from_directory返回值 tensorflow2.0 ImageDataGenerator中关于flow_from_directory返回值的方法列举ImageDataGeneratorImageDataGenerator.flow_from_directory ImageDataGenerator tensorflow中用于数据读入处理等问题的包,使用起来较为方便,也提供了很多方法供大家灵活使用具体见链接 link. ImageDataGenerator.flow_from_directory 由于在模型测试时需要对数据进行详细了 阅读详情

flow_from_diectory是ImageGenerator类下的函数,从函数名,就可以明白其就是从文件夹中读取图像。

定义

  def flow_from_directory(self,
                          directory,
                          target_size=(256, 256),
                          color_mode='rgb',
                          classes=None,
                          class_mode='categorical',
                          batch_size=32,
                          shuffle=True,
                          seed=None,
                          save_to_dir=None,
                          save_prefix='',
                          save_format='png',
                          follow_links=False,
                          subset=None,
                          interpolation='nearest'):
    """Takes the path to a directory & generates batches of augmented data.

    Args:
        directory: string, path to the target directory. It should contain one
          subdirectory per class. Any PNG, JPG, BMP, PPM or TIF images inside
          each of the subdirectories directory tree will be included in the
          generator. See [this script](
            https://gist.github.com/fchollet/0830affa1f7f19fd47b06d4cf89ed44d)
              for more details.
        target_size: Tuple of integers `(height, width)`, defaults to `(256,
          256)`. The dimensions to which all images found will be resized.
        color_mode: One of "grayscale", "rgb", "rgba". Default: "rgb". Whether
          the images will be converted to have 1, 3, or 4 channels.
        classes: Optional list of class subdirectories
            (e.g. `['dogs', 'cats']`). Default: None. If not provided, the list
              of classes will be automatically inferred from the subdirectory
              names/structure under `directory`, where each subdirectory will be
              treated as a different class (and the order of the classes, which
              will map to the label indices, will be alphanumeric). The
              dictionary containing the mapping from class names to class
              indices can be obtained via the attribute `class_indices`.
        class_mode: One of "categorical", "binary", "sparse",
            "input", or None. Default: "categorical".
            Determines the type of label arrays that are returned:
            - "categorical" will be 2D one-hot encoded labels,
            - "binary" will be 1D binary labels,
            - "sparse" will be 1D integer labels,
            - "input"  will be images identical to input images (mainly used to
              work with autoencoders).
            - If None, no labels are returned (the generator will only yield
              batches of image data, which is useful to use with
              `model.predict()`).
            Please note that in case of class_mode None, the data still needs to
            reside in a subdirectory of `directory` for it to work correctly.
        batch_size: Size of the batches of data (default: 32).
        shuffle: Whether to shuffle the data (default: True) If set to False,
          sorts the data in alphanumeric order.
        seed: Optional random seed for shuffling and transformations.
        save_to_dir: None or str (default: None). This allows you to optionally
          specify a directory to which to save the augmented pictures being
          generated (useful for visualizing what you are doing).
        save_prefix: Str. Prefix to use for filenames of saved pictures (only
          relevant if `save_to_dir` is set).
        save_format: one of "png", "jpeg", "bmp", "pdf", "ppm", "gif",
            "tif", "jpg"
            (only relevant if `save_to_dir` is set). Default: "png".
        follow_links: Whether to follow symlinks inside
            class subdirectories (default: False).
        subset: Subset of data (`"training"` or `"validation"`) if
          `validation_split` is set in `ImageDataGenerator`.
        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, `"box"` and `"hamming"` are also
          supported. By default, `"nearest"` is used.

    Returns:
        A `DirectoryIterator` yielding tuples of `(x, y)`
            where `x` is a numpy array containing a batch
            of images with shape `(batch_size, *target_size, channels)`
            and `y` is a numpy array of corresponding labels.
    """

flow_from_diectory中参数含义:


directory:目标文件夹路径,对于每一个类,该文件夹都要包含一个子文件夹。

target_size:整数tuple,默认为(256, 256)。图像将被resize成该尺寸

color_mode:颜色模式,为"grayscale"和"rgb"之一,默认为"rgb",代表这些图片是否会被转换为单通道或三通道的图片。

classes:可选参数,为子文件夹的列表,如['cat','dog'],默认为None。若未提供,则该类别列表将从directory下的子文件夹名称/结构自动推断。每一个子文件夹都会被认为是一个新的类。(类别的顺序将按照字母表顺序映射到标签值)。

class_mode: "categorical", "binary", "sparse"或None之一。默认为"categorical。该参数决定了返回的标签数组的形式, "categorical"会返回2D的one-hot编码标签,"binary"返回1D的二值标签。"sparse"返回1D的整数标签,如果为None则不返回任何标签,生成器将仅仅生成batch数据。

batch_size:batch数据的大小,默认32。

shuffle:是否打乱数据,默认为True。

seed:可选参数,打乱数据和进行变换时的随机数种子。

save_to_dir:None或字符串,该参数能让你将数据增强后的图片保存起来,用以可视化。

save_prefix:字符串,保存数据增强后图片时使用的前缀, 仅当设置了save_to_dir时生效。

save_format:"png"或"jpeg"之一,指定保存图片的数据格式,默认"jpeg"。

这些参数中的directory一定要弄清楚,它是指类别文件夹的上一层文件夹,在该数据集中,类别文件夹为cat和dog,它的上一级文件夹是train。所以director为 r"D://Learning//tensorflow_2.0//animal//data//train"

另外,class这个参数也要注意,通常我们就采用默认None,directory的子文件夹就是标签。在该分类任务中标签就是smile和neutral。

GD32_ADC采样+DMA多通道扫描传输 所使用的MCU 片上集成了 12 位逐次逼近式模数转换器模块(ADC),可以采样来自于 16 个外部通道和 2 个内部通道上的模拟信号。这 18 个 ADC 采样通道都支持多种运行模式,采样转换后,转换结果可以按照最低有效位对齐或最高有效位对齐的方式保存在相应的数据寄存器中。我们主要介绍其多通道扫描转换和DMA传输功能,在多个通道轮询采集ad数据,并使用DMA分别保存各个数据值,其能大大提高ADC的工作效率。以下为ADC 模块框图: 阅读详情

相关推荐

Ubuntu20.04/Debian10安装向日葵远程控制踩坑实录(附依赖问题解决方案)

本文详细介绍了在Ubuntu 20.04/Debian 10系统上安装向日葵远程控制软件的全过程,重点解决了常见的依赖问题,特别是libwebkitgtk相关错误。通过自动修复、手动修改.deb包依赖和使用兼容层三种解决方案,帮助用户顺利完成安装并优化远程控制体验。

silver的专栏 748

ImageDataGenerator生成器的flow,flow_from_directory用法

flow: flow(self, X, y, batch_size=32, shuffle=True, seed=None, save_to_dir=None, save_prefix='', save_format='png'):接收numpy数组和标签为参数,生成经过数据提升或标准化后的batch数据,并在一个无限循环中不断的返回batch数据 x:样本数据,秩应为4.在黑白图像的情况...

mieleizhi0522的博客 8万+

Spring Boot Swagger未授权访问漏洞:原理、风险与修复方案详解

在微服务架构中,API文档管理是开发与运维的重要环节。Swagger作为RESTful API文档生成与调试的标准化工具,通过OpenAPI规范自动生成交互式接口文档,极大提升了开发效率。然而,其默认配置往往缺乏访问控制,导致文档端点直接暴露,形成未授权访问漏洞。从技术原理看,该漏洞源于Spring Boot等框架集成Swagger时,相关端点未纳入安全框架的拦截范围,攻击者可通过扫描常见路径获取完整的接口定义与数据结构。这不仅会造成敏感信息泄露,更可能成为越权操作、数据篡改等深度攻击的入口点。在工程实践中

weixin_42524171的博客 492

keras flow_from_directory()

keras_preprocessing.image.image_data_generator.ImageDataGenerator.flow_from_directory() 获取目录路径并生成一批增强数据。 def flow_from_directory(self, directory: Any, t...

baixue0729的博客 1万+

UVM自学笔记3——项目之三——从零开始搭建ahb_sramc验证平台

创建如下所示的目录结构: 2.在tb的文件下:顶层的testbench如下:在tb中,第24行的代码将uvm宏相关的内容include进来,第26行的代码把uvm_pkg包导入进来,然后将agent相关的包(ahb_pkg/sram_pkg),testcase相关的包(uvm_ahb_sram_test_pkg)以及env相关的包(uvm_ahb_sram_env_pkg)都导入进来,在第38行和39行将接口以virtual interface的形式配置给ahb_agent和sramc_agent下

ZhangShuHuai11的博客 9469

RK3588开发板实战:从零开始移植Ubuntu 24.04(讯为SDK版)

本文详细介绍了如何在RK3588开发板上从零开始移植Ubuntu 24.04系统(讯为SDK版),涵盖开发环境准备、SDK解析、根文件系统定制、驱动适配、系统集成与烧录等全流程。通过实战案例,帮助开发者快速掌握RK3588开发板的系统移植技巧,适用于嵌入式开发与定制化Linux系统构建。

sand8的博客 435

Tensorflow2中ImageDataGenerator中flow_from_directory()和image_dataset_from_directory()区别

这两个函数经常用来创建深度学习的数据集,有些类似,但也有不同,不同在于数据返回的类型不一样。 1.flow_from_directory() keras_preprocessing.image.image_data_generator.ImageDataGenerator.flow_from_directory() def flow_from_directory(self, directory: Any,

soderayer的博客 3963

Dify 第 13 篇 Dify 工作流 详解

工作流通过将复杂任务分解为节点降低复杂度,提升LLM应用的性能和稳定性。Dify工作流分为两类:Chatflow面向对话场景(如客服),支持多轮对话;Workflow面向批处理场景(如翻译),提供逻辑节点实现自动化。核心概念包括节点、变量(系统/会话/环境变量)及应用类型差异:Chatflow支持中间输出和对话历史,Workflow仅支持结束节点输出。系统变量以"sys"开头,用于全局数据传递,不同应用类型变量不同,如Chatflow的sys.query存储用户输入,Workflow的s

甘蓝的专栏 3243

keras ImageDataGenerator类(1)-flow_from_directory

1前言 ImageDataGenerator()是keras.preprocessing.image模块中的图片生成器,可以每一次给模型“喂”一个batch_size大小的样本数据,同时也可以在每一个批次中对这batch_size个样本数据进行增强,扩充数据集大小,增强模型的泛化能力。比如进行旋转,变形,归一化等等。 图片生成器,负责生成一个批次一个批次的图片,以生成器的形式给模型训练; 对每一个批次的训练图片,适时地进行数据增强处理(data augmentation); ——————————————

chenvvei的博客 4614

YOLOv11改进 | 损失函数改进篇 | EIoU、SIoU、WIoU、DIoU、FocusIoU等二十余种损失函数

这篇文章介绍了YOLOv11的重大改进,特别是在损失函数方面的创新。它不仅包括了多种IoU损失函数的改进和变体,如SIoU、WIoU、GIoU、DIoU、EIOU、CIoU,还融合了“Focus”思想,创造了一系列新的损失函数。这些组合形式的损失函数超过了二十余种,每种都针对特定的目标检测挑战进行优化。文章会详细探讨这些损失函数如何提高YOLOv11在各种检测任务中的性能,包括提升精度、加快收敛速度和增强模型对复杂场景的适应性。

Snu77的博客 6183

ImageDataGenerator生成器flow, flow_from_dataframe, flow_from_directory方法

ImageDataGenerator.flow 函数 def flow(self, x, y=None, batch_size=32, shuffle=True, sample_weight=None, seed=None, save_to_dir=None, save_prefix='', save_format...

qq_31119155的博客 7210

Far planner代码系列(2)

graph_decoder系列(2) 承接上文 我们接着来看decoder_node.cpp的代码部分 void GraphDecoder::Init() { /* initialize subscriber and publisher */ //graph_sub_ 订阅节点/robot_vgraph 其类型是visibility_graph_msg/Graph的消息 graph_sub_ = nh.subscribe("/robot_vgrap...

博客 1533

tensorflow数据集制作方法之ImageDataGenerator-flow_from_directory

import cv2 #正则匹配使用: import re import os #此库用于拷贝,删除,移动,复制以及解压缩 import shutil import numpy as np import tensorflow as tf from tensorflow.keras.preprocessing.image import ImageDataGenerator import matplotlib.pyplot as plt #如此读取图像,直接返回numpy.ndarray #img=cv2.im

种一棵树最好的时间是十年前,其次是现在 1173

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

利用keras中image.ImageDataGenerator.flow_from_directory()实现从文件夹中提取图片和进行简单归一化处理

keras中有很多封装好的API可以帮助我们实现对图片数据的读取和处理。 比如 : keras.preprocessing.image.ImageDataGenerator.flow_from_directory( ) 这个函数 这个函数的参数包括: flow_from_directory(self, directory, target

liguandong 4万+

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

ImageDataGenerator生成器的flow_from_directory()函数

作用:获取目录的路径并生成增强数据批 参数如下: def flow_from_directory(self, directory, target_size=(256, 256), color_mode='rgb', ...

weixin_43786241的博客 1433

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

keras利用flow_from_directoryt自己构建数据集

train_datagen = ImageDataGenerator(rescale=1. / 255, #归一化 rotation_range=10, #旋转角度 width_shift_range=0.1, #水平偏移 height_shift_range

重剑无锋博客 1338

keras的图像预处理全攻略(四)—— ImageDataGenerator 类实践案例

前言:前面已经详细介绍了keras整个图像预处理模块的详细流程,参见下面两篇文章: keras的图像预处理全攻略(二)—— ImageDataGenerator 类 keras的图像预处理全攻略(三)—— ImageDataGenerator 类的辅助类 本文结合实际案例来说说明到底该怎么应用ImageDataGenerator 类以及需要注意的一些事项 一、图像分类问题中Im...

MIss-Y的博客 2万+

使用tensorflow搭建分类神经网络以及迁移学习(训练过程)

*************************************************** 码字不易,收藏之余,别忘了给我点个赞吧! *************************************************** ---------Start 本文不涉及tensorflow环境配置过程,只讲解整个项目代码大致内容。至于每个函数的每个参数意义,同学们可以百度了解或私信我,见谅! 数据集:二分类数据集,每个类别包含一个文件夹,文件夹中都保存了对应类别的图像数据。 Norma

qq_37652891的博客 3485

Keras教学(9):Keras的图像预处理,看这一篇就够了

Keras进行图像预处理的方法,包括讲解了flow函数,flow_generator函数和model.fit_generrator函数

my_name_is_learn的博客 3566

ImageDataGenerator.flow_from_directory(...)

日萌社 人工智能AI:Keras PyTorch MXNet TensorFlow PaddlePaddle 深度学习实战(不定时更新) # 定义输入数据的大小和批次大小 image_size = (224, 224) batch_size = 32 #即使读取的图片分辨率大小和image_size指定的大小不一致也没关系, #会对输入图片进行自动截取image_size指定的大...

あずにゃん梓喵的博客 1508

【计算视觉】ImageDataGenerator生成器的flow,flow_from_directory用法

flow: flow(self, X, y, batch_size=32, shuffle=True, seed=None, save_to_dir=None, save_prefix='', save_format='png'):接收numpy数组和标签为参数,生成经过数据提升或标准化后的batch数据,并在一个无限循环中不断的返回batch数据 x:样本数据,秩应为4.在黑白图像的情况下c...

小白兔的窝 6777

Keras数据增强并保存到本地

当需要对指定文件夹下的图片进行数据增广时,使用keras的ImageDataGenerator类的flow_from_directory()方法可快速的实现 1.首先实例化ImageDataGenerator对象以自己想要的属性 img_datagen = keras.preprocessing.image.ImageDataGenerator(featurewise_center=False, samplew

爱CV 1235

猫狗大战【1】——CNN

数据集:链接:https://pan.baidu.com/s/1KHv3-2FwXgAsaEHHSb3Vrg 提取码:rpxv 或者在移动盘中的data文件夹中,创建两个文件夹,train、test;两个文件夹中分别创建两个文件cat、dog;train各1000个,test各500个 from keras.models import Sequential from keras.layer...

Ring__Rain的博客 1040

keras图像输入通道建立——flow_from_directory

动机 keras日渐火热,了解其高效建立输入通道的方法有重要意义。 目标 创建并结构化数据集 生成训练集和验证集 模型选择、加载、编译和训练 创建并结构化数据集 以图像分割为例,你必须跟踪图像和它们的膜。通常情况下,,你将选择PASCAL VOC, 或者MS COCO, 或者Cityscapes。 如果选择这些数据集,你大部分的工作已经完成...

tianzhiya121的博客 4937

keras生成器的flow方法实例(flow_from_directory)

flow 是使用生成器进行数据增强的一种方法, 具体的参数列表可以参考官网, 实例如下, # -*- coding: utf-8 -*- """ @Time : @Author : kkk @File : @Software: PyCharm """ from keras.preprocessing.image import ImageDataGenerator, im...

Pierce_KK的博客 1241
上一篇: 【TensorFlow2.0】tf.keras.preprocessing.image.ImageDataGenerator
下一篇: 【TensorFlow2.0】以后我们再也离不开Keras了?
Accelerating
博客等级 码龄9年 3220粉丝 28原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值