【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路径下的数据进行执行该函数。
相关推荐
寻星探路1 分钟前
【算法专题】哈希表:从“两数之和”到“最长连续序列”的深度解析
java·数据结构·人工智能·python·算法·ai·散列表
非凡ghost3 分钟前
ImageConverter(图像转换编辑工具)
图像处理·人工智能·windows·学习·计算机视觉·软件需求
@zulnger4 分钟前
python 学习笔记(闭包)
笔记·python·学习
SHolmes18545 分钟前
Python all函数 判断是否同时满足多个条件
java·服务器·python
inksci5 分钟前
Python 中使用 SQL 连接池
服务器·数据库·python
猫头虎6 分钟前
Claude Code 2026 年1月9日迎来大更新:Agent 能力增强(2.1.0 详解 + 升级指南)
ide·人工智能·macos·langchain·编辑器·aigc·ai编程
子午9 分钟前
【2026原创】中草药识别系统实现~Python+深度学习+模型训练+人工智能
人工智能·python·深度学习
洛克大航海10 分钟前
Python 在系统 Windows 和 Ubuntu 中创建虚拟环境
windows·python·ubuntu·虚拟环境
ZEERO~12 分钟前
@dataclass的作用
开发语言·windows·python
编码小哥17 分钟前
OpenCV特征匹配:暴力匹配与FLANN匹配实战
人工智能·opencv·计算机视觉