CARVIEW |
Select Language
HTTP/2 200
date: Wed, 23 Jul 2025 20:03:54 GMT
content-type: text/html; charset=utf-8
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With,Accept-Encoding, Accept, X-Requested-With
x-repository-download: git clone https://github.com/opencv/opencv.git
etag: W/"b77c0ce666c769e068deda9a8943207f"
cache-control: max-age=0, private, must-revalidate
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: no-referrer-when-downgrade
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=alS%2F4Qv%2Bar0RcP0FAaLDc%2F%2BY0TwJfN150wF4KJwET9jS0TsKPOoKh%2FxhoW8PTgN44K%2BS8DVr9ylbe6pA8K6kgCpks6iJDkasEE0DElFpn68%2BTWUkXDUjSQiFeiy9H%2FoYH%2BjU9ALRM6TB4aw63hiKPKeSBgfQtxhTESZ4J%2BEe8Pnrho%2FugvYN5ciXfPryqy1CTDeJD2NRh2IbCuRFc7Hyf2MnNnRDOKZBrp8Gl1B9UHsNIJzPq7z66SMmD6wfx349lI8Y4HG4asqlaV%2BCTYQBdw%3D%3D--IRh%2BXYhbmED6pCP4--afnyM%2BRVb3j9rcYSUUnoPg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.1902391121.1753301031; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 20:03:51 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 20:03:51 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: EB0E:35B563:107680C:138B8AF:68814027
Merge pull request #23597 from dmatveev:dm/gapi_onnx_py_integration · opencv/opencv@fc5d412 · GitHub
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/fluid/imgproc.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/gkernel.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/infer/ie.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/infer/onnx.hpp
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/pyopencv_gapi.hpp
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/test/test_gapi_infer_onnx.py
Copy file name to clipboard
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/test/test_gapi_stateful_kernel.py
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/test/test_gapi_streaming.py
Skip to content
Navigation Menu
{{ message }}
-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
Commit fc5d412
authored
Merge pull request #23597 from dmatveev:dm/gapi_onnx_py_integration
G-API: Integration branch for ONNX & Python-related changes #23597
# Changes overview
## 1. Expose ONNX backend's Normalization and Mean-value parameters in Python
* Since Python G-API bindings rely on `Generic` infer to express Inference, the `Generic` specialization of `onnx::Params` was extended with new methods to control normalization (`/255`) and mean-value; these methods were exposed in the Python bindings
* Found some questionable parts in the existing API which I'd like to review/discuss (see comments)
UPD:
1. Thanks to @TolyaTalamanov normalization inconsistencies have been identified with `squeezenet1.0-9` ONNX model itself; tests using these model were updated to DISABLE normalization and NOT using mean/value.
2. Questionable parts were removed and tests still pass.
### Details (taken from @TolyaTalamanov's comment):
`squeezenet1.0.*onnx` - doesn't require scaling to [0,1] and mean/std because the weights of the first convolution already scaled. ONNX documentation is broken. So the correct approach to use this models is:
1. ONNX: apply preprocessing from the documentation: https://github.com/onnx/models/blob/main/vision/classification/imagenet_preprocess.py#L8-L44 but without normalization step:
```
# DON'T DO IT:
# mean_vec = np.array([0.485, 0.456, 0.406])
# stddev_vec = np.array([0.229, 0.224, 0.225])
# norm_img_data = np.zeros(img_data.shape).astype('float32')
# for i in range(img_data.shape[0]):
# norm_img_data[i,:,:] = (img_data[i,:,:]/255 - mean_vec[i]) / stddev_vec[i]
# # add batch channel
# norm_img_data = norm_img_data.reshape(1, 3, 224, 224).astype('float32')
# return norm_img_data
# INSTEAD
return img_data.reshape(1, 3, 224, 224)
```
2. G-API: Convert image from BGR to RGB and then pass to `apply` as-is with configuring parameters:
```
net = cv.gapi.onnx.params('squeezenet', model_filename)
net.cfgNormalize('data_0', False)
```
**Note**: Results might be difference because `G-API` doesn't apply central crop but just do resize to model resolution.
---
`squeezenet1.1.*onnx` - requires scaling to [0,1] and mean/std - onnx documentation is correct.
1. ONNX: apply preprocessing from the documentation: https://github.com/onnx/models/blob/main/vision/classification/imagenet_preprocess.py#L8-L44
2. G-API: Convert image from BGR to RGB and then pass to `apply` as-is with configuring parameters:
```
net = cv.gapi.onnx.params('squeezenet', model_filename)
net.cfgNormalize('data_0', True) // default
net.cfgMeanStd('data_0', [0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
```
**Note**: Results might be difference because `G-API` doesn't apply central crop but just do resize to model resolution.
## 2. Expose Fluid & kernel package-related functionality in Python
* `cv::gapi::combine()`
* `cv::GKernelPackage::size()` (mainly for testing purposes)
* `cv::gapi::imgproc::fluid::kernels()`
Added a test for the above.
## 3. Fixed issues with Python stateful kernel handling
Fixed error message when `outMeta()` of custom python operation fails.
## 4. Fixed various issues in Python tests
1. `test_gapi_streaming.py` - fixed behavior of Desync test to avoid sporadic issues
2. `test_gapi_infer_onnx.py` - fixed model lookup (it was still using the ONNX Zoo layout but was NOT using the proper env var we use to point to one).
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake1 parent 93d4902 commit fc5d412Copy full SHA for fc5d412
File tree
Expand file treeCollapse file tree
13 files changed
+261
-79
lines changedFilter options
- modules/gapi
- include/opencv2/gapi
- fluid
- infer
- misc/python
- test
- src/backends/onnx
- test/infer
Expand file treeCollapse file tree
13 files changed
+261
-79
lines changedmodules/gapi/include/opencv2/gapi/fluid/imgproc.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/fluid/imgproc.hpp+1-1Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
13 | 13 |
| |
14 | 14 |
| |
15 | 15 |
| |
16 |
| - | |
| 16 | + | |
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
|
modules/gapi/include/opencv2/gapi/gkernel.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/gkernel.hpp+5-3Lines changed: 5 additions & 3 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
414 | 414 |
| |
415 | 415 |
| |
416 | 416 |
| |
417 |
| - | |
418 |
| - | |
| 417 | + | |
| 418 | + | |
419 | 419 |
| |
420 | 420 |
| |
421 | 421 |
| |
| |||
513 | 513 |
| |
514 | 514 |
| |
515 | 515 |
| |
516 |
| - | |
| 516 | + | |
517 | 517 |
| |
518 | 518 |
| |
519 | 519 |
| |
| |||
717 | 717 |
| |
718 | 718 |
| |
719 | 719 |
| |
| 720 | + | |
| 721 | + | |
720 | 722 |
| |
721 | 723 |
| |
722 | 724 |
| |
|
modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/infer/bindings_onnx.hpp+7Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
29 | 36 |
| |
30 | 37 |
| |
31 | 38 |
| |
|
modules/gapi/include/opencv2/gapi/infer/ie.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/infer/ie.hpp+1-1Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
242 | 242 |
| |
243 | 243 |
| |
244 | 244 |
| |
245 |
| - | |
| 245 | + | |
246 | 246 |
| |
247 | 247 |
| |
248 | 248 |
| |
|
modules/gapi/include/opencv2/gapi/infer/onnx.hpp
Copy file name to clipboardExpand all lines: modules/gapi/include/opencv2/gapi/infer/onnx.hpp+19-1Lines changed: 19 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
70 | 70 |
| |
71 | 71 |
| |
72 | 72 |
| |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
73 | 81 |
| |
74 | 82 |
| |
75 | 83 |
| |
| |||
298 | 306 |
| |
299 | 307 |
| |
300 | 308 |
| |
301 |
| - | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
302 | 320 |
| |
303 | 321 |
| |
304 | 322 |
| |
|
modules/gapi/misc/python/pyopencv_gapi.hpp
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/pyopencv_gapi.hpp+11-15Lines changed: 11 additions & 15 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
785 | 785 |
| |
786 | 786 |
| |
787 | 787 |
| |
788 |
| - | |
789 |
| - | |
790 |
| - | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
791 | 791 |
| |
792 | 792 |
| |
793 | 793 |
| |
794 | 794 |
| |
795 |
| - | |
796 |
| - | |
| 795 | + | |
797 | 796 |
| |
798 | 797 |
| |
799 | 798 |
| |
800 | 799 |
| |
801 | 800 |
| |
802 | 801 |
| |
803 | 802 |
| |
804 |
| - | |
805 |
| - | |
806 |
| - | |
807 |
| - | |
808 | 803 |
| |
| 804 | + | |
809 | 805 |
| |
810 | 806 |
| |
811 | 807 |
| |
812 | 808 |
| |
813 |
| - | |
| 809 | + | |
814 | 810 |
| |
815 | 811 |
| |
816 |
| - | |
| 812 | + | |
817 | 813 |
| |
818 |
| - | |
| 814 | + | |
819 | 815 |
| |
820 |
| - | |
| 816 | + | |
821 | 817 |
| |
822 | 818 |
| |
823 | 819 |
| |
| |||
826 | 822 |
| |
827 | 823 |
| |
828 | 824 |
| |
829 |
| - | |
| 825 | + | |
830 | 826 |
| |
831 | 827 |
| |
832 | 828 |
| |
| |||
947 | 943 |
| |
948 | 944 |
| |
949 | 945 |
| |
950 |
| - | |
| 946 | + | |
951 | 947 |
| |
952 | 948 |
| |
953 | 949 |
| |
|
modules/gapi/misc/python/test/test_gapi_infer_onnx.py
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/test/test_gapi_infer_onnx.py+4-10Lines changed: 4 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
14 | 14 |
| |
15 | 15 |
| |
16 | 16 |
| |
17 |
| - | |
18 |
| - | |
19 |
| - | |
| 17 | + | |
20 | 18 |
| |
21 | 19 |
| |
22 |
| - | |
23 |
| - | |
24 |
| - | |
25 |
| - | |
26 |
| - | |
27 |
| - | |
| 20 | + | |
| 21 | + | |
28 | 22 |
| |
29 | 23 |
| |
30 | 24 |
| |
31 |
| - | |
32 | 25 |
| |
33 | 26 |
| |
34 | 27 |
| |
| |||
45 | 38 |
| |
46 | 39 |
| |
47 | 40 |
| |
| 41 | + | |
48 | 42 |
| |
49 | 43 |
| |
50 | 44 |
| |
|
modules/gapi/misc/python/test/test_gapi_kernels.py
Copy file name to clipboard+48Lines changed: 48 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + |
modules/gapi/misc/python/test/test_gapi_stateful_kernel.py
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/test/test_gapi_stateful_kernel.py+75-1Lines changed: 75 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
24 | 24 |
| |
25 | 25 |
| |
26 | 26 |
| |
27 |
| - | |
| 27 | + | |
28 | 28 |
| |
29 | 29 |
| |
30 | 30 |
| |
| |||
45 | 45 |
| |
46 | 46 |
| |
47 | 47 |
| |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
48 | 64 |
| |
49 | 65 |
| |
50 | 66 |
| |
| |||
124 | 140 |
| |
125 | 141 |
| |
126 | 142 |
| |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
127 | 201 |
| |
128 | 202 |
| |
129 | 203 |
| |
|
modules/gapi/misc/python/test/test_gapi_streaming.py
Copy file name to clipboardExpand all lines: modules/gapi/misc/python/test/test_gapi_streaming.py+5-7Lines changed: 5 additions & 7 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
17 | 17 |
| |
18 | 18 |
| |
19 | 19 |
| |
20 |
| - | |
| 20 | + | |
21 | 21 |
| |
22 | 22 |
| |
23 | 23 |
| |
| |||
30 | 30 |
| |
31 | 31 |
| |
32 | 32 |
| |
33 |
| - | |
| 33 | + | |
34 | 34 |
| |
35 | 35 |
| |
36 | 36 |
| |
| |||
289 | 289 |
| |
290 | 290 |
| |
291 | 291 |
| |
292 |
| - | |
293 |
| - | |
| 292 | + | |
294 | 293 |
| |
295 | 294 |
| |
296 | 295 |
| |
| |||
307 | 306 |
| |
308 | 307 |
| |
309 | 308 |
| |
310 |
| - | |
311 |
| - | |
| 309 | + | |
312 | 310 |
| |
313 | 311 |
| |
314 | 312 |
| |
315 |
| - | |
| 313 | + | |
316 | 314 |
| |
317 | 315 |
| |
318 | 316 |
| |
|
You can’t perform that action at this time.
0 commit comments