【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路径下的数据进行执行该函数。
相关推荐
荷蒲2 分钟前
【小白量化Qbuddy】用AI设计miniQMT指标公式计算量化平台
人工智能·python·机器人
猎头南楼2 分钟前
VLA 模型在双臂机器人操作中的工程落地:从 pi0 到 diffusion policy 的实践思考
人工智能·机器人
阿童木写作6 分钟前
跨境电商图片翻译工具,批量翻译视频字幕一键抠图
人工智能·python·音视频
ITmaster073119 分钟前
从零开始实现一个 AI Agent CLI
人工智能
user-猴子1 小时前
钛媒体测五款、光锥智能测WorkBuddy、用户测AiPy——三组实测交叉对比,哪款AI办公工具最值得下载?
人工智能
IT古董1 小时前
AI 资讯日报 | 2026年8月29日:开源大模型三连发,DeepSeek 500 亿融资落地
人工智能·开源
何以解忧,唯有..1 小时前
Pydantic 介绍与使用:Python 数据校验的现代方案
数据库·python·microsoft
IT_陈寒1 小时前
Vite打包时的静态资源坑,我帮你踩过了
前端·人工智能·后端
IJCAST2 小时前
IJCAST最新一期已经发布
人工智能·深度学习·神经网络
又幸福了哥2 小时前
Python入门到高级(知识点七)
python