Utils

Helpers classes and functions.

class ttools.utils.ExponentialMovingAverage(keys, alpha=0.999)[source]

Keyed tracker that maintains an exponential moving average for each key.

Parameters:
  • keys (list of str) – keys to track.
  • alpha (float) – exponential smoothing factor (higher = smoother).
class ttools.utils.Averager(keys)[source]

Keeps track of running averages, for each key.

class ttools.utils.Timer(sync=True)[source]

A simple timer context.

Returns timing in ms

Parameters:sync (bool) – if True, synchronize CUDA kernels.
ttools.utils.tensor2image(t, normalize=False, dtype=<sphinx.ext.autodoc.importer._MockObject object>)[source]

Converts an tensor image (4D tensor) to a numpy 8-bit array. :param t: input tensor with dimensions [bs, c, h, w], c=3, bs=1 :type t: th.Tensor :param normalize: if True, normalize the tensor’s range to [0, 1] before clipping :type normalize: bool

Returns:[h, w, c] image in uint8 format, with c=3
Return type:(np.array)
ttools.utils.get_logger(name)[source]

Get a named logger.

Parameters:name (string) – name of the logger
ttools.utils.set_logger(debug=False)[source]

Set the default logging level and log format.

Parameters:debug (bool) – if True, enable debug logs.