【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路径下的数据进行执行该函数。
相关推荐
weixin_402486342 分钟前
小分子 pdb准化为sdf
python
橘子编程2 分钟前
密码学完全指南:从基础到实战
java·python·密码学
蓝色的杯子3 分钟前
Python面试30分钟突击掌握-LeetCode2-Strings
python
ZC跨境爬虫5 分钟前
海南大学交友平台开发实战 day9(头像上传存入 SQLite+BLOB 存储 + 前后端联调避坑全记录)
前端·数据库·python·sqlite
FreakStudio5 分钟前
嘉立创开源:应该是全网MicroPython教程最多的开发板
python·单片机·嵌入式·大学生·面向对象·并行计算·电子diy
kaikaile19958 分钟前
能量算子的MATLAB实现与详细算法
人工智能·算法·matlab
上天_去_做颗惺星 EVE_BLUE11 分钟前
接口自动化测试全流程:pytest 用例收集、并行执行、Allure 报告合并与上传
python·pytest
小布的学习手记12 分钟前
教AI读小说:把《时光机器》变成一串数字的奇妙旅程
人工智能
chushiyunen15 分钟前
python fastapi使用、uvicorn
开发语言·python·fastapi
就是有点傻15 分钟前
机器视觉图像处理学习第一天
人工智能·计算机视觉