TimeMixin#

class deepinv.physics.TimeMixin[source]#

Bases: object

Base class for temporal capabilities for physics and models.

Implements various methods to add or remove the time dimension.

Also provides template methods for temporal physics to implement.

static average(x, mask=None, dim=2)[source]#

Flatten time dim of x by averaging across frames.

If mask is non-overlapping in time dim, then this will simply be the sum across frames.

Parameters:
  • x (Tensor) – input tensor of shape (B,C,T,H,W) (e.g. time-varying k-space)

  • mask (Tensor | None) – mask showing where x is non-zero. If not provided, then calculated from x.

  • dim (int) – time dimension, defaults to 2 (i.e. shape B,C,T,H,W)

Returns:

flattened tensor with time dim removed of shape (B,C,H,W)

Return type:

Tensor

static flatten(x)[source]#

Flatten time dim into batch dim.

Lets non-dynamic algorithms process dynamic data by treating time frames as batches.

Parameters:

x (Tensor) – input tensor of shape (B, C, T, H, W)

Returns:

output tensor of shape (B*T, C, H, W)

Return type:

Tensor

static flatten_C(x)[source]#

Flatten time dim into channel dim.

Use when channel dim doesn’t matter and you don’t want to deal with annoying batch dimension problems (e.g. for transforms).

Parameters:

x (Tensor) – input tensor of shape (B, C, T, H, W)

Returns:

output tensor of shape (B, C*T, H, W)

Return type:

Tensor

static repeat(x, target, dim=2)[source]#

Repeat static image across new time dim T times. Opposite of average.

Parameters:
  • x (Tensor) – input tensor of shape (B,C,H,W)

  • target (Tensor) – any tensor of desired shape (B,C,T,H,W)

  • dim (int) – time dimension, defaults to 2 (i.e. shape B,C,T,H,W)

Returns:

tensor with new time dim of shape (B,C,T,H,W)

Return type:

Tensor

static unflatten(x, batch_size=1)[source]#

Creates new time dim from batch dim. Opposite of flatten.

Parameters:
  • x (Tensor) – input tensor of shape (B*T, C, H, W)

  • batch_size (int) – batch size, defaults to 1

Returns:

output tensor of shape (B, C, T, H, W)

Return type:

Tensor

static wrap_flatten_C(f)[source]#

Flatten time dim into channel dim, apply function, then unwrap.

The first argument is assumed to be the tensor to be flattened.

Parameters:

f (Callable[[Tensor], Tensor]) – function to be wrapped

Returns:

wrapped function

Return type:

Callable

Examples using TimeMixin:#

Image transforms for equivariance & augmentations

Image transforms for equivariance & augmentations

Tour of MRI functionality in DeepInverse

Tour of MRI functionality in DeepInverse

Image transformations for Equivariant Imaging

Image transformations for Equivariant Imaging

Self-supervised learning with Equivariant Imaging for MRI.

Self-supervised learning with Equivariant Imaging for MRI.

Self-supervised MRI reconstruction with Artifact2Artifact

Self-supervised MRI reconstruction with Artifact2Artifact