Feat: Add SAHI (Slicing Aided Hyper Inference) Transform#329
Feat: Add SAHI (Slicing Aided Hyper Inference) Transform#329DerrickUnleashed wants to merge 31 commits into
Conversation
|
@cregouby, I'm still a bit unclear about the usage of |
There was a problem hiding this comment.
praise I think that the cropping values logic is there.
todo design all transform_ functions shall return a object of the same type as the input (except transform to tensor) as they will be piped. Your only freedom is to change the shape of the tensor, and move the crops into a sequential batch, as transform_five_crop() do.
ex for x$shape [1, 3, 10, 10], transform_sahi_crop(x, c(4,4) , c(.2, .2)) shall output a tensor of shape [25, 3, 3, 3] (see
torchvision/tests/testthat/test-transforms-tensor.R
Lines 161 to 174 in ac32fa5
suggestion you should rely on the existing crop function to crop the tensor, saving you a lot of unit tests.
todo software design this transform shall be an S3 transform so shall have an entry in transform-generics.R for the dispatch, one in transforms-defaults.R, one in transforms-magick.R, one in transforms-tensor.R, as you never know what transform goes before, what transform is piped after.
todo code relocation Please keep (the badly named, my fault) transform-segmentation.R file for target_transforms
suggestion for clarity, you may rename the transform-segmentation.R into target-transform-segmentation.R (and the test file accordingly)
thought as SAHI intimately rely on input image size and coco bbox (so both x and y at the same time), and as there is no way to pass information from transform_sahi_crop to target_transform_sahi_crop, I think maybe a prepare_sahi_crop(dataset, size, overlap_size_ratio, ... ) function gathering all the needed context into a specific class object sahi_preparation and having both functions using it a the only input parameter transform_sahi_crop(x, sahi_preparation) and target_transform_sahi_crop(x, sahi_preparation) could be a nice API to SAHI.
| #' SAHI Documentation: | ||
| #' https://obss.github.io/sahi/slicing/ | ||
| #' | ||
| #' @family transforms |
There was a problem hiding this comment.
todo family transform does not exist. please stick to an existing transform family.
There was a problem hiding this comment.
I was thinking that we could edit the orginal one from target_transforms to segmentation_transforms
the existing title for the family is also a bit ambiguous
- subtitle: Target transformations for segmentation
desc: >
Functions to convert dataset native targets annotations into segmentation masks compatible
with draw_segmentation_masks() and segmentation models.
contents:
- has_concept("target_transforms")And it would be better if we keep it as segmentation_transforms and add both target and normal transforms to it ?
There was a problem hiding this comment.
The description of the family should be reworked (i.e. remove 'for segmentation') and each individual function title could me more explicit if it is for segmentation purpose.
but the family shall remain target_transforms
There was a problem hiding this comment.
I agree.
How does this look?
- subtitle: Target transformations
desc: >
Functions to convert dataset-native target annotations into segmentation masks compatible
with draw_segmentation_masks() and segmentation models.
contents:
- has_concept("target_transforms")
```
This helps us combine all the target transforms into a single family.
Also, regarding the sahi transform, I have removed the family called transform that was an overlook on my behalf.a56d682 to
5ba16b6
Compare
I didn't understand properly, Do I need to move the code of transform_sahi and target_transform_sahi to transform-generics ? |
|
No. Transform_sahi_crop must manage magick images, tensors and nothing else. The way to do it is S3 dispatch which required an entry in each of the mentioned R files.
Le 13 juin 2026 19:56:59 GMT+02:00, Derrick Richard ***@***.***> a écrit :
…DerrickUnleashed left a comment (mlverse/torchvision#329)
> **todo** **software design** this transform shall be an S3 transform so shall have an entry in transform-generics.R for the dispatch, one in transforms-defaults.R, one in transforms-magick.R, one in transforms-tensor.R, as you never know what transform goes before, what transform is piped after.
I didn't understand properly, Do I need to move the code of transform_sahi and target_transform_sahi to transform-generics ?
--
Reply to this email directly or view it on GitHub:
#329 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|

This PR Adds:
transform_sahi_crop()target_transform_sahi_crop()nms.RdDocumentation to Roxygen2Fixes Implement SAHI: (Slicing Aided Hyper Inference) as both
transform_andtarget_transform_#324