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] = <function default_loader>, is_valid_file: ~typing.Optional[~typing.Callable[[str], bool]] = None, allow_empty: bool = False)[原始碼]¶
預設情況下,圖像以此方式排列的通用資料載入器
root/dog/xxx.png root/dog/xxy.png root/dog/[...]/xxz.png root/cat/123.png root/cat/nsdf3.png root/cat/[...]/asd932_.png
此類別繼承自
DatasetFolder
,因此可以覆寫相同的方法來自訂資料集。- 參數:
root (str 或
pathlib.Path
) – 根目錄路徑。transform (callable, optional) – 接收 PIL 圖像並傳回轉換版本的函數/轉換。例如,
transforms.RandomCrop
target_transform (callable, optional) – 接收目標並轉換它的函數/轉換。
loader (callable, optional) – 給定路徑時載入圖像的函數。
is_valid_file (callable, optional) – 接收圖像檔案路徑並檢查該檔案是否為有效檔案的函數 (用於檢查損毀的檔案)
allow_empty – 如果為 True,則將空資料夾視為有效的類別。如果為 False (預設),則會在空資料夾上引發錯誤。