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

Sliced Inference Support for Improved Results #468

Merged
merged 2 commits into from
Oct 11, 2024

Conversation

mali-afridi
Copy link
Contributor

This pull request supports sliced window inference to improve object detection results, especially for larger or high-resolution images. By slicing an image into smaller overlapping windows and running the detection model on each slice, we increase the chances of detecting smaller objects or objects partially visible in a single frame.
The key addition is a slicing mechanism that divides an image into smaller sections before passing it through the detection model. After detection, the predictions from each slice are merged back into the original image space. This method helps detect objects that span slice boundaries while also handling scenarios where a large object might be missed in a single inference pass on the full image.

Key Changes:

  1. The infer.py script now has a slice window inference option, which is enabled by the -sliced flag.
  2. Introduced functions to slice images into smaller tiles with a configurable overlap ratio.
  3. Implemented postprocessing logic to merge detection results from individual slices back into a single set of predictions.
  4. Support for setting the number of slices via the --numberofboxes flag.

How to Use:

  1. When running the inference script, use the—- sliced flag to enable the sliced window inference.
  2. You can configure the number of slices by specifying the—- number of boxes argument, which defines how many slices to create based on the image's aspect ratio.

Results on 0.6 threshold score:

These results were achieved by using

Model Dataset Input Size APval AP50val #Params(M) FPS checkpoint
rtdetr_r101vd COCO 640 54.3 72.8 76 74 url*
With Sliced Inference Without Sliced Inference
results_0 results01-withoutsliced
results_withslice results1_wslice

Example Usage

python tools/infer.py \ -c configs/rtdetr/rtdetr_r101vd_6x_coco.yml \ -r /path/to/model/weights.pth \ --im-file='/path/to/image.jpg' \ --device=cuda:0 \ -s True \ -nc 35

@lyuwenyu
Copy link
Owner

Can you add some message for this feature in Updates in README.md?

@mali-afridi
Copy link
Contributor Author

Done.

@lyuwenyu lyuwenyu merged commit 74f82d6 into lyuwenyu:main Oct 11, 2024
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

Successfully merging this pull request may close these issues.

3 participants