from detectron2.structures import Instances from detectron2.utils.logger import setup_logger from detectron2.utils.visualizer import ( Visualizer, _create_text_labels, GenericMask, ColorMode, VisImage, random_color, _SMALL_OBJECT_AREA_THRESH, ) from fvcore.common.file_io import PathManager from indiscapes_dataset import register_dataset register_dataset(combined_train_val=False) class CustomVisualizer(Visualizer): def __init__(self, img_rgb, metadata=None, scale=1.0, instance_mode=ColorMode.IMAGE): """ Args: img_rgb: a numpy array of shape (H, W, C), where H and W correspond to the height and width of the image respectively. C is the number of color channels. The image is required to be in RGB format since that is a requirement of the Matplotlib library. The image is also expected to be in the range [0, 255].
import detectron2.utils.comm as comm from d2.detr import DetrDatasetMapper, add_detr_config from detectron2.checkpoint import DetectionCheckpointer from detectron2.config import get_cfg from detectron2.data import MetadataCatalog, build_detection_train_loader from detectron2.engine import DefaultTrainer, default_argument_parser, default_setup, launch from detectron2.evaluation import COCOEvaluator, verify_results from detectron2.evaluation import DatasetEvaluators from detectron2.solver.build import maybe_add_gradient_clipping from hd.evaluator import HDEvaluator from indiscapes_dataset import register_dataset from validation_hooks import EvalHook register_dataset(combined_train_val=True) class Trainer(DefaultTrainer): """ Extension of the Trainer class adapted to DETR. """ @classmethod def build_evaluator(cls, cfg, dataset_name, output_folder=None): """ Create evaluator(s) for a given dataset. This uses the special metadata "evaluator_type" associated with each builtin dataset. For your own dataset, you can simply create an evaluator manually in your script and do not have to worry about the hacky if-else logic here. """ if output_folder is None: