osc.utils

Collection of utilities.

Functions

batches_per_epoch

Compute the number of batches in one epoch according to batch size and drop behavior.

fill_diagonal_

Fill diagonal of torch tensor, batched and in-place.

latest_checkpoint

Find the checkpoint with the highest numerical epoch.

print_arrays

Print array/tensor info (name, shape, dtype).

ravel_multi_index_tf

Same as :func:np.ravel_multi_index with no checks.

seed_everything

Seed python, torch, tensorflow, and numpy

to_dotlist

Iterate over a flattened dict using dot-separated keys.

Classes

AverageMetric

Keep track of the average value of a metric across batches

SigIntCatcher

Context manager to gracefully handle SIGINT or KeyboardInterrupt.

StepCounter

A simple counter to keep track of update steps.