Add stateful kernel to python G-API#22037
Add stateful kernel to python G-API#22037asmorkalov merged 3 commits intoopencv:4.xfrom xiong-jie-y:py_gapi_add_state_kernel
Conversation
|
Hi @xiong-jie-y the proposal & design looks great the only question is that really should be exposed to python? I think it should cover your needs. |
@TolyaTalamanov in your example, is the state shared across all instances of your kernel? We do have stateful kernels as special objects in G-API since the state is managed explicitly and its lifetime is well-defined. |
Yes, it's shared across all instances |
Thats not a way to go I believe :) Imagine running multiple trackers on multiple streams in the same app (and it is a pretty valid scenario). We should prioritize merging the @xiong-jie-y 's feature than |
| GPythonKernel(Impl run); | ||
| GPythonKernel(Impl run, Setup setup); | ||
|
|
||
| cv::GRunArgs operator()(const GPythonContext& ctx); |
There was a problem hiding this comment.
I think it's redundant to wrap every stored std::function to method
|
@dmatveev @xiong-jie-y @asmorkalov @alalek Folks, do you have any comments? Can it be merged? |
dmatveev
left a comment
There was a problem hiding this comment.
👍 thanks Anatoliy for completing this
|
💣 |
Please review both interface design and code. 🙂
Motivation
Stateful kernel in C++ is really useful to many usecases like tracking.
This PR will enable python G-API users to use stateful kernel and expand the usecases in python G-API.
Feature Design
Here is the example video and the example code of this feature.
The example kernel is like this.
Basically it create internal state in the
setupmethod and pass it to the G-API framework by returning it.runmethod recieves additionalstateargument and user can handle state with this argument.It is quite similar to the C++ stateful kernel API
GAPI_OCV_KERNEL_STand difference is setup method return state to the framework. This is the interface that I'd like to ask you to review 🙂How to run the demo code?
pip install numpy clickFor video input.
For video file
TODO
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.
-> No need for performance