【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路径下的数据进行执行该函数。
相关推荐
ZTLJQ1 小时前
序列化的艺术:Python JSON处理完全解析
开发语言·python·json
H5css�海秀1 小时前
今天是自学大模型的第一天(sanjose)
后端·python·node.js·php
SuniaWang2 小时前
《Spring AI + 大模型全栈实战》学习手册系列 · 专题六:《Vue3 前端开发实战:打造企业级 RAG 问答界面》
java·前端·人工智能·spring boot·后端·spring·架构
阿贵---2 小时前
使用XGBoost赢得Kaggle比赛
jvm·数据库·python
无敌昊哥战神2 小时前
【LeetCode 257】二叉树的所有路径(回溯法/深度优先遍历)- Python/C/C++详细题解
c语言·c++·python·leetcode·深度优先
IDZSY04302 小时前
AI社交平台进阶指南:如何用AI社交提升工作学习效率
人工智能·学习
七七powerful3 小时前
运维养龙虾--AI 驱动的架构图革命:draw.io MCP 让运维画图效率提升 10 倍,使用codebuddy实战
运维·人工智能·draw.io
水星梦月3 小时前
大白话讲解AI/LLM核心概念
人工智能
温九味闻醉3 小时前
关于腾讯广告算法大赛2025项目分析1 - dataset.py
人工智能·算法·机器学习
White-Legend3 小时前
第三波GPT5.4 日400刀
人工智能·ai编程