Shortcuts

Generic Tools

Average Meter

class tllib.utils.meter.AverageMeter(name, fmt=':f')[source]

Computes and stores the average and current value.

Examples:

>>> # Initialize a meter to record loss
>>> losses = AverageMeter()
>>> # Update meter after every minibatch update
>>> losses.update(loss_value, batch_size)

Progress Meter

class tllib.utils.meter.ProgressMeter(num_batches, meters, prefix='')[source]

Meter

class tllib.utils.meter.Meter(name, fmt=':f')[source]

Computes and stores the current value.

Data

class tllib.utils.data.ForeverDataIterator(data_loader, device=None)[source]

A data iterator that will never stop producing data

class tllib.utils.data.CombineDataset(datasets)[source]

Dataset as a combination of multiple datasets. The element of each dataset must be a list, and the i-th element of the combined dataset is a list splicing of the i-th element of each sub dataset. The length of the combined dataset is the minimum of the lengths of all sub datasets.

Parameters

datasets (sequence) – List of datasets to be concatenated

tllib.utils.data.send_to_device(tensor, device)[source]

Recursively sends the elements in a nested list/tuple/dictionary of tensors to a given device.

Parameters
  • tensor (nested list/tuple/dictionary of torch.Tensor) – The data to send to a given device.

  • device (torch.device) – The device to send the data to

Returns

The same data structure as tensor with all tensors sent to the proper device.

tllib.utils.data.concatenate(tensors)[source]

concatenate multiple batches into one batch. tensors can be torch.Tensor, List or Dict, but they must be the same data format.

Logger

class tllib.utils.logger.TextLogger(filename, stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'>)[source]

Writes stream output to external text file.

Parameters
  • filename (str) – the file to write stream output

  • stream – the stream to read from. Default: sys.stdout

class tllib.utils.logger.CompleteLogger(root, phase='train')[source]

A useful logger that

  • writes outputs to files and displays them on the console at the same time.

  • manages the directory of checkpoints and debugging images.

Parameters
  • root (str) – the root directory of logger

  • phase (str) – the phase of training.

get_checkpoint_path(name=None)[source]

Get the full checkpoint path.

Parameters

name (optional) – the filename (without file extension) to save checkpoint. If None, when the phase is train, checkpoint will be saved to {epoch}.pth. Otherwise, will be saved to {phase}.pth.

get_image_path(filename)[source]

Get the full image path for a specific filename

set_epoch(epoch)[source]

Set the epoch number. Please use it during training.

Docs

Access comprehensive documentation for Transfer Learning Library

View Docs

Tutorials

Get started for Transfer Learning Library

Get Started

Paper List

Get started for transfer learning

View Resources