Search code examples
pytorchdetectron

Image size in DefaultPredictor of Detectron2


For object detection, I'm using detectron2. I want to fix the input image size so I made my customized dataloader:

def build_train_loader(cls, cfg):
    dataloader = build_detection_train_loader(cfg,
        mapper=DatasetMapper(cfg, is_train=True, augmentations=[
            T.Resize((1200, 1200))
        ]))

What I wonder is for the prediction, I can use the DefaultPredictor of detectron2 and resize my images to (1200, 1200) as prepossessing before sending to the predictor? Or the DefaultPredictor is resizing the image before the prediction and I have to override a function to resize to (1200, 1200)?


Solution

  • You have to preprocess the images yourself or to write your own predictor that will apply the resize before calling the model.

    The DefaultPredictor applies a ResizeShortestEdge transform (that can be configured in the config file), but this is not exactly what you want.