【pytorch | torchvision | datasets】ImageFolder()类

Class ImageFolder##

class torchvision.datasets.ImageFolder(root: ~typing.Union[str, ~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路径下的数据进行执行该函数。
相关推荐
曲幽12 分钟前
不止于JWT:用FastAPI的Depends实现细粒度权限控制
python·fastapi·web·jwt·rbac·permission·depends·abac
风象南8 小时前
我把大脑开源给了AI
人工智能·后端
Johny_Zhao10 小时前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
飞哥数智坊10 小时前
我帮你读《一人公司(OPC)发展研究》
人工智能
冬奇Lab13 小时前
OpenClaw 源码精读(3):Agent 执行引擎——AI 如何「思考」并与真实世界交互?
人工智能·aigc
没事勤琢磨15 小时前
如何让 OpenClaw 控制使用浏览器:让 AI 像真人一样操控你的浏览器
人工智能
用户51914958484515 小时前
CrushFTP 认证绕过漏洞利用工具 (CVE-2024-4040)
人工智能·aigc
牛马摆渡人52816 小时前
OpenClaw实战--Day1: 本地化
人工智能
前端小豆16 小时前
玩转 OpenClaw:打造你的私有 AI 助手网关
人工智能
BugShare16 小时前
写一个你自己的Agent Skills
人工智能·程序员