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: ImageDataset

Dataset loading images from files.

By default, the images are loaded from image files (png, jpg etc.) located in root.

For more flexibility, set x_path or y_path to load ground truth x and/or measurements y from specific file patterns.

Tip

To load data from subfolders, use globs such as x_path = "GT/**/*.png", y_path = "meas/**/*.png".

Tip

Set y_path only 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=True to 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 to PIL.Image.open.

  • estimate_params (Callable) – optional function that takes tensors x,y and returns dict of params. Advanced usage only.

  • transform (Callable, tuple) – optional callable transform. If tuple or list of length 2, x is transformed with first transform and y with second.

  • use_dict_output (bool) – whether to return output as dict with keys β€œx”, β€œy”, β€œparams” instead of tuple. Default False for 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) pair

Loading 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

Imaging inverse problems with adversarial networks

Bring your own dataset

Bring your own dataset

Distributed Training of Unfolded Networks

Distributed Training of Unfolded Networks

Low-intensity STED fluorescence microscopy denoising

Low-intensity STED fluorescence microscopy denoising

Fitting NIQE on a custom dataset

Fitting NIQE on a custom dataset

Super-resolution with SRResNet

Super-resolution with SRResNet

Training a reconstruction model

Training a reconstruction model

Image deblurring with Total-Variation (TV) prior

Image deblurring with Total-Variation (TV) prior

Poisson Inverse Problems with Maximum-Likelihood Expectation-Maximization (MLEM)

Poisson Inverse Problems with Maximum-Likelihood Expectation-Maximization (MLEM)

Image inpainting with wavelet prior

Image inpainting with wavelet prior

Multi-scale Plug-and-Play for Inpainting

Multi-scale Plug-and-Play for Inpainting

Image transformations for Equivariant Imaging

Image transformations for Equivariant Imaging

Self-supervised learning with Equivariant Splitting

Self-supervised learning with Equivariant Splitting

Scan-specific zero-shot SSDU for MRI

Scan-specific zero-shot SSDU for MRI

Deep Equilibrium (DEQ) algorithms for image deblurring

Deep Equilibrium (DEQ) algorithms for image deblurring

Unfolded Chambolle-Pock for constrained image inpainting

Unfolded Chambolle-Pock for constrained image inpainting