TensorDataset#

class deepinv.datasets.TensorDataset(*, x=None, y=None, params=None, use_dict_output=False)[source]#

Bases: ImageDataset

Dataset wrapping data explicitly passed as tensors.

This dataset can be used to return ground truth x, ground truth and measurements (x, y), or measurements only (y). All input tensors must be of shape (N, ...) and of same N where N is the number of samples and … represents the data dimensions.

Tip

Alternatively, you can use use_dict_output=True to return a dict with at least keys "x" or "y", and "params" instead of a tuple. This is recommended for better readability and flexibility in returned outputs.

Optionally, params are returned too.

Parameters:
  • x (torch.Tensor, None) – optional input ground truth tensor x

  • y (torch.Tensor, None) – optional input measurement tensor y

  • params (dict[str, torch.Tensor], None) – optional input physics parameters params of format {"str": Tensor}

  • use_dict_output (bool) – whether to return output as dict with keys "x", "y", "params"` instead of tuple. Defaults to False for backward compatibility.


Examples:

Construct a dataset from a single measurement only:

>>> import torch
>>> from deepinv.datasets import TensorDataset
>>> y = torch.rand(1, 3, 8, 8) # B,C,H,W
>>> dataset = TensorDataset(y=y)
>>> x, y = dataset[0]
>>> x
nan
>>> y.shape
torch.Size([3, 8, 8])

Construct a dataset from a ground truth batch:

>>> x = torch.rand(4, 3, 8, 8)  # 4 samples of 3-channel 8x8 images
>>> dataset = TensorDataset(x=x)
>>> dataset[0].shape
torch.Size([3, 8, 8])

Examples using TensorDataset:#

Bring your own dataset

Bring your own dataset

Inference and fine-tune a foundation model

Inference and fine-tune a foundation model

Low-field MRI denoising without ground truth

Low-field MRI denoising without ground truth