ImageFolder#
- class deepinv.datasets.ImageFolder(root, x_path=None, y_path=None, loader=None, estimate_params=None, transform=None)[source]#
Bases:
ImageDatasetDataset loading images from files.
By default, the images are loaded from image files (png, jpg etc.) located in
root.For more flexibility, set
x_pathory_pathto load ground truthxand/or measurementsyfrom specific file patterns.Tip
To load data from subfolders, use globs such as
x_path = "GT/**/*.png", y_path = "meas/**/*.png".Tip
Set
y_pathonly to load measurements following the file pattern. The measurement-only data will be returned as a tuple(torch.nan, y).- Parameters:
root (str, pathlib.Path) – dataset root directory.
x_path (str, None) – file glob pattern for ground truth data, defaults to None.
y_path (str, None) – file glob pattern for measurement data, defaults to None.
loader (Callable) – optional function that takes filename string and loads file. If
None, defaults toPIL.Image.open.estimate_params (Callable) – optional function that takes tensors
x,yand returns dict ofparams. Advanced usage only.transform (Callable, tuple) – optional callable transform. If
tupleorlistof length 2,xis transformed with first transform andywith second.
Examples:
Using default loading from root folder with image files. Folder structure:
root ├── img1.png └── img2.png dataset = ImageFolder(root) dataset[0] tensor(...) # Returns x only
Loading paired tensors from nested folders using custom glob and loader. Folder structure:
data/ ├── GT/ │ ├── scene1/ │ │ └── x0.pt │ └── scene2/ │ └── x1.pt └── meas/ ├── scene1/ │ └── y0.pt └── scene2/ └── y1.pt dataset = ImageFolder( root, x_path="GT/**/*.pt", y_path="meas/**/*.pt", loader=torch.load ) dataset[0] (tensor(...), tensor(...)) # Returns (x, y) pairLoading unpaired measurements only. Folder structure:
data/ └── meas/ ├── meas0.png └── meas1.png dataset = ImageFolder( "data/", y_path="meas/*.png" ) dataset[0] (torch.nan, tensor(...)) # Returns unpaired y
Examples using ImageFolder:#
Imaging inverse problems with adversarial networks
Deep Equilibrium (DEQ) algorithms for image deblurring
Unfolded Chambolle-Pock for constrained image inpainting