thelper.infer package

Infer package.

This package contains classes specialized for inference of models on various tasks.

Submodules

thelper.infer.base module

class thelper.infer.base.Tester(session_name, session_dir, model, task, loaders, config, ckptdata=None)[source]

Bases: thelper.train.base.Trainer

Base interface of a session runner for testing.

This call mostly delegates calls to existing Trainer implementation, but limiting their use to ‘eval’ methods to make sure that ‘train’ operations are not called by mistake.

__init__(session_name, session_dir, model, task, loaders, config, ckptdata=None)[source]

Receives the trainer configuration dictionary, parses it, and sets up the session.

eval_epoch(model, epoch, dev, loader, metrics, output_path)[source]

Evaluates the model using the provided objects.

Parameters:
  • model – the model with which to run inference that is already uploaded to the target device(s).
  • epoch – the epoch index we are training for (0-based, and should normally only be 0 for single test pass).
  • dev – the target device that tensors should be uploaded to (corresponding to model’s device(s)).
  • loader – the data loader used to get transformed test samples.
  • metrics – the dictionary of metrics/consumers to report inference results (mostly loggers and basic report generator in this case since there shouldn’t be ground truth labels to validate against).
  • output_path – directory where output files should be written, if necessary.
test()[source]
test_epoch(*args, **kwargs)[source]
train()[source]

Starts the training process.

This function will train the model until the required number of epochs is reached, and then evaluate it on the test data. The setup of loggers, tensorboard writers is done here, so is model improvement tracking via monitored metrics. However, the code related to loss computation and back propagation is implemented in a derived class via thelper.train.base.Trainer.train_epoch().

train_epoch(model, epoch, dev, loss, optimizer, loader, metrics, output_path)[source]

Trains the model for a single epoch using the provided objects.

Parameters:
  • model – the model to train that is already uploaded to the target device(s).
  • epoch – the epoch index we are training for (0-based).
  • dev – the target device that tensors should be uploaded to.
  • loss – the loss function used to evaluate model fidelity.
  • optimizer – the optimizer used for back propagation.
  • loader – the data loader used to get transformed training samples.
  • metrics – the dictionary of metrics/consumers to update every iteration.
  • output_path – directory where output files should be written, if necessary.

thelper.infer.impl module

Explicit Tester definitions from existing Trainers.

class thelper.infer.impl.ImageClassifTester(session_name, session_dir, model, task, loaders, config, ckptdata=None)[source]

Bases: thelper.train.classif.ImageClassifTrainer, thelper.infer.base.Tester

Session runner specialized for testing of image classification task with safeguard against model training.

supports_classification = True
class thelper.infer.impl.ImageSegmTester(session_name, session_dir, model, task, loaders, config, ckptdata=None)[source]

Bases: thelper.train.segm.ImageSegmTrainer, thelper.infer.base.Tester

Session runner specialized for testing of image segmentation task with safeguard against model training.

supports_segmentation = True
class thelper.infer.impl.ObjDetectTester(session_name, session_dir, model, task, loaders, config, ckptdata=None)[source]

Bases: thelper.train.detect.ObjDetectTrainer, thelper.infer.base.Tester

Session runner specialized for testing of object detection task with safeguard against model training.

supports_detection = True
class thelper.infer.impl.RegressionTester(session_name, session_dir, model, task, loaders, config, ckptdata=None)[source]

Bases: thelper.train.regr.RegressionTrainer, thelper.infer.base.Tester

Session runner specialized for testing of regression task with safeguard against model training.

supports_regression = True

thelper.infer.utils module

thelper.infer.utils.create_tester(session_name, save_dir, config, model, task, loaders, ckptdata=None)[source]

Instantiates the tester object based on the type contained in the config dictionary.

The tester type is expected to be in the configuration dictionary’s tester field, under the type key. For backward compatibility, the fields runner and trainer will also be looked for. For more information on the configuration, refer to thelper.train.base.Trainer. The instantiated type must be compatible with the constructor signature of thelper.train.base.Trainer. The object’s constructor will be given the full config dictionary and the checkpoint data for resuming the session (if available).

If the trainer type is missing, it will be automatically deduced based on the task object.

Parameters:
  • session_name – name of the training session used for printing and to create internal tensorboardX directories.
  • save_dir – path to the session directory where logs and checkpoints will be saved.
  • config – full configuration dictionary that will be parsed for trainer parameters and saved in checkpoints.
  • model – model to train/evaluate; should be compatible with thelper.nn.utils.Module.
  • task – global task interface defining the type of model and training goal for the session.
  • loaders – a tuple containing the training/validation/test data loaders (a loader can be None if empty).
  • ckptdata – raw checkpoint to parse data from when resuming a session (if None, will start from scratch).
Returns:

The fully-constructed trainer object, ready to begin model training/evaluation.