-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
New cookbook: Small Object Detection with SAHI #1483
Conversation
PreviewPreview and run these notebook edits with Google Colab: Rendered notebook diffs available on ReviewNB.com. If commits are added to the pull request, synchronize your local branch:git pull origin docs/cookbook-sahi
|
Hey everyone, I recently solved a small object detection problem and wanted to share my experience using supervision. It’s great to see the fixes from @SkalskiP (#1434) that addressed the issue of calculating overlaps correctly, now with def calculate_tile_size(image_shape: tuple[int, int], tiles: tuple[int, int], overlap_ratio_wh: tuple[float, float] = (0.0, 0.0)):
"""
Calculate the size of the tiles based on the image shape, the number of tiles, and the overlap ratio.
Parameters:
----------
image_shape : tuple[int, int]
The dimensions of the image as (width, height).
tiles : tuple[int, int]
The tiling strategy defined as (rows, columns), specifying the number of tiles along the height and width of the image.
overlap_ratio_wh : tuple[float, float], optional
The overlap ratio for width and height as (overlap_ratio_w, overlap_ratio_h). This defines the fraction of overlap between adjacent tiles. Default is (0.0, 0.0), meaning no overlap.
Returns:
-------
tuple[tuple[int, int], tuple[int, int]]
A tuple containing:
- The size of each tile as (tile_width, tile_height), accounting for overlap.
- The overlap dimensions as (overlap_width, overlap_height).
Example:
-------
>>> image_shape = (1024, 768)
>>> tiles = (4, 4)
>>> overlap_ratio_wh = (0.15, 0.15)
>>> calculate_tile_size(image_shape, tiles, overlap_ratio_wh)
((281, 230), (39, 29))
Notes:
-----
- The function calculates the width and height of each tile based on the number of rows and columns specified.
- It then applies the overlap ratio to adjust the tile size, ensuring that tiles overlap by a specified fraction.
- The overlap dimensions are rounded up to the nearest integer to ensure complete coverage.
"""
w, h = image_shape
rows, columns = tiles
tile_width = (w / columns)
tile_height = (h / rows)
overlap_ratio_w, overlap_ratio_h = overlap_ratio_wh
overlap_wh = (math.ceil(tile_width * overlap_ratio_w), math.ceil(tile_height * overlap_ratio_h))
tile_width = math.ceil(tile_width + overlap_wh[0])
tile_height = math.ceil(tile_height + overlap_wh[1])
tile_size = (tile_width, tile_height)
return tile_size, overlap_wh In this cookbook, I’m installing supervision from a specific commit on its GitHub repository using the command |
Small friendly tip using
|
Maybe adding this blog to top with badge (https://blog.roboflow.com/detect-small-objects/) (since cookbook about InferenceSlicer) instead of keeping down there. |
Great idea and piece of content. Added! |
Done . |
Hello @ediardo 👋 Here is my initial technical review
I am probably missing points but I hope it helps |
Thank you so much for taking the time to review my pull request so thoroughly. I really appreciate the detailed feedback.
On it.
TIL.
I had a version of download
Those
Great idea! I’ll add links to the documentation for the key functions and features to help users better understand the code.
Thanks for the suggestion! I’ll look into using
Could you please provide some examples? I’m looking forward to learning more about how I could use them.
As much as I liked the image comparison experience, I think it’s time to look for an alternative way to compare the grids, as I also started experiencing undesired behavior towards the end of writing this cookbook |
- Drop leafmap - Remove unnecesarry pkgs - Consolidate imports - Use sv.plot_image - Refactor code
hi @onuralpszr , I made it leaner:
|
Thank you very much I will do new review again as well. |
Hello @onuralpszr, I hope you're doing well! Is there anything else I can do or address to help move the cookbook PR towards merging? |
Hi @ediardo 👋 This is the nicest cookbook I've ever seen. Let's address a few things and merge it in: I'd remove the mention of [assets]. It's great to let people know it exists, but my experience is that most often developers fail to install if not given an exact command. With a standard release it is pip install "supervision[assets]" (quotes are important), and from a branch it should be pip install "assets @ git+https://github.com/roboflow/supervision.git@develop" (failing at the moment).
Within InferenceSlicer later we're using get_model - could we use that here too, instead of the HTTP client? This way, there's less cognitive load for the users.
In most of our examples, we use colors directly and don't make a COLOR_BBOX_PEOPLE variable. Up to you if you want to keep it.
https://blog.roboflow.com/how-to-code-non-maximum-suppression-nms-in-plain-numpy |
b81d595
to
f55a5e6
Compare
@onuralpszr, thank you for your contributions :). @LinasKo: I addressed your comments. Thanks! |
Awesome !! I am checking changes if all good let us merge in as well. |
0c4da1c
to
7782fcd
Compare
…r image slider chore: address comments refactor: jupyter_compare_view resize and small typing and import fixes Signed-off-by: Onuralp SEZER <[email protected]>
13a531f
to
1b7344d
Compare
Description
Small Object Detection with SAHI.
Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
Jupyter Notebook, Google Colab
Any specific deployment considerations
For example, documentation changes, usability, usage/costs, secrets, etc.
Docs