Skip to content

[G-API] Introduce custom python operator API#19804

Merged
alalek merged 3 commits intoopencv:masterfrom
TolyaTalamanov:at/python-custom-op
Mar 30, 2021
Merged

[G-API] Introduce custom python operator API#19804
alalek merged 3 commits intoopencv:masterfrom
TolyaTalamanov:at/python-custom-op

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Build configuration

force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2021.3.0:20.04
build_image:Custom Win=openvino-2021.2.0
build_image:Custom Mac=openvino-2021.2.0

test_modules:Custom=gapi,python2,python3,java
test_modules:Custom Win=gapi,python2,python3,java
test_modules:Custom Mac=gapi,python2,python3,java

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@TolyaTalamanov TolyaTalamanov requested a review from dmatveev March 30, 2021 06:21
@TolyaTalamanov TolyaTalamanov force-pushed the at/python-custom-op branch 2 times, most recently from 94f3bd5 to de02d58 Compare March 30, 2021 08:47
@TolyaTalamanov TolyaTalamanov removed the request for review from dmatveev March 30, 2021 08:47
@TolyaTalamanov TolyaTalamanov requested a review from dmatveev March 30, 2021 10:39
@TolyaTalamanov TolyaTalamanov added this to the 4.5.2 milestone Mar 30, 2021
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dmatveev All check are passed

Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed.

I see a lot of stuff in the public API part which may be hard to change once we merge it to an OpenCV release... Dunno wut to do with it tbh, ideally we need to isolate all this code into some "volatile" header or something to indicate clearly it WILL change.

Comment on lines +215 to +219
template <typename... T>
GOutputs op(const std::string& id, cv::GKernel::M outMeta, T&&... args)
{
return op(id, outMeta, cv::GArgs{cv::GArg(std::forward<T>(args))... });
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not for python, right?

Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov TolyaTalamanov Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for python it's implemented in misc/python/python_bridge.hpp and these symbols doesn't exist in libopencv_gapi.so

return outputs;
}

class cv::gapi::GOutputs::Priv
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Priv is usually hidden from the headers (as it acts for PIMPL purposes)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no way to implement it in cpp file, because this files will be included into cv2.cpp

def custom_add_meta(img_desc1, img_desc2, dtype):
return img_desc1

return cv.gapi_wip_op('custom.add', custom_add_meta, g_in1, g_in2, dtype).getGMat()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can it be cv.gapi.wip.op ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it can't all custom function placed in cv2 namespace

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

TolyaTalamanov commented Mar 30, 2021

Reviewed.

I see a lot of stuff in the public API part which may be hard to change once we merge it to an OpenCV release... Dunno wut to do with it tbh, ideally we need to isolate all this code into some "volatile" header or something to indicate clearly it WILL change.

This stuff isn't a part of libopencv_gapi.so, it's placed in cv2.cpython-36m-x86_64-linux-gnu.so which is used for python.
Also all stuff which is placed in misc/python/* isn't a part of libopencv_gapi

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek

@TolyaTalamanov TolyaTalamanov requested a review from dmatveev March 30, 2021 16:02
Copy link
Copy Markdown
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge it as wip and complete till the next major ocv release.

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek Can it be merged ?

@alalek alalek merged commit 3f14cb0 into opencv:master Mar 30, 2021
@alalek alalek mentioned this pull request Apr 9, 2021
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
[G-API] Introduce custom python operator API

* Introduce custom python operator API

* Add wip namespace
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants