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
- 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
Metrics
Other Utilities
- class ezflow.utils.other_utils.AverageMeter[source]
Computes and stores the average and current value
- ezflow.utils.other_utils.coords_grid(batch_size, h, w)[source]
Returns a grid of coordinates in the shape of (batch_size, h, w, 2)
- Parameters
batch_size (int) – Batch size
h (int) – Height of the image
w (int) – Width of the image
- Returns
Grid of coordinates
- Return type
torch.Tensor
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