Helpers for detectron2 training

Simple Trainer for basic training


source

Trainer

 Trainer (cfg)

Trainer class for training detectron2 models, using default augmentations


source

RotatedDatasetMapper

 RotatedDatasetMapper (is_train:bool, augmentations:List[Union[detectron2.
                       data.transforms.augmentation.Augmentation,fvcore.tr
                       ansforms.transform.Transform]], image_format:str,
                       use_instance_mask:bool=False,
                       use_keypoint:bool=False,
                       instance_mask_format:str='polygon', keypoint_hflip_
                       indices:Optional[numpy.ndarray]=None,
                       precomputed_proposal_topk:Optional[int]=None,
                       recompute_boxes:bool=False)

A callable which takes a dataset dict in Detectron2 Dataset format, and map it into a format used by the model.

This is the default callable to be used to map your dataset dict into training data. You may need to follow it to implement your own one for customized logic, such as a different way to read or transform images. See :doc:/tutorials/data_loading for details.

The callable currently does the following:

  1. Read the image from “file_name”
  2. Applies cropping/geometric transforms to the image and annotations
  3. Prepare data and annotations to Tensor and :class:Instances

source

transform_rotated_annotations

 transform_rotated_annotations (annotation, transforms, image_size,
                                keypoint_hflip_indices=None)

source

RotatedTrainer

 RotatedTrainer (cfg)

A trainer with default training logic. It does the following:

  1. Create a :class:SimpleTrainer using model, optimizer, dataloader defined by the given config. Create a LR scheduler defined by the config.
  2. Load the last checkpoint or cfg.MODEL.WEIGHTS, if exists, when resume_or_load is called.
  3. Register a few common hooks defined by the config.

It is created to simplify the standard model training workflow and reduce code boilerplate for users who only need the standard training workflow, with standard features. It means this class makes many assumptions about your training logic that may easily become invalid in a new research. In fact, any assumptions beyond those made in the :class:SimpleTrainer are too much for research.

The code of this class has been annotated about restrictive assumptions it makes. When they do not work for you, you’re encouraged to:

  1. Overwrite methods of this class, OR:
  2. Use :class:SimpleTrainer, which only does minimal SGD training and nothing else. You can then add your own hooks if needed. OR:
  3. Write your own training loop similar to tools/plain_train_net.py.

See the :doc:/tutorials/training tutorials for more details.

Note that the behavior of this class, like other functions/classes in this file, is not stable, since it is meant to represent the “common default behavior”. It is only guaranteed to work well with the standard models and training workflow in detectron2. To obtain more stable behavior, write your own training logic with other public APIs.

Examples: :: trainer = DefaultTrainer(cfg) trainer.resume_or_load() # load last checkpoint or MODEL.WEIGHTS trainer.train()

Attributes: scheduler: checkpointer (DetectionCheckpointer): cfg (CfgNode):