【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路径下的数据进行执行该函数。
相关推荐
DogDaoDao7 分钟前
深度学习增强的视频压缩框架:Neutron Star 如何超越 VVC
人工智能·深度学习·音视频·视频编解码·h266·vvc·视频压缩
nuo53420210 分钟前
2026-07-31 AI 新闻汇总
人工智能
仙宇觉尘15 分钟前
【译】Visual Studio Copilot 中更智能的人工智能编辑
人工智能·copilot·visual studio
AI创界者16 分钟前
【8G显存福音】最新LTX-2.3-22B-DISTILLED-1.1-VBVR 整合包文生视频、图生视频,支持首尾帧/单图无限时长,50系显卡全适配!
人工智能·音视频
科技新芯16 分钟前
ChinaJoy 首日直击!Bidnex 两大 AI 新品正式亮相
人工智能
limingade18 分钟前
如何在手机本地不依靠网络-实现真正的端到端语音交互的智能AI应答
人工智能·智能手机·ai机器人·ai外呼·手机本地ai大模型·离线ai机器人·离线ai
m0_敲代码的彭于晏16819 分钟前
如何查看自己的电脑是 x64 还是 ARM64 ?
人工智能·电脑
南方程序猴19 分钟前
2026年7月最新国内 Codex 安装教程和使用教程:GPT-5.6 完整指南
人工智能·gpt·ai·ai编程
iiiiii1122 分钟前
【论文阅读笔记】Reparameterization Proximal Policy Optimization (RPO):将PPO的稳定性引入可微分强化学习
论文阅读·人工智能·笔记·深度学习·机器学习·机器人·具身智能
GitCode官方32 分钟前
openPangu-2.0-Pro 模型及技术报告正式开源上线 AtomGit AI
人工智能·华为·开源·harmonyos·atomgit