ImageFolder#
- class deepinv.datasets.ImageFolder(root, x_path=None, y_path=None, loader=None, estimate_params=None, transform=None, use_dict_output=False)[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).Tip
Use
use_dict_output=Trueto return a dict with keys"x","y", and"params"instead of a tuple. This is recommended for better readability and flexibility in returned outputs.- 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.use_dict_output (bool) β whether to return output as dict with keys βxβ, βyβ, βparamsβ instead of tuple. Default
Falsefor backward compatibility.
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
Low-intensity STED fluorescence microscopy denoising
Poisson Inverse Problems with Maximum-Likelihood Expectation-Maximization (MLEM)
Self-supervised learning with Equivariant Splitting
Deep Equilibrium (DEQ) algorithms for image deblurring
Unfolded Chambolle-Pock for constrained image inpainting