Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch inference #101

Open
davidmasek opened this issue Sep 12, 2022 · 1 comment
Open

Batch inference #101

davidmasek opened this issue Sep 12, 2022 · 1 comment

Comments

@davidmasek
Copy link

Hello,
I've been using the model for some experiments with code based on the demo/ctw1500_detection.py. I would like to move from VisualizationDemo because it does not support batch inference. Looking through the source code I tried something like:

from detectron2.engine.defaults import DefaultPredictor

predictor = DefaultPredictor(cfg)

height, width = bgr_img.shape[:2]
image = predictor.transform_gen.get_transform(bgr_img).apply_image(bgr_img)
image = torch.as_tensor(image.astype("float32").transpose(2, 0, 1))
inputs = {"image": image, "height": height, "width": width}

with torch.no_grad():
    predictions_single = predictor.model([inputs]) # works OK
    predictions_batch = predictor.model([inputs, inputs]) # crashes

Inference on single image is fine, but giving multiple images crashes inside mutil_path_fuse_module.py, specifically on feature_fuse = char_context + x + global_context with

RuntimeError: The size of tensor a (2) must match the size of tensor b (4) at non-singleton dimension 0

What should I do to get batch inference?

Thanks.

@davidmasek
Copy link
Author

So I think I solved this?

Inside of Mutil_Path_Fuse_Module class the forward method just uses proposals[0] instead of iterating over them when there are multiple. However this looks like it would never work, so now I'm confused a bit (since I assume the model was used for batch inference at least in training).

@ying09 could you comment on this? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant