Meta FAIR · object detection & segmentation on PyTorch · verified against Detectron2 0.6 (2026)

Detectron2 cheat sheet

Detectron2 is Meta AI's PyTorch library for detection & segmentation: pretrained Faster/Mask R-CNN, RetinaNet, Cascade R-CNN, PointRend, ViTDet, panoptic & keypoint models in a Model Zoo, driven by a config system. The everyday flow: build a cfg, run a DefaultPredictor for inference or a DefaultTrainer for fine-tuning on your own COCO-format data. This sheet targets Detectron2 0.6 (main branch adds more). MMDetection is a common alternative.

install & config inference visualize & outputs custom data & training evaluation gotcha most common

Verified 2026-08-24 against the official docs at detectron2.readthedocs.io (0.6) and the facebookresearch/detectron2 repo. Requires a matching PyTorch + CUDA build; GPU strongly recommended.

Outline

Everything hangs off the cfg. Inference = cfg + DefaultPredictor; training = register data + set a few cfg fields + DefaultTrainer.

Setup

  1. 1 · Install & imports
  2. 2 · Config & Model Zoo

Run

  1. 3 · Inference (DefaultPredictor)
  2. 4 · Outputs (Instances)
  3. 5 · Visualize

Train

  1. 6 · Register custom data
  2. 7 · Fine-tune (DefaultTrainer)
  3. 8 · Evaluation

Reference

  1. 9 · Tasks & configs
  2. 10 · Gotchas
  3. Worth memorizing

Setup

Install, and build the config that drives everything.

1Install & imports0.6
2Config & Model Zoocfg is everything

Run Inference

Predict on an image and read the results.

3Inference (DefaultPredictor)one image
4Outputs (Instances)read predictions
5Visualizedraw results

Train on Your Data

Register COCO-format data, then fine-tune.

6Register custom dataCOCO format
7Fine-tune (DefaultTrainer)transfer learning
8EvaluationCOCO metrics

Reference

What's in the zoo, and the traps.

9Tasks & configsmodel zoo
!Common gotchasread before shipping

Worth memorizing

cfg drives everythingget_cfg + merge zoo yaml + set WEIGHTS
same yaml for config & checkpointget_config_file and get_checkpoint_url with the same string
DefaultPredictor takes BGR, single imagecv2.imread; batch manually for throughput
outputs["instances"]pred_boxes / scores / pred_classes / pred_masks — move .to("cpu")
Visualizer wants RGBimg[:, :, ::-1] and back again to save
register_coco_instancesname, {}, json, img_dir — then set DATASETS.TRAIN
NUM_CLASSES = your classes onlybackground is implicit
SOLVER counts iterationsMAX_ITER, not epochs; resume_or_load(False) to fine-tune
COCOEvaluator for mAPbuild_detection_test_loader + inference_on_dataset