Utilities

IO

class ezflow.utils.io.InputPadder(dims, divisor=8, mode='sintel')[source]

Class to pad / unpad the input to a network with a given padding

Parameters
  • dims (tuple) – Dimensions of the input

  • divisor (int) – Divisor to make the input evenly divisible by

  • mode (str) – Padding mode

pad(*inputs)[source]

Pad the input

Parameters

inputs (list) – List of inputs to pad

Returns

Padded inputs

Return type

list

unpad(x)[source]

Unpad the input

Parameters

x (torch.Tensor) – Input to unpad

Returns

Unpadded input

Return type

torch.Tensor

ezflow.utils.io.read_flow(file_name)[source]

Read ground truth flow from a variety of file formats

Parameters

file_name (str) – Path to flow file

Returns

  • flow (np.ndarray) – Optical flow map

  • valid (None if .flo and .pfm files else np.ndarray) – Valid flow map

ezflow.utils.io.read_flow_middlebury(fn)[source]

Read .flo file in Middlebury format

Parameters

fn (str) – Absolute path to flow file

Returns

flow – Optical flow map

Return type

np.ndarray

ezflow.utils.io.read_flow_pfm(file)[source]

Read optical flow from a .pfm file

Parameters

file (str) – Path to flow file

Returns

flow – Optical flow map

Return type

np.ndarray

ezflow.utils.io.read_flow_png(filename)[source]

Read optical flow from a png file.

Parameters

filename (str) – Path to flow file

Returns

  • flow (np.ndarray) – Optical flow map

  • valid (np.ndarray) – Valid flow map

ezflow.utils.io.read_image(file_name)[source]

Read images from a variety of file formats

Parameters

file_name (str) – Path to flow file

Returns

flow – Optical flow map

Return type

np.ndarray

ezflow.utils.io.write_flow(filename, uv, v=None)[source]

Write optical flow to file.

If v is None, uv is assumed to contain both u and v channels, stacked in depth.

Parameters
  • filename (str) – Path to file

  • uv (np.ndarray) – Optical flow

  • v (np.ndarray, optional) – Optional second channel

Metrics

ezflow.utils.metrics.endpointerror(pred, flow_gt, valid=None, multi_magnitude=False, **kwargs)[source]

Endpoint error

Parameters
  • pred (torch.Tensor) – Predicted flow

  • flow_gt (torch.Tensor) – flow_gt flow

  • valid (torch.Tensor) – Valid flow vectors

Returns

Endpoint error

Return type

torch.Tensor

Other Utilities

Registry

Adapted from Detectron2 (https://github.com/facebookresearch/detectron2)

class ezflow.utils.registry.Registry(name)[source]

Class to register objects and then retrieve them by name.

Parameters

name (str) – Name of the registry

get(name)[source]

Method to retrieve an object from the registry

Parameters

name (str) – Name of the object to retrieve

Returns

Object registered under the given name

Return type

object

get_list()[source]

Method to retrieve all objects from the registry

Returns

List of all objects registered in the registry

Return type

list

register(obj=None, name=None)[source]

Method to register an object in the registry

Parameters
  • obj (object, optional) – Object to register, defaults to None (which will return the decorator)

  • name (str, optional) – Name of the object to register, defaults to None (which will use the name of the object)

Resampling

ezflow.utils.resampling.bilinear_sampler(img, coords, mask=False)[source]

Biliear sampler for images

Parameters
  • img (torch.Tensor) – Image to be sampled

  • coords (torch.Tensor) – Coordinates to be sampled

Returns

Sampled image

Return type

torch.Tensor

ezflow.utils.resampling.convex_upsample_flow(flow, mask_logits, out_stride)[source]

Upsample flow field [H/8, W/8, 2] -> [H, W, 2] using convex combination

Parameters
  • flow (torch.Tensor) – Flow field to be upsampled

  • mask_logits (torch.Tensor) – Mask logits

  • out_stride (int) – Output stride

Returns

Upsampled flow field

Return type

torch.Tensor

ezflow.utils.resampling.forward_interpolate(flow)[source]

Forward interpolation of flow field

Parameters

flow (torch.Tensor) – Flow field to be interpolated

Returns

Forward interpolated flow field

Return type

torch.Tensor

ezflow.utils.resampling.upflow(flow, scale=8, mode='bilinear')[source]

Interpolate flow field

Parameters
  • flow (torch.Tensor) – Flow field to be interpolated

  • scale (int) – Scale of the interpolated flow field

  • mode (str) – Interpolation mode

Returns

Interpolated flow field

Return type

torch.Tensor

Visualization

Warping

ezflow.utils.warp.warp(x, flow)[source]

Warps an image x according to the optical flow field specified

Parameters
  • x (torch.Tensor) – Image to be warped

  • flow (torch.Tensor) – Optical flow field

Returns

Warped image

Return type

torch.Tensor