artus.train package

Submodules

artus.train.build_trainer module

Build a to train deep learning model.

class artus.train.build_trainer.MyTrainer(cfg)

Bases: DefaultTrainer

A custom trainer that performs validation loop.

classmethod build_evaluator(cfg, dataset_name, output_folder=None)

_summary_

Parameters:
  • cfg (CfgNode) – config file in detectron2 format

  • dataset_name (str) – name of the dataset

  • output_folder (str, optional) – Path to the directory where results of training and evaluation will be saved. Defaults to None.

Returns:

an evaluator for coco dataset.

Return type:

detectron2.evaluation.COCOEvaluator

build_hooks()

Build a hook to make validation on the validation dataset.

Returns:

validation metrics

Return type:

hooks

classmethod build_test_loader(cfg: CfgNode, dataset_name)

Build a test dataloader.

Parameters:
  • cfg (CfgNode) – config file in detectron2 format

  • dataset_name (str) – the name of the dataset

Returns:

A test dataloader.

Return type:

torch.utils.data.DataLoader

classmethod build_train_loader(cfg)

Build a train dataloader.

Parameters:

cfg (CfgNode) – config file in detectron2 format

Returns:

A train dataloader.

Return type:

torch.utils.data.DataLoader

artus.train.config module

A module to handle a config file in yaml format and build a CfgNode.

An example of the config file expected can be found in artus’s tutorials at https://github.com/6tronl/artus-examples/blob/main/configs/x101_allsites_species_overlapping25_tiles5000_ITER3000.yml

artus.train.config.add_config(cfg, config_path, device, train_dataset, test_dataset, output_dir=None, mode=['train', 'inference'])

Add config for DL model coming from a yaml config file.

Parameters:
  • cfg (CfgNode) – a config file in detectron2 format

  • config_path (str) – the path to a config file following the format provided in the tutorials.

  • device (str) – β€˜cpu’ or β€˜cuda’. Results of β€œcuda” if torch.cuda.is_available() else β€œcpu”

  • train_dataset (str) – name of the registered dataset for training

  • test_dataset (str) – name of the registered dataset for validation

  • output_dir (str, optional) – the path to the output directory. Defaults to None.

  • mode (list, optional) – Whether this config will be added in a training or inference use case. Defaults to [β€˜train’, β€˜inference’].

Returns:

a custom config file for training a deep learning model

Return type:

CfgNode

artus.train.config.read_config(config_path)

Read a yaml file used to config a model for training or inference.

Parameters:

config_path (str) – the path to a config file in yaml format

Returns:

A python object

artus.train.data_augmentation module

A module to perform data augmentation during the training and/or inference process

artus.train.data_augmentation.custom_mapper(dataset_dict)

A custom mapper to make data augmentation with the images

Custom mapper performs resizing, flipping, color editor to artificially augment data.

Parameters:

dataset_dict (dict) – a dict mapping the images along with their labels.

Returns:

a dict mapping the augmentated images along with their labels

Return type:

dict

artus.train.train module

A module to train a deep learning model with a config file in the yaml format.

artus.train.train.add_logs_path_to_config(config_path, checkpoint_path_dict)

Add logs paths to the config file to keep track of trained models. :param config_path: the path to a config file (yaml) :type config_path: str :param checkpoint_path_dict: a dict including the β€˜CHECKPOINT’ (the path to the checkpoint saved) :type checkpoint_path_dict: dict

Returns:

The same config file with the path to the final checkpoint added.

artus.train.train.train_model(config_path)

A function that trains a deep learning model with detectron2.

Support multiple deep learning tasks : object detection and instance segmentation.

Parameters:

config_path – the path to a config file (yaml)

Returns: A folder within the logs directory with the checkpoint (.pth) of the model and events file for visualization of the training and validation metrics with tensorboard. A subdirectory is also created with the inference resultst of the validation step.

artus.train.validation_hook module

A detectron2 hook system to make validation during the training process.

class artus.train.validation_hook.LossEvalHook(eval_period, model, data_loader)

Bases: HookBase

after_step()

Called after each iteration.

Module contents