text: from detectron2.engine import DefaultTrainer
  from detectron2.config import get_cfg
  from detectron2 import model_zoo
  import os
  import cv2
  
  from detectron2.data.datasets import register_coco_instances
  from detectron2.data import MetadataCatalog, DatasetCatalog
  
  register_coco_instances("aquarium_train", {}, "data/aquarium/train/_annotations.coco.json", "data/aquarium/train")
  register_coco_instances("aquarium_val", {}, "data/aquarium/valid/_annotations.coco.json", "data/aquarium/valid")
  MetadataCatalog.get("aquarium_train").thing_classes = ["creatures", "fish", "jellyfish", "penguin", "puffin", "shark", "starfish", "stingray"]
  
  cfg = get_cfg()
  cfg.merge_from_file(model_zoo.get_config_file("COCO-Detection/retinanet_R_50_FPN_1x.yaml"))
  cfg.DATASETS.TRAIN = ("aquarium_train",)
  cfg.DATASETS.TEST = ()
  cfg.DATALOADER.NUM_WORKERS = 2
  cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-Detection/retinanet_R_50_FPN_1x.yaml")  # Let training initialize from model zoo
  cfg.SOLVER.IMS_PER_BATCH = 2
  cfg.SOLVER.BASE_LR = 0.00125
  cfg.SOLVER.MAX_ITER = 4000
  cfg.SOLVER.STEPS = []        # do not decay learning rate
  cfg.MODEL.ROI_HEADS.BATCH_SIZE_PER_IMAGE = 512
  cfg.MODEL.ROI_HEADS.NUM_CLASSES = 8
  # NOTE: this config means the number of classes, but a few popular unofficial tutorials incorrect uses num_classes+1 here. (copied from the official detectron2 tutorial)
  
  os.makedirs(cfg.OUTPUT_DIR, exist_ok=True)
  trainer = DefaultTrainer(cfg)
  trainer.resume_or_load(resume=False)
  trainer.train()
  
  