[Core] Reference implementation for RGBtoNV12 and BGRtoNV12 operations#34437
[Core] Reference implementation for RGBtoNV12 and BGRtoNV12 operations#34437mostafafaheem wants to merge 43 commits into
Conversation
|
Hello @riverlijunjie and @praasz, sorry for the large PR, I thought that splitting it into smaller PRs would not be suitable for the granularity of this task, however, once this PR is merged, I will submit another PR containing CPU plugin reference implementation, and hopefully extend the operation to the GPU plugin. |
There was a problem hiding this comment.
Pull request overview
Adds core ops and template-plugin reference support for RGB/BGR → NV12 conversion, and wires the conversion into the postprocessing pipeline (NV12 single-plane), with accompanying functional/type/visitor tests.
Changes:
- Introduce new opset16 operations
RGBtoNV12andBGRtoNV12(single-plane and two-plane outputs) with shape inference and reference implementation. - Enable evaluation/registration in the template plugin backend and add reference/functional tests.
- Extend postprocessing
convert_color()to support RGB/BGR →NV12_SINGLE_PLANE, plus new preprocess/postprocess tests.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/preprocess_builders.hpp | Adds postprocess subgraph builders for RGB/BGR → NV12 single-plane. |
| src/plugins/template/tests/functional/subgraph_reference/preprocess.cpp | Adds template-plugin reference preprocess tests for postprocess RGB/BGR → NV12. |
| src/plugins/template/tests/functional/op_reference/convert_color_to_nv12.cpp | Adds op-reference tests for RGBtoNV12/BGRtoNV12 (single/two-plane). |
| src/plugins/template/backend/opset_int_tbl.hpp | Registers new ops in the template plugin opset table. |
| src/plugins/template/backend/ops/ops_evaluates.hpp | Declares template-backend evaluate specializations for the new ops. |
| src/plugins/template/backend/ops/convert_color_to_nv12.cpp | Implements template-backend evaluation via the core reference function. |
| src/core/tests/visitors/op/convert_color_to_nv12.cpp | Adds visitor attribute tests for both ops and plane modes. |
| src/core/tests/type_prop/convert_color_to_nv12_base.hpp | Adds typed shape/type propagation tests for the new NV12 base op. |
| src/core/tests/type_prop/convert_color_to_nv12.cpp | Instantiates the new type-prop test suite for both ops. |
| src/core/tests/preprocess.cpp | Adds postprocess pipeline tests for RGB/BGR → NV12 single-plane and rejects two-plane. |
| src/core/src/preprocess/preprocess_steps_impl.cpp | Wires postprocess convert_color() to emit RGBtoNV12/BGRtoNV12 for NV12_SINGLE_PLANE. |
| src/core/src/op/util/convert_color_to_nv12_base.cpp | Implements validation/type inference for the NV12 base op. |
| src/core/src/op/rgb_to_nv12.cpp | Implements RGBtoNV12 op shell + cloning. |
| src/core/src/op/bgr_to_nv12.cpp | Implements BGRtoNV12 op shell + cloning. |
| src/core/shape_inference/include/rgb_bgr_to_nv12_shape_inference.hpp | Adds shape inference for RGB/BGR → NV12 (single/two-plane). |
| src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp | Adds reference kernel for RGB/BGR → NV12 conversion. |
| src/core/include/openvino/opsets/opset16_tbl.hpp | Registers new ops in core opset16 table. |
| src/core/include/openvino/op/util/convert_color_to_nv12_base.hpp | Introduces the new base op API/attributes for RGB/BGR → NV12. |
| src/core/include/openvino/op/rgb_to_nv12.hpp | Adds public op header for RGBtoNV12. |
| src/core/include/openvino/op/ops.hpp | Exposes new op headers via umbrella include. |
| src/core/include/openvino/op/bgr_to_nv12.hpp | Adds public op header for BGRtoNV12. |
| src/core/docs/operation_enabling_flow.md | Updates documentation path for op implementation locations. |
|
build_jenkins |
| constructor_validate_and_infer_types(); | ||
| } | ||
| ov::op::v17::BGRtoNV12::BGRtoNV12(const Output<Node>& arg, bool single_plane) | ||
| : util::ConvertColorToNV12Base(arg, util::ConvertColorToNV12Base::ColorConversion::BGR_TO_NV12, single_plane) { |
There was a problem hiding this comment.
There is concept of base class which defined source color format. It will more clean to keep this patter instead add ConvertColorToNV12Base
For class BGRtoNV12 the format can be set RGB_TO_NV12 which is wrong and should be not possible to set it as source is not RGB
There was a problem hiding this comment.
I think this ConvertColorToNV12Base::ColorConversion can be removed entirely, since it is not accessed anywhere in the code anymore and contains no useful information. However, this will diverge from other color conversion ops.
Is it OK to remove it? @praasz
There was a problem hiding this comment.
If there is no need for this enum to be set by user it should be removed from public interface.
| return std::make_shared<ov::Model>(results, ParameterVector{params}, "ConvertColorGraph"); | ||
| } | ||
|
|
||
| std::shared_ptr<ov::Model> generateConvertColorToNV12(const std::shared_ptr<ov::op::Op> &node) { |
There was a problem hiding this comment.
Why generateConvertColor cannot be expanded?
There was a problem hiding this comment.
Because RGB input has a channel dim, unlike I420 and NV12, so params in generateConvertColor wouldn't work with RGBtoNV12 and BGRtoNV12.
Co-authored-by: Pawel Raasz <pawel.raasz@intel.com>
|
build_jenkins |
p-wysocki
left a comment
There was a problem hiding this comment.
Thank you for your PR, it's very well done. I only had minor comments, mostly about tests. For other reviewers, the scope of my changes was shape infer, spec, type prop tests, reference tests, reference implementation.
| @@ -0,0 +1,129 @@ | |||
| // Copyright (C) 2018-2026 Intel Corporation | |||
There was a problem hiding this comment.
[random spot]
- Can we get a multibatch test? There's some logic in reference implementation which is not tested when
N=1 - The inputs are monochrome, can we switch at least one of the tests to have different colors in the 2x2 pixel blocks? While we're at it, also all tests assume 2x2 blocks, can we test bigger ones as well?
- Since we already have
NV12toRGBandNV12toBGRoperators, can we get a round-trip tests, such as NV12 -> RGB -> NV12? It would explicitly assert that the operation is correct.
There was a problem hiding this comment.
Thank you for these suggestions, 0ba5bfa added the following:
- Multi-batch RGB to single-plane NV12
- Multi-batch BGR to two-plane NV12
- Mixed primary colors RGB to single-plane NV12
- Mixed primary colors BGR to two-plane NV12
- Mixed RGB values to single-plane NV12
- Mixed RGB values to two-plane NV12
- 4x4 RGB to single-plane NV12
- 4x4 BGR to two-plane NV12
- Round-trip NV12 to RGB to NV12
- Round-trip NV12 to BGR to NV12
All pass locally. I used a python script to calculate the expected outputs for each using the RGB -> YUV formula, I can share if you want.
Co-authored-by: Przemyslaw Wysocki <przemyslaw.wysocki@intel.com>
|
@p-wysocki I really appreciate it, and thanks for the review😄 Always glad to be contributing |
|
Some builds are failing due to /__w/openvino/openvino/openvino/src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp:18:36: error: no member named 'min' in namespace 'std'; did you mean 'fmin'?
18 | return static_cast<T>(std::min(std::max(std::round(a), 0.0), 255.0));Overall LGTM, thank you for your PR. Let's wait for more reviews, since this PR is quite big, I'm only covering a part of it. My approve is for the scope of shape infer, spec, type prop tests, reference tests and reference implementation. @riverlijunjie do you know if there's a model we can use to test the changes? |
|
build_jenkins |
Details:
Tickets:
AI Assistance: