0

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)?

Kosar KAZEMI
  • 3
  • 1
  • 2

1 Answers1

2

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.

Rémi Chauvenne
  • 479
  • 2
  • 10
  • Thank you for the answer. I am also aware of the ResizeShortestEdge function and the INPUT.MIN_SIZE_{TRAIN, TEST} configurations. Do you think I have to modify them also to make sure about the input size of the network? – Kosar KAZEMI Feb 17 '21 at 10:34
  • Also, I don’t understand with ResizeShortestEdge how the input images can be in different sizes and not square-shaped? – Kosar KAZEMI Feb 17 '21 at 10:35
  • Yes you have to modify INPUT.MIN_SIZE_{TRAIN, TEST} to ensure the input size will be what you want. – Rémi Chauvenne Feb 17 '21 at 11:28
  • ResizeShortestEdge will increase the size until the shortest edge reaches the given value, and such that the original image ratio is preserved. Then if the longest edge has become larger than the given limit, it will reduce the image to fit the requirements. I would advice writting your own predictor that uses the Resize transform. – Rémi Chauvenne Feb 17 '21 at 11:36
  • @RémiChauvenne , I have a simple question: what does edge mean in this context? Could you please help me with this matter? – Saeed Masoomi May 16 '21 at 11:30
  • In this context, the shortest edge is min(height, width) of the image – Rémi Chauvenne May 16 '21 at 15:33