Criterion

Sequence Loss

class ezflow.functional.criterion.sequence.SequenceLoss(gamma=0.8, max_flow=400, **kwargs)[source]

Sequence loss for optical flow estimation. Used in RAFT (https://arxiv.org/abs/2003.12039)

Parameters
  • gamma (float) – Weight for the loss

  • max_flow (float) – Maximum flow magnitude

forward(flow_preds, flow_gt, valid, **kwargs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Multi-scale Loss

class ezflow.functional.criterion.multiscale.MultiScaleLoss(norm='l1', q=0.4, eps=0.01, weights=(1, 0.5, 0.25), average='mean', resize_flow='upsample', extra_mask=None, use_valid_range=True, valid_range=None, **kwargs)[source]

Multi-scale loss for optical flow estimation. Used in DICL (https://papers.nips.cc/paper/2020/hash/add5aebfcb33a2206b6497d53bc4f309-Abstract.html)

Parameters
  • norm (str, default: "l1") – The norm to use for the loss. Can be either “l2”, “l1” or “robust”

  • q (float, default: 0.4) – This parameter is used in robust loss for fine tuning. q < 1 gives less penalty to outliers

  • eps (float, default: 0.01) – This parameter is a small constant used in robust loss to stabilize fine tuning.

  • weights (list) – The weights to use for each scale

  • average (str, default: "mean") – The mode to set the average of the EPE map. If “mean”, the mean of the EPE map is returned. If “sum”, the EPE map is summed and divided by the batch size.

  • resize_flow (str, default: "upsample") – The mode to resize flow. If “upsample”, predicted flow will be upsampled to the size of the ground truth. If “downsample”, ground truth flow will be downsampled to the size of the predicted flow.

  • extra_mask (torch.Tensor) – A mask to apply to the loss. Useful for removing the loss on the background

  • use_valid_range (bool) – Whether to use the valid range of flow values for the loss

  • valid_range (list) – The valid range of flow values for each scale

forward(flow_preds, flow_gt, **kwargs)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.