【pytorch | torchvision | datasets】ImageFolder()类

Class ImageFolder##

class torchvision.datasets.ImageFolder(root: ~typing.Unionstr, \~pathlib.Path, transform: ~typing.Optional~typing.Callable = None, target_transform: ~typing.Optional~typing.Callable = None, loader: ~typing.Callable\[str, ~typing.Any] = , is_valid_file: ~typing.Optional~typing.Callable\[\[str, bool]] = None, allow_empty: bool = False)

就该类输出的格式

A generic data loader where the images are arranged in this way by default:

一个通用的默认排列方式的图像数据加载器:

root/dog/xxx.png

root/dog/xxy.png

root/dog/.../xxz.png


root/cat/123.png

root/cat/nsdf3.png

root/cat/.../asd932_.png

parameters;

This class inherits from DatasetFolder so the same methods can be overridden to customize the dataset.

  • Parameters:
    • root (str or pathlib.Path) -- Root directory path.

    • transform (callable, optional) -- A function/transform that takes in a PIL image or torch.Tensor, depends on the given loader, and returns a transformed version. E.g, transforms.RandomCrop

    • target_transform (callable, optional) -- A function/transform that takes in the target and transforms it.

    • loader (callable, optional) -- A function to load an image given its path.

    • is_valid_file (callable, optional) -- A function that takes path of an Image file and check if the file is a valid file (used to check of corrupt files)

    • allow_empty -- If True, empty folders are considered to be valid classes. An error is raised on empty folders if False (default).

参数

  • root (数据集根目录路径)
  • transform (可选参数;回调函数。就是torchvision中的transform模块中的类对象)。ImageFolder类对象并不会立即执行,而是在你需要该数据时 才会对root路径下的数据进行执行该函数。
相关推荐
kaixin_啊啊16 分钟前
【零基础学AI】第 34 章课后练习与答案
人工智能
always20221 小时前
AI运行时 · 04 - Kata Containers 整体架构
人工智能·架构
星恒随风1 小时前
从0实现C++ AI大模型接入SDK(七):Ollama本地模型部署、NDJSON流式响应与LLMManager模型管理
linux·开发语言·c++·人工智能·笔记
zhinengws1 小时前
沃思智能智能路灯监控终端:从项目落地到智慧城市生态的深度观察
网络·人工智能·智慧城市·智能路灯监控终端
积流成海2 小时前
Agent演化史(十):2027年它会消失吗?(终章)
python·agent·智能体·大模型应用
真上帝的左手2 小时前
4. 关系型数据库-MySQL-原生集成 AI能力
数据库·人工智能·mysql·ai
深频率2 小时前
补丁还在排队,AI先替服务器挡了一刀
服务器·人工智能·jenkins
谙弆悕博士2 小时前
生物启发式集群(Swarm)工程实现:五条规则、一群蚂蚁和四十个粒子
人工智能·gpt·游戏引擎·cocos2d·蚁群算法·多智能体·boids
Summer-Bright3 小时前
深度 | 微调接棒开源:权重免费后,后训练成了云厂商的新收费单元
人工智能·开源·llm·微调·强化训练
专注仿真3 小时前
仿真智能体训练:强化学习中的奖励塑形算法与实战
python·强化学习·afsim智能体·仿真训练·afsim智能体训练