-
Notifications
You must be signed in to change notification settings - Fork 491
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
[Feat] Add new burn-vision crate with one initial op #2753
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a backend extension, what do you think about keeping the implementation within the vision crate instead?
Similar to how you've added a default cpu_impl
, the vision crate would look something like this:
burn-vison/src/
└── ops/
├── cpu_impl/
├── jit/
├── mod.rs
└── base.rs
It would only move your current additions in burn-jit/src/kernel/vision
to burn-vision/src/ops/jit
(and change the imports to use burn_jit
). The jit
module can be under a feature flag.
That way, the backend implementations are kept to the required stuff only and the vision trait implementations are isolated within the crate.
That's how I originally had it, I wasn't sure which way was correct. I guess that's one vote for keeping it in the crate. Anyways I'm still working on CPU support, all the fast algorithms use decision forests and they're full of |
Yeah I was debating that as well when going over the code. But I think this is too specific to live in the backend implementations like you said, it will probably stay restricted to our own backends and not third-party backends. So it makes more sense in this state to have it as an extension in the vision crate.
Yeah I'm sure opencv would be a pain to use here 😬 but at the same time it offers so much for image processing lol. Must be a pain to link though. A default CPU implementation is not a hard requirement either for the vision crate (that is, unless you also need it for your own application lol). This is an extension after all.. |
My vision (hah) for this crate is to provide easy access to image pre and postprocessing for burn, since the current solutions are very awkward (imageproc is pretty incomplete and doesn't support GPU acceleration, opencv is a pain to build and transferring data across FFI is hard). Part of that is always having a fallback implementation available, so you know it always at least works, and uses acceleration where possible. Ideally, if someone is missing an operation, we could relatively easily port the default opencv implementation from C++ to Rust and set it as the default, then if someone wants to add GPU support it can be done later. Once I get GRAPHGEN up and running it should be fairly easy to do even with decision forest algorithms. That's why I'm attempting to modify the codegen instead of manually translating the generated code. |
Not gonna lie that would be pretty awesome 👀 |
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (27.18%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2753 +/- ##
==========================================
- Coverage 83.67% 82.10% -1.58%
==========================================
Files 832 849 +17
Lines 109524 112704 +3180
==========================================
+ Hits 91643 92532 +889
- Misses 17881 20172 +2291 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not familiar with these CV algorithms so I can't really comment on that, but otherwise the vision crate as an extension looks good!
The codegen is not pretty but glad to see that you managed to get it working 😅
Some small stuff below.
@nathanielsimard new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another point to keep all the kernels in burn-vision
. Compiling kernels is quite expensive, and if they are all within the same crate, they can't be parallelized by Cargo. I plan to move the fusion
portion of burn-jit
into its own crate for that reason as well, so less stuff in burn-jit
is better.
B::connected_components(img, connectivity) | ||
} | ||
|
||
fn connected_components_with_stats( | ||
img: burn_tensor::ops::BoolTensor<Self>, | ||
connectivity: crate::Connectivity, | ||
opts: crate::ConnectedStatsOptions, | ||
) -> ( | ||
burn_tensor::ops::IntTensor<Self>, | ||
crate::ConnectedStatsPrimitive<Self>, | ||
) { | ||
let (labels, stats) = B::connected_components_with_stats(img, connectivity, opts); | ||
let stats = crate::ConnectedStatsPrimitive::<Self> { | ||
area: stats.area, | ||
left: stats.left, | ||
top: stats.top, | ||
right: stats.right, | ||
bottom: stats.bottom, | ||
max_label: stats.max_label, | ||
}; | ||
(labels, stats) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there no partial derivative for those ops? In this case, should we actually implement the autodiff backend?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I did that is because Tensor
is generic over the backend, and it would be much more ergonomic to be able to use autodiff tensors for pre/post-processing. Not sure how big the actual use case is, but you might need some vision ops for at least evaluation so having it implemented makes things a lot nicer.
} | ||
} | ||
|
||
#[cube(launch)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can it be unchecked
? I saw an early return previously. Same question for all launch kernels.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, I'm just a bit paranoid after that big OOB write issue we had a while ago. As long as we keep it in mind in case any future issues pop up, it should be fine to run unchecked.
#[cfg(feature = "export-tests")] | ||
#[allow(missing_docs)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to export the tests, since they run in this crate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Integration tests count as running in a separate crate, and we need to use integration tests because of annoying rust limitations around macro_export
(which is generated by burn-tensor-testgen
).
…into feat/burn-vision
Pull Request Template
Checklist
run-checks all
script has been executed.Changes
Adds a new
burn-vision
crate and an initial implementation ofconnected_components
andconnected_components_with_stats
(as in opencv).The algorithms are WIP and rely on tracel-ai/cubecl#446, but I'd like some early feedback on the structure of the new crate and the backend implementations.
Testing
Adds new connected components tests.